Skip to content

Commit

Permalink
refactor 프로젝트 패키지, 클래스 구조 개선
Browse files Browse the repository at this point in the history
- 웹만을 고려하지 않고 확장성 있는 의미로 web 패키지 -> api 패키지로 명칭 변경
- 영속성 관리 차원에서 persistence 패키지 내부에 rdbms, searchengine 패키지 이동
- logs 패키지는 controller에서 활용되는 부분이므로 api 패키지 하위로 이동
- security 관련 설정은 전 프로젝트를 아우르므로 common 패키지 하위에 security 패키지 생성 후 관리 예정
- 실제 외부 영속성과 통신하는 부분은 Repository로 끝나도록 명칭 변경 (예외는 존재)
- 가독성 향상을 위해 adapter layer에서 명시적으로 entity 패키지를 생성하여 관리
- domain 패키지는 비즈니스 로직을 구현하는 부분인 application 패키지 내부로
이동하는게 더 자연스럽다는 의견 반영
  • Loading branch information
jlee38266 committed Sep 20, 2024
1 parent cfd800c commit 8f1987c
Show file tree
Hide file tree
Showing 32 changed files with 59 additions and 111 deletions.
16 changes: 0 additions & 16 deletions webtoon-search-back/webtoon-search/Dockerfile-spring-original

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.samsamohoh.webtoonsearch.common;
package com.samsamohoh.webtoonsearch.adapter.api;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.samsamohoh.webtoonsearch.common.logs;
package com.samsamohoh.webtoonsearch.adapter.api.logs;

