From 5b44cdc1cff4d2f6b942ef1410b2c3a4dbd26ce9 Mon Sep 17 00:00:00 2001 From: LeeYuJoon Date: Thu, 28 Nov 2024 20:01:08 +0900 Subject: [PATCH] :bug: Fix Scrap Related: --- .../serviceImpl/ReportServiceImpl.java | 41 ++++++++----------- .../serviceImpl/ScrapServiceImpl.java | 2 +- .../java/the_monitor/domain/model/Scrap.java | 2 +- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/main/java/the_monitor/application/serviceImpl/ReportServiceImpl.java b/src/main/java/the_monitor/application/serviceImpl/ReportServiceImpl.java index bc0c3ab..85d18b3 100644 --- a/src/main/java/the_monitor/application/serviceImpl/ReportServiceImpl.java +++ b/src/main/java/the_monitor/application/serviceImpl/ReportServiceImpl.java @@ -23,6 +23,7 @@ import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; @Service @@ -77,7 +78,7 @@ public ReportCreateResponse createReports(ReportCreateRequest request, Multipart // 각 카테고리별로 ReportArticle 생성 및 저장 createAndSaveReportArticlesByCategories(report, request); - unScrapArticles(request, clientId); + scrapService.unScrapArticle(); updateAdded(request); @@ -573,26 +574,6 @@ private void setReportArticleDefaultCategory(Report report, ReportArticle report } - private void unScrapArticles(ReportCreateRequest request, Long clientId) { - - List articleIds = getArticleIdsByReportCreateRequest(request); - - for (Long articleId : articleIds) { - Article article = articleService.findArticleById(articleId); - article.setScrapStatus(false); - } - - List scraps = scrapService.findAllByClientId(clientId); - - List scrapIds = scraps.stream() - .map(Scrap::getId) - .toList(); - - scrapService.deleteScraps(scrapIds); - - - } - private void updateAdded(ReportCreateRequest request) { List articleIds = getArticleIdsByReportCreateRequest(request); @@ -607,11 +588,21 @@ private void updateAdded(ReportCreateRequest request) { private List getArticleIdsByReportCreateRequest(ReportCreateRequest request) { - return request.getReportCategoryTypeRequest().getReportCategorySelfRequests().stream() - .map(ReportCategoryRequest::getArticleId) - .flatMap(Collection::stream) + // 각 카테고리의 articleId 리스트를 스트림으로 병합 + return Stream.concat( + Stream.concat( + request.getReportCategoryTypeRequest().getReportCategorySelfRequests().stream() + .map(ReportCategoryRequest::getArticleId) + .flatMap(Collection::stream), + request.getReportCategoryTypeRequest().getReportCategoryCompetitorRequests().stream() + .map(ReportCategoryRequest::getArticleId) + .flatMap(Collection::stream) + ), + request.getReportCategoryTypeRequest().getReportCategoryIndustryRequests().stream() + .map(ReportCategoryRequest::getArticleId) + .flatMap(Collection::stream) + ) .toList(); - } } diff --git a/src/main/java/the_monitor/application/serviceImpl/ScrapServiceImpl.java b/src/main/java/the_monitor/application/serviceImpl/ScrapServiceImpl.java index e020805..49737a0 100644 --- a/src/main/java/the_monitor/application/serviceImpl/ScrapServiceImpl.java +++ b/src/main/java/the_monitor/application/serviceImpl/ScrapServiceImpl.java @@ -186,7 +186,7 @@ private Map> groupedByCategory(List s return scrappedArticles.stream() .map(scrap -> ScrapArticleDto.builder() - .originalArticleId(scrap.getId()) + .originalArticleId(scrap.getOriginalArticleId()) .scrapId(scrap.getId()) .keyword(scrap.getKeyword()) .title(scrap.getTitle()) diff --git a/src/main/java/the_monitor/domain/model/Scrap.java b/src/main/java/the_monitor/domain/model/Scrap.java index ca93f0c..cb0cc5a 100644 --- a/src/main/java/the_monitor/domain/model/Scrap.java +++ b/src/main/java/the_monitor/domain/model/Scrap.java @@ -25,7 +25,7 @@ public class Scrap extends BaseTimeEntity { @Column(name = "scrap_title", nullable = false) private String title; - @Column(name = "scrap_url", nullable = false) + @Column(name = "scrap_url", nullable = false, length = 1024) private String url; @Column(name = "scrap_keyword", nullable = false)