Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
L-U-Ready committed Nov 28, 2024
2 parents 7b724aa + d722e80 commit 216479e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ public interface ArticleService {
PageResponse<ArticleResponse> getArticlesByKeyword(CategoryType categoryType, Long keywordId, int page);

Article findArticleById(Long articleId);

String readArticle(Long articleId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ public PageResponse<ArticleResponse> getArticlesByKeyword(CategoryType categoryT
return getArticleResponsePageResponse(articlePage);
}

@Override
@Transactional
public String readArticle(Long articleId) {

Article article = findArticleById(articleId);
article.setReadStatus(true);

return "기사 읽기 변경";

}

private PageResponse<ArticleResponse> getArticleResponsePageResponse(Page<Article> articlePage) {
List<ArticleGoogleDto> articleDtos = articlePage.getContent().stream()
.map(article -> ArticleGoogleDto.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ReportListResponse> getReports() {
Expand Down Expand Up @@ -77,6 +79,8 @@ public ReportCreateResponse createReports(ReportCreateRequest request, Multipart

unScrapArticles(request, clientId);

updateAdded(request);

return ReportCreateResponse.builder()
.reportId(report.getId())
.build();
Expand Down Expand Up @@ -571,10 +575,7 @@ private void setReportArticleDefaultCategory(Report report, ReportArticle report

private void unScrapArticles(ReportCreateRequest request, Long clientId) {

List<Long> articleIds = request.getReportCategoryTypeRequest().getReportCategorySelfRequests().stream()
.map(ReportCategoryRequest::getArticleId)
.flatMap(Collection::stream)
.toList();
List<Long> articleIds = getArticleIdsByReportCreateRequest(request);

for (Long articleId : articleIds) {
Article article = articleService.findArticleById(articleId);
Expand All @@ -591,4 +592,26 @@ private void unScrapArticles(ReportCreateRequest request, Long clientId) {


}

private void updateAdded(ReportCreateRequest request) {

List<Long> articleIds = getArticleIdsByReportCreateRequest(request);

for (Long articleId : articleIds) {
Article article = articleService.findArticleById(articleId);
article.setAddedStatus(true);
articleRepository.save(article);
}

}

private List<Long> getArticleIdsByReportCreateRequest(ReportCreateRequest request) {

return request.getReportCategoryTypeRequest().getReportCategorySelfRequests().stream()
.map(ReportCategoryRequest::getArticleId)
.flatMap(Collection::stream)
.toList();

}

}
10 changes: 10 additions & 0 deletions src/main/java/the_monitor/domain/model/Article.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,17 @@ public Article(String title,
this.keyword = keyword;

}

public void setScrapStatus(boolean scrapped) {
this.scrapped = scrapped;
}

public void setAddedStatus(boolean added) {
this.added = added;
}

public void setReadStatus(boolean read) {
this.read = read;
}

}
7 changes: 7 additions & 0 deletions src/main/java/the_monitor/presentation/ArticleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ public ApiResponse<PageResponse<ArticleResponse>> getArticlesByKeyword(@RequestP

}

@PatchMapping("/read")
public ApiResponse<String> readArticle(@RequestParam("articleId") Long articleId) {

return ApiResponse.onSuccess(articleService.readArticle(articleId));

}

}

0 comments on commit 216479e

Please sign in to comment.