Skip to content

Commit 36e03e2

Browse files
committed
fix: 삭제된 부모 댓글의 자식 댓글이 조회되지 않던 문제 수정
- Repository 쿼리에서 isActive 조건 제거 → 삭제된 부모 댓글도 포함되도록 수정 - Service/DTO 단에서 삭제 여부를 판단하여 '삭제된 댓글입니다'로 표시 예정 - 자식 댓글이 정상적으로 조회되어 UI에 노출됨
1 parent f681063 commit 36e03e2

4 files changed

Lines changed: 6 additions & 8 deletions

File tree

src/main/java/com/project/Journey/community/comment/dto/CommunityCommentResponseDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static CommunityCommentResponseDTO of(CommunityComment c, boolean isMine,
6363
.isMine(isMine)
6464
.displayName(c.getMember().getDisplayName())
6565
.profileImage(c.getMember().getProfileImage())
66-
.content(c.getContent())
66+
.content(c.isActive() ? c.getContent() : "삭제된 댓글입니다.")
6767
.parentCommentId(c.getParentComment() != null ? c.getParentComment().getCommentId() : null)
6868
.isActive(c.isActive())
6969
.createdAt(c.getCreatedAt())

src/main/java/com/project/Journey/community/comment/entity/CommunityComment.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ public class CommunityComment {
4040
@Column(nullable = false)
4141
private boolean isActive = true;
4242

43-
@OneToMany(mappedBy = "parentComment", cascade = CascadeType.ALL)
44-
private List<CommunityComment> replies = new ArrayList<>();
45-
46-
4743
@Column(nullable = false)
4844
private int replyCount = 0;
4945

src/main/java/com/project/Journey/community/comment/repository/CommunityCommentRepository.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.util.List;
88

99
public interface CommunityCommentRepository extends JpaRepository<CommunityComment, Long> {
10-
List<CommunityComment> findByCommunityAndParentCommentIsNullAndIsActiveTrueOrderByCreatedAtAsc(Community community);
10+
List<CommunityComment> findByCommunityAndParentCommentIsNullOrderByCreatedAtAsc(Community community);
1111
List<CommunityComment> findByParentCommentAndIsActiveTrueOrderByCreatedAtAsc(CommunityComment parent);
12+
List<CommunityComment> findByParentComment_CommentIdAndIsActiveTrueOrderByCreatedAtAsc(Long parentId);
13+
1214
}

src/main/java/com/project/Journey/community/comment/service/CommunityCommentService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public List<CommunityCommentResponseDTO> getRootComments(Long communityId, Long
8585
.orElseThrow(() -> new IllegalArgumentException("커뮤니티 글이 없습니다"));
8686

8787
return commentRepo
88-
.findByCommunityAndParentCommentIsNullAndIsActiveTrueOrderByCreatedAtAsc(community)
88+
.findByCommunityAndParentCommentIsNullOrderByCreatedAtAsc(community)
8989
.stream()
9090
.map(c -> toDtoWithReplies(c, currentMemberId))
9191
.toList();
@@ -113,7 +113,7 @@ public List<CommunityCommentResponseDTO> getReplies(Long parentId, Long currentM
113113
.orElseThrow(() -> new IllegalArgumentException("댓글이 없습니다"));
114114

115115
return commentRepo
116-
.findByParentCommentAndIsActiveTrueOrderByCreatedAtAsc(parent)
116+
.findByParentComment_CommentIdAndIsActiveTrueOrderByCreatedAtAsc(parentId)
117117
.stream()
118118
.map(child -> CommunityCommentResponseDTO.of(child,
119119
child.getMember().getId().equals(currentMemberId)))

0 commit comments

Comments
 (0)