diff --git a/src/main/java/me/snaptime/reply/domain/ChildReply.java b/src/main/java/me/snaptime/reply/domain/ChildReply.java index 79c195d3..684f1971 100644 --- a/src/main/java/me/snaptime/reply/domain/ChildReply.java +++ b/src/main/java/me/snaptime/reply/domain/ChildReply.java @@ -33,7 +33,7 @@ public class ChildReply extends BaseTimeEntity { @JoinColumn(name = "parent_reply_id",nullable = false) private ParentReply parentReply; - @OneToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.EAGER) @OnDelete(action = OnDeleteAction.SET_NULL) @JoinColumn(name = "reply_tag_user_id", nullable = true) private User replyTagUser; diff --git a/src/main/java/me/snaptime/reply/dto/res/ParentReplyInfoResDto.java b/src/main/java/me/snaptime/reply/dto/res/ParentReplyInfoResDto.java index fed36ce4..64f6004c 100644 --- a/src/main/java/me/snaptime/reply/dto/res/ParentReplyInfoResDto.java +++ b/src/main/java/me/snaptime/reply/dto/res/ParentReplyInfoResDto.java @@ -15,9 +15,10 @@ public record ParentReplyInfoResDto( String writerUserName, String content, Long replyId, - String timeAgo + String timeAgo, + Long childReplyCnt ) { - public static ParentReplyInfoResDto toDto(Tuple tuple, String profilePhotoURL, String timeAgo){ + public static ParentReplyInfoResDto toDto(Tuple tuple, String profilePhotoURL, String timeAgo,Long childReplyCnt){ return ParentReplyInfoResDto.builder() .writerEmail(tuple.get(user.email)) .writerProfilePhotoURL(profilePhotoURL) @@ -25,6 +26,7 @@ public static ParentReplyInfoResDto toDto(Tuple tuple, String profilePhotoURL, S .content(tuple.get(parentReply.content)) .replyId(tuple.get(parentReply.parentReplyId)) .timeAgo(timeAgo) + .childReplyCnt(childReplyCnt) .build(); } } diff --git a/src/main/java/me/snaptime/reply/repository/ChildReplyPagingRepository.java b/src/main/java/me/snaptime/reply/repository/ChildReplyPagingRepository.java index 03aa51c0..abf7bdbd 100644 --- a/src/main/java/me/snaptime/reply/repository/ChildReplyPagingRepository.java +++ b/src/main/java/me/snaptime/reply/repository/ChildReplyPagingRepository.java @@ -7,4 +7,6 @@ public interface ChildReplyPagingRepository { List findReplyPage(Long parentReplyId, Long pageNum); + + Long countByParentReplyId(Long parentReplyId); } diff --git a/src/main/java/me/snaptime/reply/repository/impl/ChildReplyPagingRepositoryImpl.java b/src/main/java/me/snaptime/reply/repository/impl/ChildReplyPagingRepositoryImpl.java index 59a7fb04..9d3f4180 100644 --- a/src/main/java/me/snaptime/reply/repository/impl/ChildReplyPagingRepositoryImpl.java +++ b/src/main/java/me/snaptime/reply/repository/impl/ChildReplyPagingRepositoryImpl.java @@ -39,4 +39,14 @@ public List findReplyPage(Long parentReplyId, Long pageNum) { return childReplies; } + + @Override + public Long countByParentReplyId(Long parentReplyId) { + Long childReplyCnt = jpaQueryFactory.select( childReply.count() ) + .from(childReply) + .where(childReply.parentReply.parentReplyId.eq(parentReplyId)) + .fetchOne(); + + return childReplyCnt; + } } diff --git a/src/main/java/me/snaptime/reply/service/impl/ReplyServiceImpl.java b/src/main/java/me/snaptime/reply/service/impl/ReplyServiceImpl.java index c84ce757..2b434291 100644 --- a/src/main/java/me/snaptime/reply/service/impl/ReplyServiceImpl.java +++ b/src/main/java/me/snaptime/reply/service/impl/ReplyServiceImpl.java @@ -108,7 +108,9 @@ public ParentReplyPagingResDto findParentReplyPage(Long snapId, Long pageNum){ { String profilePhotoURL = urlComponent.makeProfileURL(tuple.get(user.profilePhoto.profilePhotoId)); String timeAgo = TimeAgoCalculator.findTimeAgo(tuple.get(parentReply.lastModifiedDate)); - return ParentReplyInfoResDto.toDto(tuple,profilePhotoURL,timeAgo); + Long childReplyCnt = childReplyRepository.countByParentReplyId(tuple.get(parentReply.parentReplyId)); + + return ParentReplyInfoResDto.toDto(tuple,profilePhotoURL,timeAgo,childReplyCnt); }).collect(Collectors.toList()); return ParentReplyPagingResDto.toDto(parentReplyInfoResDtos, hasNextPage);