Skip to content

Commit

Permalink
게시글 조회 응답에 댓글 개수 추가 (#271)
Browse files Browse the repository at this point in the history
* feat: 게시글 조회 응답에 댓글 개수 추가

* refactor: 댓글 개수 가져오는 책임을 Post 객체에 위임
  • Loading branch information
Hanjaemo authored and jschoi-96 committed Mar 30, 2024
1 parent 1c2765c commit 0413d31
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/balancetalk/module/post/domain/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/balancetalk/module/post/dto/PostResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "2024/03/30 11:12:37")
private LocalDateTime createdAt;
Expand All @@ -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()))
Expand Down

0 comments on commit 0413d31

Please sign in to comment.