Skip to content

Commit

Permalink
fix(article): change sort criteria to take into account publishedAt
Browse files Browse the repository at this point in the history
  • Loading branch information
gracefulBrown committed Jun 5, 2024
1 parent e44c3c7 commit f1f9d86
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ public List<ArticleResponse> getFilteredArticles(final LoginMember member,
.collect(toList());
}

public List<ArticleResponse> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public interface ArticleRepository extends JpaRepository<Article, Long> {

List<Article> findAllByOrderByCreatedAtDesc();

@Query("SELECT a FROM Article a ORDER BY COALESCE(a.publishedAt, a.createdAt) desc")
List<Article> findAllOrderByPublishedAtOrCreatedAt();

@Query("select a from Article a join fetch a.articleBookmarks where a.id = :id")
Optional<Article> findFetchBookmarkById(@Param("id") final Long id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public ResponseEntity<Void> likeArticle(@PathVariable final Long id,
}

@GetMapping
public ResponseEntity<List<ArticleResponse>> getFilteredArticles(@AuthMemberPrincipal final LoginMember member,
public ResponseEntity<List<ArticleResponse>> getArticlesByPublishedAt(@AuthMemberPrincipal final LoginMember member,
@RequestParam("course") final ArticleFilterType course,
@RequestParam("onlyBookmarked") boolean onlyBookmarked) {
final List<ArticleResponse> articleResponses = articleService.getFilteredArticles(member, course, onlyBookmarked);
final List<ArticleResponse> articleResponses = articleService.getArticlesByPublishedAt(member);

return ResponseEntity.ok(articleResponses);
}
Expand Down

0 comments on commit f1f9d86

Please sign in to comment.