Skip to content

Commit

Permalink
refactor: (#833) 인기순 전체 게시글 목록 조회 기능의 QueryDsl 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdtls690 committed Nov 2, 2023
1 parent 1d3a5e1 commit 8d08f39
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ public List<Post> findPostsWithFilteringAndPaging(
final Long categoryId,
final Pageable pageable
) {
return jpaQueryFactory
.selectDistinct(post)
List<Long> postIds = jpaQueryFactory
.select(post.id)
.from(post)
.join(post.writer).fetchJoin()
.leftJoin(post.postCategories, postCategory)
.where(
categoryIdEq(categoryId),
Expand All @@ -65,6 +64,14 @@ public List<Post> findPostsWithFilteringAndPaging(
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

return jpaQueryFactory
.selectDistinct(post)
.from(post)
.join(post.writer).fetchJoin()
.where(post.id.in(postIds))
.orderBy(orderBy(postSortType))
.fetch();
}

private BooleanExpression categoryIdEq(final Long categoryId) {
Expand Down

0 comments on commit 8d08f39

Please sign in to comment.