Skip to content

Commit

Permalink
fix: 댓글 삭제 시 개수가 줄어들지 않는 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jjuny0310 committed Oct 29, 2023
1 parent 117178d commit 68e1675
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ssafy.ssafsound.domain.post.dto;

import com.ssafy.ssafsound.domain.board.domain.Board;
import com.ssafy.ssafsound.domain.comment.domain.Comment;
import com.ssafy.ssafsound.domain.post.domain.Post;
import com.ssafy.ssafsound.domain.post.domain.PostImage;
import lombok.AllArgsConstructor;
Expand All @@ -10,6 +11,7 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@Builder
Expand Down Expand Up @@ -38,13 +40,20 @@ public GetPostElement(Post post) {
this.title = post.getTitle();
this.content = post.getContent();
this.likeCount = post.getLikes().size();
this.commentCount = post.getComments().size();
this.commentCount = getCommentSize(post);
this.createdAt = post.getCreatedAt();
this.nickname = anonymity ? "익명" : post.getMember().getNickname();
this.anonymity = anonymity;
this.thumbnail = findThumbnailUrl(post);
}

private int getCommentSize(Post post) {
List<Comment> comments = post.getComments();

return (int) comments.stream()
.filter(comment -> !comment.getDeletedComment()).count();
}

private String findThumbnailUrl(Post post) {
List<PostImage> images = post.getImages();
if (images.size() >= 1)
Expand Down

0 comments on commit 68e1675

Please sign in to comment.