From e0ce2868bf440fa63eda47d05899f11b8ed67017 Mon Sep 17 00:00:00 2001 From: SeokGeunHo Date: Thu, 2 Oct 2025 23:06:01 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=20=EC=82=AD=EC=A0=9C=EB=90=9C=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20=ED=95=84=ED=84=B0=EB=A7=81,=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=EC=88=98=20=EC=A6=9D=EA=B0=80=20=EB=A1=9C=EC=A7=81=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/comment/repository/CommentRepository.java | 10 ++++++---- .../domain/post/comment/service/CommentService.java | 4 ++-- .../com/back/domain/post/post/service/PostService.java | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) 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 97fa3c8..f141c1e 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,15 +1,17 @@ package com.back.domain.post.comment.repository; import com.back.domain.post.comment.entity.Comment; +import com.back.domain.post.comment.enums.CommentStatus; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import java.util.List; - @Repository public interface CommentRepository extends JpaRepository { - List findTop10ByPostIdOrderByIdDesc(Long postId); + // 첫 페이지 (lastId == null) + List findTop10ByPostIdAndStatusNotOrderByIdDesc(Long postId, CommentStatus status); - List findTop10ByPostIdAndIdLessThanOrderByIdDesc(Long postId, Long lastId); + // 무한스크롤 (lastId != null) + List findTop10ByPostIdAndIdLessThanAndStatusNotOrderByIdDesc(Long postId, Long id, CommentStatus status); } 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 dff2468..1d0aaca 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,12 +68,12 @@ public CommentResponseDto createComment(Long postId, CommentCreateRequestDto req @Transactional(readOnly = true) public List getComments(Long postId, Long lastId) { if (lastId == null) { - return commentRepository.findTop10ByPostIdOrderByIdDesc(postId) + return commentRepository.findTop10ByPostIdAndStatusNotOrderByIdDesc(postId, CommentStatus.DELETED) .stream() .map(CommentResponseDto::new) .toList(); } else { - return commentRepository.findTop10ByPostIdAndIdLessThanOrderByIdDesc(postId, lastId) + return commentRepository.findTop10ByPostIdAndIdLessThanAndStatusNotOrderByIdDesc(postId, lastId, CommentStatus.DELETED) .stream() .map(CommentResponseDto::new) .toList(); diff --git a/src/main/java/com/back/domain/post/post/service/PostService.java b/src/main/java/com/back/domain/post/post/service/PostService.java index 5dbbe26..b5a2161 100644 --- a/src/main/java/com/back/domain/post/post/service/PostService.java +++ b/src/main/java/com/back/domain/post/post/service/PostService.java @@ -116,7 +116,7 @@ public List getPosts(PostSortScrollRequestDto reqBody) { } // 게시글 단건 조회 로직 - @Transactional(readOnly = true) + @Transactional public PostResponseDto getPost(Long postId) { Post post = postRepository.findById(postId) .orElseThrow(() -> new NoSuchElementException("해당 게시글을 찾을 수 없습니다. ID: " + postId));