Skip to content

Commit

Permalink
🐛 Fix Scrap
Browse files Browse the repository at this point in the history
Related:
  • Loading branch information
L-U-Ready committed Nov 28, 2024
1 parent 3134e86 commit 5b44cdc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;


@Service
Expand Down Expand Up @@ -77,7 +78,7 @@ public ReportCreateResponse createReports(ReportCreateRequest request, Multipart
// 각 카테고리별로 ReportArticle 생성 및 저장
createAndSaveReportArticlesByCategories(report, request);

unScrapArticles(request, clientId);
scrapService.unScrapArticle();

updateAdded(request);

Expand Down Expand Up @@ -573,26 +574,6 @@ private void setReportArticleDefaultCategory(Report report, ReportArticle report

}

private void unScrapArticles(ReportCreateRequest request, Long clientId) {

List<Long> articleIds = getArticleIdsByReportCreateRequest(request);

for (Long articleId : articleIds) {
Article article = articleService.findArticleById(articleId);
article.setScrapStatus(false);
}

List<Scrap> scraps = scrapService.findAllByClientId(clientId);

List<Long> scrapIds = scraps.stream()
.map(Scrap::getId)
.toList();

scrapService.deleteScraps(scrapIds);


}

private void updateAdded(ReportCreateRequest request) {

List<Long> articleIds = getArticleIdsByReportCreateRequest(request);
Expand All @@ -607,11 +588,21 @@ private void updateAdded(ReportCreateRequest request) {

private List<Long> 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();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private Map<CategoryType, List<ScrapArticleDto>> groupedByCategory(List<Scrap> s

return scrappedArticles.stream()
.map(scrap -> ScrapArticleDto.builder()
.originalArticleId(scrap.getId())
.originalArticleId(scrap.getOriginalArticleId())
.scrapId(scrap.getId())
.keyword(scrap.getKeyword())
.title(scrap.getTitle())
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/the_monitor/domain/model/Scrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5b44cdc

Please sign in to comment.