diff --git a/src/main/java/balancetalk/module/post/domain/Post.java b/src/main/java/balancetalk/module/post/domain/Post.java index 41a918441..41b446733 100644 --- a/src/main/java/balancetalk/module/post/domain/Post.java +++ b/src/main/java/balancetalk/module/post/domain/Post.java @@ -87,6 +87,13 @@ public long likesCount() { } return likes.size(); } + + public long commentsCount() { + if (comments == null) { + return 0; + } + return comments.size(); + } @PrePersist public void init() { diff --git a/src/main/java/balancetalk/module/post/dto/PostResponse.java b/src/main/java/balancetalk/module/post/dto/PostResponse.java index 226341a12..391916c12 100644 --- a/src/main/java/balancetalk/module/post/dto/PostResponse.java +++ b/src/main/java/balancetalk/module/post/dto/PostResponse.java @@ -57,6 +57,9 @@ public class PostResponse { @Schema(description = "전체 투표 수", example = "15") private int totalVotesCount; + @Schema(description = "댓글 개수", example = "12") + private long commentsCount; + @JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss") @Schema(description = "게시글 작성일", example = "2023-12-25T15:30:00") private LocalDateTime createdAt; @@ -83,6 +86,7 @@ public static PostResponse fromEntity(Post post, Member member, boolean myLike, .balanceOptions(getBalanceOptions(post)) .postTags(getPostTags(post)) .totalVotesCount(getTotalVotes(post)) + .commentsCount(post.commentsCount()) .createdAt(post.getCreatedAt()) .createdBy(post.getMember().getNickname()) .profileImageUrl(getProfileImageUrl(post.getMember()))