@@ -68,15 +68,15 @@ public CommentResponseDto createComment(Long postId, CommentCreateRequestDto req
6868 @ Transactional (readOnly = true )
6969 public List <CommentResponseDto > getComments (Long postId , Long lastId ) {
7070 if (lastId == null ) {
71- return commentRepository .findTop10ByPostIdOrderByIdDesc (postId )
72- .stream ()
73- .map (CommentResponseDto ::new )
74- .toList ();
71+ return commentRepository .findTop10ByPostIdAndStatusNotOrderByIdDesc (postId , CommentStatus . DELETED )
72+ .stream ()
73+ .map (CommentResponseDto ::new )
74+ .toList ();
7575 } else {
76- return commentRepository .findTop10ByPostIdAndIdLessThanOrderByIdDesc (postId , lastId )
77- .stream ()
78- .map (CommentResponseDto ::new )
79- .toList ();
76+ return commentRepository .findTop10ByPostIdAndStatusNotAndIdLessThanOrderByIdDesc (postId , CommentStatus . DELETED , lastId )
77+ .stream ()
78+ .map (CommentResponseDto ::new )
79+ .toList ();
8080 }
8181 }
8282
@@ -85,6 +85,11 @@ public List<CommentResponseDto> getComments(Long postId, Long lastId) {
8585 public CommentResponseDto getComment (Long postId , Long commentId ) {
8686 Comment comment = findCommentWithValidation (postId , commentId );
8787
88+ // 삭제된 댓글 조회 방지
89+ if (comment .getStatus () == CommentStatus .DELETED ) {
90+ throw new IllegalArgumentException ("삭제된 댓글입니다." );
91+ }
92+
8893 return new CommentResponseDto (comment );
8994 }
9095
@@ -131,12 +136,17 @@ public void deleteComment(Long postId, Long commentId) {
131136 // 댓글과 게시글의 연관관계 검증
132137 private Comment findCommentWithValidation (Long postId , Long commentId ) {
133138 Comment comment = commentRepository .findById (commentId )
134- .orElseThrow (() -> new IllegalArgumentException ("댓글이 존재하지 않습니다. id=" + commentId ));
139+ .orElseThrow (() -> new IllegalArgumentException ("댓글이 존재하지 않습니다. id=" + commentId ));
135140
136141 if (!comment .getPost ().getId ().equals (postId )) {
137142 throw new IllegalStateException ("댓글이 해당 게시글에 속하지 않습니다." );
138143 }
139144
145+ // 삭제된 댓글 접근 방지 (수정/삭제 시)
146+ if (comment .getStatus () == CommentStatus .DELETED ) {
147+ throw new IllegalStateException ("삭제된 댓글은 수정하거나 삭제할 수 없습니다." );
148+ }
149+
140150 return comment ;
141151 }
142152}
0 commit comments