Skip to content

Commit

Permalink
Feat: Replies를 반환안하는 메서드 오버로딩
Browse files Browse the repository at this point in the history
  • Loading branch information
seokjun01 committed Nov 8, 2024
1 parent 31ed1a2 commit 52b8fc9
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public record PostResponseDto(
List<PostResponseDto> replies,
Boolean isLikedByUser // 좋아요 여부 확인
) {


public static PostResponseDto from(Post post) {

return new PostResponseDto(
Expand All @@ -41,6 +43,25 @@ public static PostResponseDto from(Post post) {

);
}
// 전체 조회 시 자식 글을 제외하고 부모 글만 가져오기 위한 메서드
public static PostResponseDto withoutReplies(Post post, User user, LikeRepository likeRepository) {
boolean isLikedByUser = user != null && likeRepository.existsByPostAndUser(post, user);

return new PostResponseDto(
post.getId(),
post.getContent(),
post.getViews(),
post.getIsDeleted(),
post.getCreatedAt(),
convertUser(post.getUser()),
convertImagesToDtoList(post),
post.getLikesCount(),
Collections.emptyList(), // replies는 빈 리스트로 설정하여 자식 글을 제외
isLikedByUser
);
}


// 좋아요 여부를 확인하기 위한 메서드 오버로딩
public static PostResponseDto from(Post post, User user, LikeRepository likeRepository) {
boolean isLikedByUser = user != null && likeRepository.existsByPostAndUser(post, user); // 좋아요 여부 확인
Expand Down

0 comments on commit 52b8fc9

Please sign in to comment.