diff --git a/backend/src/main/java/wooteco/prolog/article/application/ArticleService.java b/backend/src/main/java/wooteco/prolog/article/application/ArticleService.java index de9ca0ff1..e8260f080 100644 --- a/backend/src/main/java/wooteco/prolog/article/application/ArticleService.java +++ b/backend/src/main/java/wooteco/prolog/article/application/ArticleService.java @@ -107,6 +107,12 @@ public List getFilteredArticles(final LoginMember member, .collect(toList()); } + public List getArticlesByPublishedAt(final LoginMember member) { + return articleRepository.findAllOrderByPublishedAtOrCreatedAt().stream() + .map(article -> ArticleResponse.of(article, member.getId())) + .collect(toList()); + } + @Transactional public void updateViewCount(final Long id) { final Article article = articleRepository.findById(id) diff --git a/backend/src/main/java/wooteco/prolog/article/domain/repository/ArticleRepository.java b/backend/src/main/java/wooteco/prolog/article/domain/repository/ArticleRepository.java index 9853141b8..cf858bb11 100644 --- a/backend/src/main/java/wooteco/prolog/article/domain/repository/ArticleRepository.java +++ b/backend/src/main/java/wooteco/prolog/article/domain/repository/ArticleRepository.java @@ -12,6 +12,9 @@ public interface ArticleRepository extends JpaRepository { List
findAllByOrderByCreatedAtDesc(); + @Query("SELECT a FROM Article a ORDER BY COALESCE(a.publishedAt, a.createdAt) desc") + List
findAllOrderByPublishedAtOrCreatedAt(); + @Query("select a from Article a join fetch a.articleBookmarks where a.id = :id") Optional
findFetchBookmarkById(@Param("id") final Long id); diff --git a/backend/src/main/java/wooteco/prolog/article/ui/ArticleController.java b/backend/src/main/java/wooteco/prolog/article/ui/ArticleController.java index 2118fa194..8caabb18b 100644 --- a/backend/src/main/java/wooteco/prolog/article/ui/ArticleController.java +++ b/backend/src/main/java/wooteco/prolog/article/ui/ArticleController.java @@ -69,10 +69,10 @@ public ResponseEntity likeArticle(@PathVariable final Long id, } @GetMapping - public ResponseEntity> getFilteredArticles(@AuthMemberPrincipal final LoginMember member, + public ResponseEntity> getArticlesByPublishedAt(@AuthMemberPrincipal final LoginMember member, @RequestParam("course") final ArticleFilterType course, @RequestParam("onlyBookmarked") boolean onlyBookmarked) { - final List articleResponses = articleService.getFilteredArticles(member, course, onlyBookmarked); + final List articleResponses = articleService.getArticlesByPublishedAt(member); return ResponseEntity.ok(articleResponses); }