diff --git a/src/main/java/com/back/domain/post/comment/repository/CommentRepository.java b/src/main/java/com/back/domain/post/comment/repository/CommentRepository.java index d482be3..97fa3c8 100644 --- a/src/main/java/com/back/domain/post/comment/repository/CommentRepository.java +++ b/src/main/java/com/back/domain/post/comment/repository/CommentRepository.java @@ -1,7 +1,6 @@ package com.back.domain.post.comment.repository; import com.back.domain.post.comment.entity.Comment; -import com.back.domain.post.comment.enums.CommentStatus; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -13,9 +12,4 @@ public interface CommentRepository extends JpaRepository { List findTop10ByPostIdOrderByIdDesc(Long postId); List findTop10ByPostIdAndIdLessThanOrderByIdDesc(Long postId, Long lastId); - - // DELETED가 아닌 댓글만 조회하는 메서드 추가 - List findTop10ByPostIdAndStatusNotOrderByIdDesc(Long postId, CommentStatus status); - - List findTop10ByPostIdAndStatusNotAndIdLessThanOrderByIdDesc(Long postId, CommentStatus status, Long lastId); } diff --git a/src/main/java/com/back/domain/post/comment/service/CommentService.java b/src/main/java/com/back/domain/post/comment/service/CommentService.java index b2b85fa..dff2468 100644 --- a/src/main/java/com/back/domain/post/comment/service/CommentService.java +++ b/src/main/java/com/back/domain/post/comment/service/CommentService.java @@ -68,15 +68,15 @@ public CommentResponseDto createComment(Long postId, CommentCreateRequestDto req @Transactional(readOnly = true) public List getComments(Long postId, Long lastId) { if (lastId == null) { - return commentRepository.findTop10ByPostIdAndStatusNotOrderByIdDesc(postId, CommentStatus.DELETED) - .stream() - .map(CommentResponseDto::new) - .toList(); + return commentRepository.findTop10ByPostIdOrderByIdDesc(postId) + .stream() + .map(CommentResponseDto::new) + .toList(); } else { - return commentRepository.findTop10ByPostIdAndStatusNotAndIdLessThanOrderByIdDesc(postId, CommentStatus.DELETED, lastId) - .stream() - .map(CommentResponseDto::new) - .toList(); + return commentRepository.findTop10ByPostIdAndIdLessThanOrderByIdDesc(postId, lastId) + .stream() + .map(CommentResponseDto::new) + .toList(); } } @@ -85,11 +85,6 @@ public List getComments(Long postId, Long lastId) { public CommentResponseDto getComment(Long postId, Long commentId) { Comment comment = findCommentWithValidation(postId, commentId); - // 삭제된 댓글 조회 방지 - if (comment.getStatus() == CommentStatus.DELETED) { - throw new IllegalArgumentException("삭제된 댓글입니다."); - } - return new CommentResponseDto(comment); } @@ -136,17 +131,12 @@ public void deleteComment(Long postId, Long commentId) { // 댓글과 게시글의 연관관계 검증 private Comment findCommentWithValidation(Long postId, Long commentId) { Comment comment = commentRepository.findById(commentId) - .orElseThrow(() -> new IllegalArgumentException("댓글이 존재하지 않습니다. id=" + commentId)); + .orElseThrow(() -> new IllegalArgumentException("댓글이 존재하지 않습니다. id=" + commentId)); if (!comment.getPost().getId().equals(postId)) { throw new IllegalStateException("댓글이 해당 게시글에 속하지 않습니다."); } - // 삭제된 댓글 접근 방지 (수정/삭제 시) - if (comment.getStatus() == CommentStatus.DELETED) { - throw new IllegalStateException("삭제된 댓글은 수정하거나 삭제할 수 없습니다."); - } - return comment; } }