From 6ed56779236746a8a2800a3df2387011a8b71036 Mon Sep 17 00:00:00 2001 From: LeeYuJoon Date: Thu, 28 Nov 2024 17:36:36 +0900 Subject: [PATCH 1/2] :sparkles: IsAdded implemented Related: --- .../serviceImpl/ReportServiceImpl.java | 31 ++++++++++++++++--- .../the_monitor/domain/model/Article.java | 6 ++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/main/java/the_monitor/application/serviceImpl/ReportServiceImpl.java b/src/main/java/the_monitor/application/serviceImpl/ReportServiceImpl.java index 3d5af9f..bc0c3ab 100644 --- a/src/main/java/the_monitor/application/serviceImpl/ReportServiceImpl.java +++ b/src/main/java/the_monitor/application/serviceImpl/ReportServiceImpl.java @@ -14,6 +14,7 @@ import the_monitor.common.ErrorStatus; import the_monitor.domain.enums.CategoryType; import the_monitor.domain.model.*; +import the_monitor.domain.repository.ArticleRepository; import the_monitor.domain.repository.ReportArticleRepository; import the_monitor.domain.repository.ReportCategoryRepository; import the_monitor.domain.repository.ReportRepository; @@ -42,6 +43,7 @@ public class ReportServiceImpl implements ReportService { private final S3Service s3Service; private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + private final ArticleRepository articleRepository; @Override public List getReports() { @@ -77,6 +79,8 @@ public ReportCreateResponse createReports(ReportCreateRequest request, Multipart unScrapArticles(request, clientId); + updateAdded(request); + return ReportCreateResponse.builder() .reportId(report.getId()) .build(); @@ -571,10 +575,7 @@ private void setReportArticleDefaultCategory(Report report, ReportArticle report private void unScrapArticles(ReportCreateRequest request, Long clientId) { - List articleIds = request.getReportCategoryTypeRequest().getReportCategorySelfRequests().stream() - .map(ReportCategoryRequest::getArticleId) - .flatMap(Collection::stream) - .toList(); + List articleIds = getArticleIdsByReportCreateRequest(request); for (Long articleId : articleIds) { Article article = articleService.findArticleById(articleId); @@ -591,4 +592,26 @@ private void unScrapArticles(ReportCreateRequest request, Long clientId) { } + + private void updateAdded(ReportCreateRequest request) { + + List articleIds = getArticleIdsByReportCreateRequest(request); + + for (Long articleId : articleIds) { + Article article = articleService.findArticleById(articleId); + article.setAddedStatus(true); + articleRepository.save(article); + } + + } + + private List getArticleIdsByReportCreateRequest(ReportCreateRequest request) { + + return request.getReportCategoryTypeRequest().getReportCategorySelfRequests().stream() + .map(ReportCategoryRequest::getArticleId) + .flatMap(Collection::stream) + .toList(); + + } + } diff --git a/src/main/java/the_monitor/domain/model/Article.java b/src/main/java/the_monitor/domain/model/Article.java index f47a5fe..90a64a6 100644 --- a/src/main/java/the_monitor/domain/model/Article.java +++ b/src/main/java/the_monitor/domain/model/Article.java @@ -77,7 +77,13 @@ public Article(String title, this.keyword = keyword; } + public void setScrapStatus(boolean scrapped) { this.scrapped = scrapped; } + + public void setAddedStatus(boolean added) { + this.added = added; + } + } From d722e80de6449c8fc28f5d8fe9d17360fcfde068 Mon Sep 17 00:00:00 2001 From: LeeYuJoon Date: Thu, 28 Nov 2024 17:39:04 +0900 Subject: [PATCH 2/2] :sparkles: IsRead Implemented Related: --- .../application/service/ArticleService.java | 3 +++ .../application/serviceImpl/ArticleServiceImpl.java | 11 +++++++++++ src/main/java/the_monitor/domain/model/Article.java | 4 ++++ .../the_monitor/presentation/ArticleController.java | 7 +++++++ 4 files changed, 25 insertions(+) diff --git a/src/main/java/the_monitor/application/service/ArticleService.java b/src/main/java/the_monitor/application/service/ArticleService.java index c4700c9..4d3955e 100644 --- a/src/main/java/the_monitor/application/service/ArticleService.java +++ b/src/main/java/the_monitor/application/service/ArticleService.java @@ -16,4 +16,7 @@ public interface ArticleService { PageResponse getArticlesByKeyword(CategoryType categoryType, Long keywordId, int page); Article findArticleById(Long articleId); + + String readArticle(Long articleId); + } diff --git a/src/main/java/the_monitor/application/serviceImpl/ArticleServiceImpl.java b/src/main/java/the_monitor/application/serviceImpl/ArticleServiceImpl.java index 02774e7..2b9057a 100644 --- a/src/main/java/the_monitor/application/serviceImpl/ArticleServiceImpl.java +++ b/src/main/java/the_monitor/application/serviceImpl/ArticleServiceImpl.java @@ -110,6 +110,17 @@ public PageResponse getArticlesByKeyword(CategoryType categoryT return getArticleResponsePageResponse(articlePage); } + @Override + @Transactional + public String readArticle(Long articleId) { + + Article article = findArticleById(articleId); + article.setReadStatus(true); + + return "기사 읽기 변경"; + + } + private PageResponse getArticleResponsePageResponse(Page
articlePage) { List articleDtos = articlePage.getContent().stream() .map(article -> ArticleGoogleDto.builder() diff --git a/src/main/java/the_monitor/domain/model/Article.java b/src/main/java/the_monitor/domain/model/Article.java index 90a64a6..95c6071 100644 --- a/src/main/java/the_monitor/domain/model/Article.java +++ b/src/main/java/the_monitor/domain/model/Article.java @@ -86,4 +86,8 @@ public void setAddedStatus(boolean added) { this.added = added; } + public void setReadStatus(boolean read) { + this.read = read; + } + } diff --git a/src/main/java/the_monitor/presentation/ArticleController.java b/src/main/java/the_monitor/presentation/ArticleController.java index 79c2df7..fbd3333 100644 --- a/src/main/java/the_monitor/presentation/ArticleController.java +++ b/src/main/java/the_monitor/presentation/ArticleController.java @@ -35,4 +35,11 @@ public ApiResponse> getArticlesByKeyword(@RequestP } + @PatchMapping("/read") + public ApiResponse readArticle(@RequestParam("articleId") Long articleId) { + + return ApiResponse.onSuccess(articleService.readArticle(articleId)); + + } + }