Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,38 @@ public class CommentResponse {
private String content;
private LocalDateTime createdDate;
private LocalDateTime updatedDate;
private UUID parentCommentId;
private List<CommentResponse> replies;

public static CommentResponse from(Comment comment) {
UUID parentId = (comment.getParentComment() != null)
? comment.getParentComment().getCommentId()
: null;

return CommentResponse.builder()
.commentId(comment.getCommentId())
.user(UserInfoResponse.from(comment.getUser()))
.postId(comment.getPost().getPostId())
.content(comment.getContent())
.createdDate(comment.getCreatedDate())
.updatedDate(comment.getUpdatedDate())
.parentCommentId(parentId)
.build();
}

public static CommentResponse from(Comment comment, List<CommentResponse> replies) {
UUID parentCommentId = (comment.getParentComment() != null)
? comment.getParentComment().getCommentId()
: null;

return CommentResponse.builder()
.commentId(comment.getCommentId())
.user(UserInfoResponse.from(comment.getUser()))
.postId(comment.getPost().getPostId())
.content(comment.getContent())
.createdDate(comment.getCreatedDate())
.updatedDate(comment.getUpdatedDate())
.parentCommentId(parentCommentId)
.replies(replies)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,13 @@ public PostResponse getPostDetail(UUID postId, UUID userId, int pageNumber, int

// 부모 댓글을 CommentResponse DTO로 변환
Page<CommentResponse> commentResponses = parentComments.map(parent -> {

// 해당 부모 댓글의 자식 댓글 목록을 조회
List<Comment> childComments = commentRepository.findByParentComment(parent);

// 부모 객체 연결
childComments.forEach(child -> child.setParentComment(parent));

// 자식 댓글 목록을 CommentResponse DTO 리스트로 변환
List<CommentResponse> replyResponses = childComments.stream()
.map(CommentResponse::from)
Expand Down