Skip to content

Commit

Permalink
[Merge] main <- seyong#155-refactoring
Browse files Browse the repository at this point in the history
[Fix] 댓글 조회 시 대댓글 수를 함께 반환
  • Loading branch information
parseyong authored Oct 10, 2024
2 parents 629249d + 8af1be9 commit 439f0df
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/me/snaptime/reply/domain/ChildReply.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ 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)
.writerUserName(tuple.get(user.name))
.content(tuple.get(parentReply.content))
.replyId(tuple.get(parentReply.parentReplyId))
.timeAgo(timeAgo)
.childReplyCnt(childReplyCnt)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
public interface ChildReplyPagingRepository {

List<ChildReply> findReplyPage(Long parentReplyId, Long pageNum);

Long countByParentReplyId(Long parentReplyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ public List<ChildReply> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 439f0df

Please sign in to comment.