import com.samsamohoh.webtoonsearch.adapter.web.webtoon.SelectRecordRequest;
import com.samsamohoh.webtoonsearch.adapter.api.webtoon.SelectRecordRequest;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
Expand All @@ -19,7 +19,7 @@
@Slf4j
public class LoggingAspect {

@Pointcut("execution(* com.samsamohoh.webtoonsearch.adapter.web.webtoon.SelectRecordController.*(..))")
@Pointcut("execution(* com.samsamohoh.webtoonsearch.adapter.api.webtoon.SelectRecordController.*(..))")
public void activeLogPointcut() {}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.samsamohoh.webtoonsearch.adapter.web.member;
package com.samsamohoh.webtoonsearch.adapter.api.member;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.samsamohoh.webtoonsearch.adapter.web.member;
package com.samsamohoh.webtoonsearch.adapter.api.member;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.samsamohoh.webtoonsearch.adapter.web.member;
package com.samsamohoh.webtoonsearch.adapter.api.member;

import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.samsamohoh.webtoonsearch.adapter.web.member;
package com.samsamohoh.webtoonsearch.adapter.api.member;

import lombok.Getter;
import lombok.ToString;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.samsamohoh.webtoonsearch.adapter.web.webtoon;
package com.samsamohoh.webtoonsearch.adapter.api.webtoon;

import com.samsamohoh.webtoonsearch.application.port.in.webtoon.SearchWebtoonCommand;
import com.samsamohoh.webtoonsearch.application.port.in.webtoon.WebtoonResult;
import com.samsamohoh.webtoonsearch.application.port.in.webtoon.SearchWebtoonUseCase;
import com.samsamohoh.webtoonsearch.common.ApiResponse;
import com.samsamohoh.webtoonsearch.adapter.api.ApiResponse;
import io.micrometer.core.annotation.Counted;
import io.micrometer.core.annotation.Timed;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.samsamohoh.webtoonsearch.adapter.web.webtoon;
package com.samsamohoh.webtoonsearch.adapter.api.webtoon;

import com.samsamohoh.webtoonsearch.application.port.in.webtoon.WebtoonResult;
import lombok.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.samsamohoh.webtoonsearch.adapter.web.webtoon;
package com.samsamohoh.webtoonsearch.adapter.api.webtoon;

import com.samsamohoh.webtoonsearch.application.port.in.webtoon.SelectRecordUseCase;
import com.samsamohoh.webtoonsearch.application.port.in.webtoon.SelectWebtoonDTO;
import com.samsamohoh.webtoonsearch.common.ApiResponse;
import com.samsamohoh.webtoonsearch.adapter.api.ApiResponse;
import io.micrometer.core.annotation.Counted;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.samsamohoh.webtoonsearch.adapter.web.webtoon;
package com.samsamohoh.webtoonsearch.adapter.api.webtoon;

import lombok.Getter;
import lombok.Value;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.samsamohoh.webtoonsearch.adapter.persistence.rdbms;

import com.samsamohoh.webtoonsearch.adapter.persistence.rdbms.entity.RegisterMemberEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberJpaRepository extends JpaRepository<RegisterMemberEntity, Long> {
RegisterMemberEntity findByProviderId(String providerId);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.samsamohoh.webtoonsearch.adapter.rdbms;
package com.samsamohoh.webtoonsearch.adapter.persistence.rdbms;

import com.samsamohoh.webtoonsearch.adapter.persistence.MemberPersistenceAdapter;
import com.samsamohoh.webtoonsearch.adapter.persistence.RegisterMemberEntity;
import com.samsamohoh.webtoonsearch.adapter.persistence.rdbms.entity.RegisterMemberEntity;
import com.samsamohoh.webtoonsearch.application.port.in.member.MemberResponseDTO;
import com.samsamohoh.webtoonsearch.application.port.out.SaveMemberPort;
import lombok.RequiredArgsConstructor;
Expand All @@ -11,7 +10,7 @@
@RequiredArgsConstructor
public class MemberRecordAdapter implements SaveMemberPort {

private final MemberPersistenceAdapter memberPersistenceAdapter;
private final MemberJpaRepository memberJpaRepository;

@Override
public MemberResponseDTO saveMember(MemberResponseDTO command) {
Expand All @@ -24,14 +23,14 @@ public MemberResponseDTO saveMember(MemberResponseDTO command) {
.provider(command.getProvider())
.build();

memberPersistenceAdapter.save(entity);
memberJpaRepository.save(entity);

return command; // 필요한 경우 savedEntity를 기반으로 새로운 DTO를 반환하도록 수정
}

@Override
public MemberResponseDTO findMemberByProviderId(String providerId) {
RegisterMemberEntity entity = memberPersistenceAdapter.findByProviderId(providerId);
RegisterMemberEntity entity = memberJpaRepository.findByProviderId(providerId);
if (entity != null) {
return new MemberResponseDTO(
entity.getProviderId(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.samsamohoh.webtoonsearch.adapter.persistence.rdbms;

import com.samsamohoh.webtoonsearch.adapter.persistence.rdbms.entity.SelectRecordEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface SelectJpaRepository extends JpaRepository<SelectRecordEntity, String> {

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.samsamohoh.webtoonsearch.adapter.rdbms;
package com.samsamohoh.webtoonsearch.adapter.persistence.rdbms;

import com.samsamohoh.webtoonsearch.adapter.persistence.SelectPersistenceAdapter;
import com.samsamohoh.webtoonsearch.adapter.persistence.SelectRecordEntity;
import com.samsamohoh.webtoonsearch.adapter.persistence.rdbms.entity.SelectRecordEntity;
import com.samsamohoh.webtoonsearch.application.port.in.webtoon.SelectWebtoonDTO;
import com.samsamohoh.webtoonsearch.application.port.out.AddRecordPort;
import lombok.RequiredArgsConstructor;
Expand All @@ -12,13 +11,13 @@
@RequiredArgsConstructor
public class SelectRecordAdapter implements AddRecordPort {

private final SelectPersistenceAdapter selectPersistenceAdapter;
private final SelectJpaRepository selectJpaRepository;

@Override
public boolean addRecord(SelectWebtoonDTO data) {

try {
selectPersistenceAdapter.save(toEntity(data));
selectJpaRepository.save(toEntity(data));

return true;
} catch(Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.samsamohoh.webtoonsearch.adapter.persistence;
package com.samsamohoh.webtoonsearch.adapter.persistence.rdbms.entity;

import jakarta.persistence.*;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.samsamohoh.webtoonsearch.adapter.persistence;
package com.samsamohoh.webtoonsearch.adapter.persistence.rdbms.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
package com.samsamohoh.webtoonsearch.adapter.searchengine;
package com.samsamohoh.webtoonsearch.adapter.persistence.searchengine;

import com.samsamohoh.webtoonsearch.adapter.persistence.SearchWebtoonEntity;
import com.samsamohoh.webtoonsearch.adapter.persistence.searchengine.entity.SearchWebtoonEntity;
import com.samsamohoh.webtoonsearch.application.port.in.webtoon.LoadWebtoonQuery;
import com.samsamohoh.webtoonsearch.application.port.in.webtoon.WebtoonResult;
import com.samsamohoh.webtoonsearch.application.port.out.LoadWebtoonPort;
import com.samsamohoh.webtoonsearch.application.port.in.webtoon.LoadWebtoonQuery;
import com.samsamohoh.webtoonsearch.common.metrics.CustomMetrics;
import io.micrometer.core.annotation.Timed;
//import org.springframework.dao.DataAccessResourceFailureException;
import io.micrometer.core.instrument.Tag;
import lombok.RequiredArgsConstructor;
import org.opensearch.client.opensearch.OpenSearchClient;
import org.opensearch.client.opensearch.core.SearchRequest;
import org.opensearch.client.opensearch.core.SearchResponse;
import org.opensearch.client.opensearch.core.search.Hit;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.List;

@Component
@RequiredArgsConstructor
//@RequiredArgsConstructor
public class SearchEngineAdapter implements LoadWebtoonPort {
// private final SearchPersistenceAdapter searchPersistenceAdapter;
private final CustomMetrics customMetrics;

private final OpenSearchClient openSearchClient;
private final CustomMetrics customMetrics;

@Override
@Timed(value = "search.opensearch.reply.duration",
Expand Down Expand Up @@ -58,28 +54,6 @@ public WebtoonResult loadWebtoons(LoadWebtoonQuery term) {
}
}

// String searchTerm = query.getSearchTerm();
//
// try {
// List<SearchWebtoonEntity> entities = searchPersistenceAdapter.searchAll(searchTerm);
//
// List<WebtoonResult.WebtoonDTO> webtoons = entities.stream()
// .map(this::mapToWebtoonDTO)
// .collect(Collectors.toList());
//
// return new WebtoonResult(webtoons);
//
// } catch(DataAccessResourceFailureException e) {
// customMetrics.getCounter("opensearch.connection.fail.count"
// ,"metrics for opensearch connecting failure"
// , Arrays.asList(Tag.of("class","search-engine-adapter"),
// Tag.of("method","load-webtoons"),
// Tag.of("endpoint","/webtoons/search"))).increment();
// throw new DataAccessResourceFailureException(e.getMessage());
// }
// return null;
// }
//

// OpenSearch한테 요청을 보내는 쿼리문
private SearchRequest createSearchRequest(String searchTerm) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
package com.samsamohoh.webtoonsearch.adapter.config;

import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
package com.samsamohoh.webtoonsearch.adapter.persistence.searchengine.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.HttpHost;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.samsamohoh.webtoonsearch.adapter.persistence;
package com.samsamohoh.webtoonsearch.adapter.persistence.searchengine.entity;

import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.samsamohoh.webtoonsearch.domain;
package com.samsamohoh.webtoonsearch.application.domain;

import lombok.Builder;
import lombok.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.samsamohoh.webtoonsearch.domain;
package com.samsamohoh.webtoonsearch.application.domain;

import lombok.Builder;
import lombok.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.samsamohoh.webtoonsearch.application.service;

import com.samsamohoh.webtoonsearch.adapter.web.member.NaverUserInfo;
import com.samsamohoh.webtoonsearch.adapter.web.member.OAuth2UserInfo;
import com.samsamohoh.webtoonsearch.adapter.web.member.PrincipalDetails;
import com.samsamohoh.webtoonsearch.adapter.api.member.NaverUserInfo;
import com.samsamohoh.webtoonsearch.adapter.api.member.OAuth2UserInfo;
import com.samsamohoh.webtoonsearch.adapter.api.member.PrincipalDetails;
import com.samsamohoh.webtoonsearch.application.port.in.member.MemberResponseDTO;
import com.samsamohoh.webtoonsearch.application.port.out.SaveMemberPort;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.samsamohoh.webtoonsearch.adapter.config;
package com.samsamohoh.webtoonsearch.common.security.config;

import com.samsamohoh.webtoonsearch.application.port.out.SaveMemberPort;
import com.samsamohoh.webtoonsearch.application.service.PrincipalOauth2UserService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.samsamohoh.webtoonsearch.adapter.web;
package com.samsamohoh.webtoonsearch.adapter.api;

import com.samsamohoh.webtoonsearch.adapter.web.webtoon.SearchWebtoonController;
import com.samsamohoh.webtoonsearch.adapter.web.webtoon.SearchWebtoonResponse;
import com.samsamohoh.webtoonsearch.adapter.api.webtoon.SearchWebtoonController;
import com.samsamohoh.webtoonsearch.adapter.api.webtoon.SearchWebtoonResponse;
import com.samsamohoh.webtoonsearch.application.port.in.webtoon.SearchWebtoonCommand;
import com.samsamohoh.webtoonsearch.application.port.in.webtoon.SearchWebtoonUseCase;
import com.samsamohoh.webtoonsearch.application.port.in.webtoon.WebtoonResult;
import com.samsamohoh.webtoonsearch.common.ApiResponse;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.samsamohoh.webtoonsearch.application.domain.SearchableWebtoon;
import org.junit.jupiter.api.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down

0 comments on commit 8f1987c

Please sign in to comment.