From 8572f8b75afa932ca1a377c243c655ab5482fa4c Mon Sep 17 00:00:00 2001 From: swa07016 Date: Sun, 14 Jan 2024 19:41:44 +0900 Subject: [PATCH] =?UTF-8?q?:recycle:=20Refactor:=20Briefing=20V2=20API=20F?= =?UTF-8?q?acade=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../briefing/briefing/api/BriefingApi.java | 5 +- .../briefing/briefing/api/BriefingV2Api.java | 33 ++----------- .../briefing/application/BriefingFacade.java | 6 +-- .../application/BriefingV2Facade.java | 47 +++++++++++++++++++ 4 files changed, 56 insertions(+), 35 deletions(-) create mode 100644 src/main/java/briefing/briefing/application/BriefingV2Facade.java diff --git a/src/main/java/briefing/briefing/api/BriefingApi.java b/src/main/java/briefing/briefing/api/BriefingApi.java index 6960418..02c01dd 100644 --- a/src/main/java/briefing/briefing/api/BriefingApi.java +++ b/src/main/java/briefing/briefing/api/BriefingApi.java @@ -10,7 +10,6 @@ import briefing.briefing.application.BriefingFacade; import briefing.briefing.application.dto.*; import briefing.common.aop.annotation.CacheEvictByBriefingId; -import briefing.common.enums.APIVersion; import briefing.common.response.CommonResponse; import briefing.member.domain.Member; import briefing.security.handler.annotation.AuthMember; @@ -31,7 +30,7 @@ public class BriefingApi { @Operation(summary = "03-01Briefing \uD83D\uDCF0 브리핑 목록 조회 V1", description = "") public CommonResponse findBriefings( @ParameterObject @ModelAttribute BriefingRequestParam.BriefingPreviewListParam params) { - return CommonResponse.onSuccess(briefingFacade.findBriefings(params, APIVersion.V1)); + return CommonResponse.onSuccess(briefingFacade.findBriefings(params)); } @GetMapping("/briefings/{id}") @@ -39,7 +38,7 @@ public CommonResponse findBriefings( @Operation(summary = "03-02Briefing \uD83D\uDCF0 브리핑 단건 조회 V1", description = "") public CommonResponse findBriefing( @PathVariable final Long id, @AuthMember Member member) { - return CommonResponse.onSuccess(briefingFacade.findBriefing(id, APIVersion.V1, member)); + return CommonResponse.onSuccess(briefingFacade.findBriefing(id, member)); } @CacheEvict(value = "findBriefingsV2", key = "#request.getBriefingType()") diff --git a/src/main/java/briefing/briefing/api/BriefingV2Api.java b/src/main/java/briefing/briefing/api/BriefingV2Api.java index 5a198f7..bfe3d21 100644 --- a/src/main/java/briefing/briefing/api/BriefingV2Api.java +++ b/src/main/java/briefing/briefing/api/BriefingV2Api.java @@ -1,21 +1,14 @@ package briefing.briefing.api; -import java.util.List; -import java.util.Optional; - import org.springdoc.core.annotations.ParameterObject; import org.springframework.cache.annotation.Cacheable; import org.springframework.web.bind.annotation.*; +import briefing.briefing.application.BriefingV2Facade; import briefing.briefing.application.dto.BriefingRequestParam; import briefing.briefing.application.dto.BriefingResponseDTO; -import briefing.briefing.application.service.BriefingCommandService; -import briefing.briefing.application.service.BriefingQueryService; -import briefing.briefing.domain.Briefing; -import briefing.common.enums.APIVersion; import briefing.common.response.CommonResponse; import briefing.member.domain.Member; -import briefing.scrap.application.ScrapQueryService; import briefing.security.handler.annotation.AuthMember; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -27,18 +20,14 @@ @RequiredArgsConstructor @RequestMapping("/v2") public class BriefingV2Api { - private final BriefingQueryService briefingQueryService; - private final BriefingCommandService briefingCommandService; - private final ScrapQueryService scrapQueryService; + private final BriefingV2Facade briefingFacade; @GetMapping("/briefings") @Operation(summary = "03-01Briefing \uD83D\uDCF0 브리핑 목록 조회 V2", description = "") @Cacheable(value = "findBriefingsV2", key = "#params.getType()") public CommonResponse findBriefingsV2( @ParameterObject @ModelAttribute BriefingRequestParam.BriefingPreviewListParam params) { - List briefingList = briefingQueryService.findBriefings(params, APIVersion.V2); - return CommonResponse.onSuccess( - BriefingConverter.toBriefingPreviewListDTOV2(params.getDate(), briefingList)); + return CommonResponse.onSuccess(briefingFacade.findBriefings(params)); } @GetMapping("/briefings/{id}") @@ -46,20 +35,6 @@ public CommonResponse findBriefing @Parameter(name = "member", hidden = true) public CommonResponse findBriefingV2( @PathVariable final Long id, @AuthMember Member member) { - - Boolean isScrap = - Optional.ofNullable(member) - .map(m -> scrapQueryService.existsByMemberIdAndBriefingId(m.getId(), id)) - .orElseGet(() -> Boolean.FALSE); - - Boolean isBriefingOpen = false; - Boolean isWarning = false; - - return CommonResponse.onSuccess( - BriefingConverter.toBriefingDetailDTOV2( - briefingQueryService.findBriefing(id, APIVersion.V2), - isScrap, - isBriefingOpen, - isWarning)); + return CommonResponse.onSuccess(briefingFacade.findBriefing(id, member)); } } diff --git a/src/main/java/briefing/briefing/application/BriefingFacade.java b/src/main/java/briefing/briefing/application/BriefingFacade.java index 379b4d4..0d947ff 100644 --- a/src/main/java/briefing/briefing/application/BriefingFacade.java +++ b/src/main/java/briefing/briefing/application/BriefingFacade.java @@ -30,17 +30,17 @@ public class BriefingFacade { private final BriefingCommandService briefingCommandService; private final ArticleCommandService articleCommandService; private final BriefingArticleCommandService briefingArticleCommandService; + private static final APIVersion version = APIVersion.V1; @Transactional(readOnly = true) public BriefingResponseDTO.BriefingPreviewListDTO findBriefings( - BriefingRequestParam.BriefingPreviewListParam params, APIVersion version) { + BriefingRequestParam.BriefingPreviewListParam params) { List briefingList = briefingQueryService.findBriefings(params, version); return BriefingConverter.toBriefingPreviewListDTO(params.getDate(), briefingList); } @Transactional(readOnly = true) - public BriefingResponseDTO.BriefingDetailDTO findBriefing( - final Long id, final APIVersion version, Member member) { + public BriefingResponseDTO.BriefingDetailDTO findBriefing(final Long id, Member member) { Boolean isScrap = Optional.ofNullable(member) .map(m -> scrapQueryService.existsByMemberIdAndBriefingId(m.getId(), id)) diff --git a/src/main/java/briefing/briefing/application/BriefingV2Facade.java b/src/main/java/briefing/briefing/application/BriefingV2Facade.java new file mode 100644 index 0000000..0051bce --- /dev/null +++ b/src/main/java/briefing/briefing/application/BriefingV2Facade.java @@ -0,0 +1,47 @@ +package briefing.briefing.application; + +import java.util.List; +import java.util.Optional; + +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import briefing.briefing.api.BriefingConverter; +import briefing.briefing.application.dto.BriefingRequestParam; +import briefing.briefing.application.dto.BriefingResponseDTO; +import briefing.briefing.application.service.BriefingQueryService; +import briefing.briefing.domain.Briefing; +import briefing.common.enums.APIVersion; +import briefing.member.domain.Member; +import briefing.scrap.application.ScrapQueryService; +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +public class BriefingV2Facade { + + private final BriefingQueryService briefingQueryService; + private final ScrapQueryService scrapQueryService; + private static final APIVersion version = APIVersion.V2; + + @Transactional(readOnly = true) + public BriefingResponseDTO.BriefingPreviewListDTOV2 findBriefings( + BriefingRequestParam.BriefingPreviewListParam params) { + List briefingList = briefingQueryService.findBriefings(params, version); + return BriefingConverter.toBriefingPreviewListDTOV2(params.getDate(), briefingList); + } + + @Transactional(readOnly = true) + public BriefingResponseDTO.BriefingDetailDTOV2 findBriefing(final Long id, Member member) { + Boolean isScrap = + Optional.ofNullable(member) + .map(m -> scrapQueryService.existsByMemberIdAndBriefingId(m.getId(), id)) + .orElseGet(() -> Boolean.FALSE); + + Boolean isBriefingOpen = false; + Boolean isWarning = false; + + return BriefingConverter.toBriefingDetailDTOV2( + briefingQueryService.findBriefing(id, version), isScrap, isBriefingOpen, isWarning); + } +}