Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

게시글 조회 응답에 댓글 개수 추가 #271

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 = "2023-12-25T15:30:00")
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
Loading