Skip to content

Commit

Permalink
Refactor/202 : 계층별 클래스 네이밍 변경 (#203)
Browse files Browse the repository at this point in the history
* ♻️ Refactor: Briefing 도메인 API 모듈 계층 네이밍 변경

* ♻️ Refactor: Member 도메인 API 모듈 계층 네이밍 변경

* ♻️ Refactor: Scrap 도메인 API 모듈 계층 네이밍 변경

* ♻️ Refactor: Adapter 어노테이션 추가 및 기존 Service 어노테이션 대체

* ♻️ Refactor: Business 계층 Service 어노테이션으로 대체

* ♻️ Refactor: 타입 Mapper 클래스들 Private 생성자 추가
  • Loading branch information
swa07016 authored Apr 16, 2024
1 parent beeb6eb commit 07b9bd5
Show file tree
Hide file tree
Showing 25 changed files with 201 additions and 170 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.briefingapi.annotation;

import org.springframework.core.annotation.AliasFor;
import org.springframework.stereotype.Component;

import java.lang.annotation.*;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Adapter {
// 스프링 빈의 이름을 지정
@AliasFor(annotation = Component.class)
String value() default "";
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.briefingapi.aop.annotation;
package com.example.briefingapi.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.example.briefingapi.aop.aspect;
package com.example.briefingapi.aop;

import java.util.Optional;

import com.example.briefingapi.aop.annotation.CacheEvictByBriefingId;
import com.example.briefingapi.annotation.CacheEvictByBriefingId;
import com.example.briefingcommon.domain.repository.article.BriefingRepository;
import com.example.briefingcommon.entity.Briefing;
import org.aspectj.lang.JoinPoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import com.example.briefingcommon.entity.Article;
import com.example.briefingcommon.entity.Briefing;
import com.example.briefingcommon.entity.enums.BriefingType;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

public class BriefingConverter {
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class BriefingMapper {

public static BriefingResponseDTO.BriefingPreviewDTOV2 toBriefingPreviewDTOV2(
Briefing briefing) {
Expand Down Expand Up @@ -46,7 +49,7 @@ private static LocalDateTime getPreviewListDTOCreatedAt(
public static BriefingResponseDTO.BriefingPreviewListDTOV2 toBriefingPreviewListDTOV2(
final LocalDate date, List<Briefing> briefingList) {
final List<BriefingResponseDTO.BriefingPreviewDTOV2> briefingPreviewDTOList =
briefingList.stream().map(BriefingConverter::toBriefingPreviewDTOV2).toList();
briefingList.stream().map(BriefingMapper::toBriefingPreviewDTOV2).toList();

return BriefingResponseDTO.BriefingPreviewListDTOV2.builder()
.createdAt(getPreviewListDTOCreatedAt(date, briefingList))
Expand All @@ -57,7 +60,7 @@ public static BriefingResponseDTO.BriefingPreviewListDTOV2 toBriefingPreviewList
public static BriefingResponseDTO.BriefingPreviewListDTO toBriefingPreviewListDTO(
final LocalDate date, List<Briefing> briefingList) {
final List<BriefingResponseDTO.BriefingPreviewDTO> briefingPreviewDTOList =
briefingList.stream().map(BriefingConverter::toBriefingPreviewDTO).toList();
briefingList.stream().map(BriefingMapper::toBriefingPreviewDTO).toList();

return BriefingResponseDTO.BriefingPreviewListDTO.builder()
.createdAt(getPreviewListDTOCreatedAt(date, briefingList))
Expand All @@ -80,7 +83,7 @@ public static BriefingResponseDTO.BriefingDetailDTO toBriefingDetailDTO(

List<BriefingResponseDTO.ArticleResponseDTO> articleResponseDTOList =
briefing.getArticles().stream()
.map(BriefingConverter::toArticleResponseDTO)
.map(BriefingMapper::toArticleResponseDTO)
.toList();

return BriefingResponseDTO.BriefingDetailDTO.builder()
Expand All @@ -102,7 +105,7 @@ public static BriefingResponseDTO.BriefingDetailDTOV2 toBriefingDetailDTOV2(

List<BriefingResponseDTO.ArticleResponseDTO> articleResponseDTOList =
briefing.getArticles().stream()
.map(BriefingConverter::toArticleResponseDTO)
.map(BriefingMapper::toArticleResponseDTO)
.toList();

return BriefingResponseDTO.BriefingDetailDTOV2.builder()
Expand Down Expand Up @@ -188,7 +191,7 @@ public static BriefingResponseDTO.BriefingPreviewV2TempDTO toBriefingPreviewV2Te
public static BriefingResponseDTO.BriefingV2PreviewListDTO toBriefingPreviewV2TempListDTO(
final LocalDate date, List<Long> temp, BriefingType briefingType) {
List<BriefingResponseDTO.BriefingPreviewV2TempDTO> tempDTOList =
temp.stream().map(BriefingConverter::toBriefingPreviewV2TempDTO).toList();
temp.stream().map(BriefingMapper::toBriefingPreviewV2TempDTO).toList();

return BriefingResponseDTO.BriefingV2PreviewListDTO.builder()
.createdAt(date.atTime(3, 0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,79 @@
import java.util.List;
import java.util.Optional;

import com.example.briefingapi.briefing.implement.service.ArticleCommandService;
import com.example.briefingapi.briefing.implement.service.BriefingCommandService;
import com.example.briefingapi.briefing.implement.service.BriefingQueryService;
import com.example.briefingapi.briefing.implement.service.ArticleCommandAdapter;
import com.example.briefingapi.briefing.implement.service.BriefingCommandAdapter;
import com.example.briefingapi.briefing.implement.service.BriefingQueryAdapter;
import com.example.briefingapi.briefing.presentation.dto.BriefingRequestDTO;
import com.example.briefingapi.briefing.presentation.dto.BriefingRequestParam;
import com.example.briefingapi.briefing.presentation.dto.BriefingResponseDTO;
import com.example.briefingapi.scrap.implement.ScrapQueryService;
import com.example.briefingapi.scrap.implement.ScrapQueryAdapter;
import com.example.briefingcommon.entity.Article;
import com.example.briefingcommon.entity.Briefing;
import com.example.briefingcommon.entity.Member;
import com.example.briefingcommon.entity.enums.APIVersion;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import lombok.RequiredArgsConstructor;

@Component
@Service
@RequiredArgsConstructor
public class BriefingFacade {
private final ScrapQueryService scrapQueryService;
private final BriefingQueryService briefingQueryService;
private final BriefingCommandService briefingCommandService;
private final ArticleCommandService articleCommandService;
public class BriefingService {
private final ScrapQueryAdapter scrapQueryAdapter;
private final BriefingQueryAdapter briefingQueryAdapter;
private final BriefingCommandAdapter briefingCommandAdapter;
private final ArticleCommandAdapter articleCommandAdapter;
private static final APIVersion version = APIVersion.V1;

@Transactional(readOnly = true)
public BriefingResponseDTO.BriefingPreviewListDTO findBriefings(
BriefingRequestParam.BriefingPreviewListParam params) {
List<Briefing> briefingList = briefingQueryService.findBriefings(params, version);
return BriefingConverter.toBriefingPreviewListDTO(params.getDate(), briefingList);
List<Briefing> briefingList = briefingQueryAdapter.findBriefings(params, version);
return BriefingMapper.toBriefingPreviewListDTO(params.getDate(), briefingList);
}

@Transactional
public BriefingResponseDTO.BriefingDetailDTO findBriefing(final Long id, Member member) {
briefingCommandService.increaseViewCountById(id);
briefingCommandAdapter.increaseViewCountById(id);
Boolean isScrap =
Optional.ofNullable(member)
.map(m -> scrapQueryService.existsByMemberIdAndBriefingId(m.getId(), id))
.map(m -> scrapQueryAdapter.existsByMemberIdAndBriefingId(m.getId(), id))
.orElseGet(() -> Boolean.FALSE);

Boolean isBriefingOpen = false;
Boolean isWarning = false;

return BriefingConverter.toBriefingDetailDTO(
briefingQueryService.findBriefing(id, version), isScrap, isBriefingOpen, isWarning);
return BriefingMapper.toBriefingDetailDTO(
briefingQueryAdapter.findBriefing(id, version), isScrap, isBriefingOpen, isWarning);
}

@Transactional
public void createBriefing(final BriefingRequestDTO.BriefingCreate request) {
Briefing createdBriefing =
briefingCommandService.create(BriefingConverter.toBriefing(request));
briefingCommandAdapter.create(BriefingMapper.toBriefing(request));

final List<Article> articles =
request.getArticles().stream()
.map(articleCreateDto -> {
Article article = BriefingConverter.toArticle(articleCreateDto);
Article article = BriefingMapper.toArticle(articleCreateDto);
article.setBriefing(createdBriefing);
return article;
}).toList();

List<Article> createdArticles = articleCommandService.createAll(articles);
List<Article> createdArticles = articleCommandAdapter.createAll(articles);
createdBriefing.setArticles(createdArticles);
}

@Transactional
public BriefingResponseDTO.BriefingUpdateDTO updateBriefing(
Long id, final BriefingRequestDTO.BriefingUpdateDTO request) {
Briefing briefing = briefingQueryService.findBriefing(id, APIVersion.V1);
Briefing briefing = briefingQueryAdapter.findBriefing(id, APIVersion.V1);
Briefing updatedBriefing =
briefingCommandService.update(
briefingCommandAdapter.update(
briefing, request.getTitle(), request.getSubTitle(), request.getContent());
return BriefingConverter.toBriefingUpdateDTO(updatedBriefing);
return BriefingMapper.toBriefingUpdateDTO(updatedBriefing);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,48 @@
import java.util.List;
import java.util.Optional;

import com.example.briefingapi.briefing.implement.service.BriefingCommandService;
import com.example.briefingapi.briefing.implement.service.BriefingQueryService;
import com.example.briefingapi.briefing.implement.service.BriefingCommandAdapter;
import com.example.briefingapi.briefing.implement.service.BriefingQueryAdapter;
import com.example.briefingapi.briefing.presentation.dto.BriefingRequestParam;
import com.example.briefingapi.briefing.presentation.dto.BriefingResponseDTO;
import com.example.briefingapi.scrap.implement.ScrapQueryService;
import com.example.briefingapi.scrap.implement.ScrapQueryAdapter;
import com.example.briefingcommon.entity.Briefing;
import com.example.briefingcommon.entity.Member;
import com.example.briefingcommon.entity.enums.APIVersion;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import lombok.RequiredArgsConstructor;

@Component
@Service
@RequiredArgsConstructor
public class BriefingV2Facade {
public class BriefingV2Service {

private final BriefingQueryService briefingQueryService;
private final BriefingCommandService briefingCommandService;
private final ScrapQueryService scrapQueryService;
private final BriefingQueryAdapter briefingQueryAdapter;
private final BriefingCommandAdapter briefingCommandAdapter;
private final ScrapQueryAdapter scrapQueryAdapter;
private static final APIVersion version = APIVersion.V2;

@Transactional(readOnly = true)
public BriefingResponseDTO.BriefingPreviewListDTOV2 findBriefings(
BriefingRequestParam.BriefingPreviewListParam params) {
List<Briefing> briefingList = briefingQueryService.findBriefings(params, version);
return BriefingConverter.toBriefingPreviewListDTOV2(params.getDate(), briefingList);
List<Briefing> briefingList = briefingQueryAdapter.findBriefings(params, version);
return BriefingMapper.toBriefingPreviewListDTOV2(params.getDate(), briefingList);
}

@Transactional
public BriefingResponseDTO.BriefingDetailDTOV2 findBriefing(final Long id, Member member) {
briefingCommandService.increaseViewCountById(id);
briefingCommandAdapter.increaseViewCountById(id);
Boolean isScrap =
Optional.ofNullable(member)
.map(m -> scrapQueryService.existsByMemberIdAndBriefingId(m.getId(), id))
.map(m -> scrapQueryAdapter.existsByMemberIdAndBriefingId(m.getId(), id))
.orElseGet(() -> Boolean.FALSE);

Boolean isBriefingOpen = false;
Boolean isWarning = false;

return BriefingConverter.toBriefingDetailDTOV2(
briefingQueryService.findBriefing(id, version), isScrap, isBriefingOpen, isWarning);
return BriefingMapper.toBriefingDetailDTOV2(
briefingQueryAdapter.findBriefing(id, version), isScrap, isBriefingOpen, isWarning);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

import java.util.List;

import com.example.briefingapi.annotation.Adapter;
import com.example.briefingcommon.domain.repository.article.ArticleRepository;
import com.example.briefingcommon.entity.Article;
import org.springframework.stereotype.Service;


import lombok.RequiredArgsConstructor;

@Service
@Adapter
@RequiredArgsConstructor
public class ArticleCommandService {
public class ArticleCommandAdapter {
private final ArticleRepository articleRepository;

public List<Article> createAll(final List<Article> articles) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.example.briefingapi.briefing.implement.service;

import com.example.briefingapi.annotation.Adapter;
import com.example.briefingcommon.domain.repository.article.BriefingRepository;
import com.example.briefingcommon.entity.Briefing;
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;

@Service
@Adapter
@RequiredArgsConstructor
public class BriefingCommandService {
public class BriefingCommandAdapter {

private final BriefingRepository briefingRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import com.example.briefingapi.annotation.Adapter;
import com.example.briefingapi.briefing.implement.context.BriefingQueryContext;
import com.example.briefingapi.briefing.implement.context.BriefingQueryContextFactory;
import com.example.briefingapi.briefing.presentation.dto.BriefingRequestParam;
Expand All @@ -12,9 +13,9 @@
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;

@Service
@Adapter
@RequiredArgsConstructor
public class BriefingQueryService {
public class BriefingQueryAdapter {

private final BriefingQueryContextFactory briefingQueryContextFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.briefingapi.briefing.presentation;

import com.example.briefingapi.briefing.business.BriefingFacade;
import com.example.briefingapi.briefing.business.BriefingService;
import com.example.briefingapi.briefing.presentation.dto.BriefingRequestDTO;
import com.example.briefingapi.briefing.presentation.dto.BriefingRequestParam;
import com.example.briefingapi.briefing.presentation.dto.BriefingResponseDTO;
Expand All @@ -15,7 +15,7 @@
import org.springframework.web.bind.annotation.*;


import com.example.briefingapi.aop.annotation.CacheEvictByBriefingId;
import com.example.briefingapi.annotation.CacheEvictByBriefingId;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -26,30 +26,30 @@
@RequiredArgsConstructor
public class BriefingApi {

private final BriefingFacade briefingFacade;
private final BriefingService briefingService;

@GetMapping("/briefings")
@Parameter(name = "timeOfDay", hidden = true)
@Operation(summary = "03-01Briefing \uD83D\uDCF0 브리핑 목록 조회 V1", description = "")
public CommonResponse<BriefingResponseDTO.BriefingPreviewListDTO> findBriefings(
@ParameterObject @ModelAttribute BriefingRequestParam.BriefingPreviewListParam params) {
return CommonResponse.onSuccess(briefingFacade.findBriefings(params));
return CommonResponse.onSuccess(briefingService.findBriefings(params));
}

@GetMapping("/briefings/{id}")
@Parameter(name = "member", hidden = true)
@Operation(summary = "03-02Briefing \uD83D\uDCF0 브리핑 단건 조회 V1", description = "")
public CommonResponse<BriefingResponseDTO.BriefingDetailDTO> findBriefing(
@PathVariable final Long id, @AuthMember Member member) {
return CommonResponse.onSuccess(briefingFacade.findBriefing(id, member));
return CommonResponse.onSuccess(briefingService.findBriefing(id, member));
}

@CacheEvict(value = "findBriefingsV2", key = "#request.getBriefingType()")
@PostMapping("/briefings")
@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "03-03Briefing \uD83D\uDCF0 브리핑 등록", description = "")
public void createBriefing(@RequestBody final BriefingRequestDTO.BriefingCreate request) {
briefingFacade.createBriefing(request);
briefingService.createBriefing(request);
}

/*
Expand All @@ -69,6 +69,6 @@ public void createBriefing(@RequestBody final BriefingRequestDTO.BriefingCreate
public CommonResponse<BriefingResponseDTO.BriefingUpdateDTO> patchBriefingContent(
@PathVariable(name = "id") Long id,
@RequestBody @Valid BriefingRequestDTO.BriefingUpdateDTO request) {
return CommonResponse.onSuccess(briefingFacade.updateBriefing(id, request));
return CommonResponse.onSuccess(briefingService.updateBriefing(id, request));
}
}
Loading

0 comments on commit 07b9bd5

Please sign in to comment.