-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor/161 : Facade 도입 & 클래스 의존관계 개선 (#162)
* ♻️ Refactor: Briefing V1 Facade 도입 * ♻️ Refactor: Briefing V2 API Facade 추가
- Loading branch information
Showing
10 changed files
with
203 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
src/main/java/briefing/briefing/application/BriefingCommandService.java
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
src/main/java/briefing/briefing/application/BriefingFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
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.BriefingRequestDTO; | ||
import briefing.briefing.application.dto.BriefingRequestParam; | ||
import briefing.briefing.application.dto.BriefingResponseDTO; | ||
import briefing.briefing.application.service.ArticleCommandService; | ||
import briefing.briefing.application.service.BriefingArticleCommandService; | ||
import briefing.briefing.application.service.BriefingCommandService; | ||
import briefing.briefing.application.service.BriefingQueryService; | ||
import briefing.briefing.domain.Article; | ||
import briefing.briefing.domain.Briefing; | ||
import briefing.briefing.domain.BriefingArticle; | ||
import briefing.common.enums.APIVersion; | ||
import briefing.member.domain.Member; | ||
import briefing.scrap.application.ScrapQueryService; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class BriefingFacade { | ||
private final ScrapQueryService scrapQueryService; | ||
private final BriefingQueryService briefingQueryService; | ||
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) { | ||
List<Briefing> briefingList = briefingQueryService.findBriefings(params, version); | ||
return BriefingConverter.toBriefingPreviewListDTO(params.getDate(), briefingList); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public BriefingResponseDTO.BriefingDetailDTO 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.toBriefingDetailDTO( | ||
briefingQueryService.findBriefing(id, version), isScrap, isBriefingOpen, isWarning); | ||
} | ||
|
||
@Transactional | ||
public void createBriefing(final BriefingRequestDTO.BriefingCreate request) { | ||
final List<Article> articles = | ||
request.getArticles().stream().map(BriefingConverter::toArticle).toList(); | ||
|
||
Briefing createdBriefing = | ||
briefingCommandService.create(BriefingConverter.toBriefing(request)); | ||
List<Article> createdArticles = articleCommandService.createAll(articles); | ||
|
||
final List<BriefingArticle> briefingArticles = | ||
createdArticles.stream() | ||
.map(article -> new BriefingArticle(createdBriefing, article)) | ||
.toList(); | ||
|
||
briefingArticleCommandService.createAll(briefingArticles); | ||
} | ||
|
||
@Transactional | ||
public BriefingResponseDTO.BriefingUpdateDTO updateBriefing( | ||
Long id, final BriefingRequestDTO.BriefingUpdateDTO request) { | ||
Briefing briefing = briefingQueryService.findBriefing(id, APIVersion.V1); | ||
Briefing updatedBriefing = | ||
briefingCommandService.update( | ||
briefing, request.getTitle(), request.getSubTitle(), request.getContent()); | ||
return BriefingConverter.toBriefingUpdateDTO(updatedBriefing); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/briefing/briefing/application/BriefingV2Facade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Briefing> 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); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/briefing/briefing/application/service/ArticleCommandService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package briefing.briefing.application.service; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import briefing.briefing.domain.Article; | ||
import briefing.briefing.domain.repository.ArticleRepository; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ArticleCommandService { | ||
private final ArticleRepository articleRepository; | ||
|
||
public List<Article> createAll(final List<Article> articles) { | ||
return articleRepository.saveAll(articles); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/briefing/briefing/application/service/BriefingArticleCommandService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package briefing.briefing.application.service; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import briefing.briefing.domain.BriefingArticle; | ||
import briefing.briefing.domain.repository.BriefingArticleRepository; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class BriefingArticleCommandService { | ||
private final BriefingArticleRepository briefingArticleRepository; | ||
|
||
public List<BriefingArticle> createAll(final List<BriefingArticle> briefingArticles) { | ||
return briefingArticleRepository.saveAll(briefingArticles); | ||
} | ||
} |
Oops, something went wrong.