Skip to content

Commit

Permalink
#256 feat: 댓글 최신순으로 조회 가능하게 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-haeseung committed Nov 6, 2024
1 parent e95913d commit 26f59cb
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ApiResponse<CommentResponseDTO.CommentDTO> updateComment(
return ApiResponse.onSuccess(SuccessStatus.COMMENT_OK, CommentConverter.toCommentResponseDto(updatedComment));
}

@Operation(summary = "댓글 조회", description = "기본적으로 10개씩 페이지네이션하여 제공됩니다.")
@Operation(summary = "댓글 조회")
@GetMapping("/posts/{post_id}/comments")
public ApiResponse<List<CommentResponseDTO.CommentDTO>> getComments(
@PathVariable("post_id") Long postId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

public interface CommentRepositoryCustom {

List<Comment> findByPostWithMemberInfoOrderByCreatedAtDesc(Long postId);
List<Comment> findByPostWithMemberInfoOrderByCreatedAtAsc(Long postId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ public class CommentRepositoryImpl implements CommentRepositoryCustom {
private final JPAQueryFactory queryFactory;

@Override
public List<Comment> findByPostWithMemberInfoOrderByCreatedAtDesc(Long postId) {
public List<Comment> findByPostWithMemberInfoOrderByCreatedAtAsc(Long postId) {
List<Comment> comments = queryFactory
.selectFrom(comment)
.leftJoin(comment.member, member)
.leftJoin(comment.post, post)
.where(comment.post.postId.eq(postId))
// .offset(pageable.getOffset())
// .limit(pageable.getPageSize())
.orderBy(comment.createdAt.asc())
.fetch();

return comments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public List<Comment> getComments(Long postId, Long memberId) {
}

// business logic: 댓글 조회
List<Comment> comments = commentRepository.findByPostWithMemberInfoOrderByCreatedAtDesc(postId);
List<Comment> comments = commentRepository.findByPostWithMemberInfoOrderByCreatedAtAsc(postId);

// response: comment list 반환
return comments;
Expand Down

0 comments on commit 26f59cb

Please sign in to comment.