Skip to content

Commit a9ccd1a

Browse files
authored
[fix] 삭제된 댓글 필터링, 조회수 증가 로직 버그 수정 (#244)
1 parent 5de540a commit a9ccd1a

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package com.back.domain.post.comment.repository;
22

33
import com.back.domain.post.comment.entity.Comment;
4+
import com.back.domain.post.comment.enums.CommentStatus;
5+
import java.util.List;
46
import org.springframework.data.jpa.repository.JpaRepository;
57
import org.springframework.stereotype.Repository;
68

7-
import java.util.List;
8-
99
@Repository
1010
public interface CommentRepository extends JpaRepository<Comment, Long> {
1111

12-
List<Comment> findTop10ByPostIdOrderByIdDesc(Long postId);
12+
// 첫 페이지 (lastId == null)
13+
List<Comment> findTop10ByPostIdAndStatusNotOrderByIdDesc(Long postId, CommentStatus status);
1314

14-
List<Comment> findTop10ByPostIdAndIdLessThanOrderByIdDesc(Long postId, Long lastId);
15+
// 무한스크롤 (lastId != null)
16+
List<Comment> findTop10ByPostIdAndIdLessThanAndStatusNotOrderByIdDesc(Long postId, Long id, CommentStatus status);
1517
}

src/main/java/com/back/domain/post/comment/service/CommentService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ 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)
71+
return commentRepository.findTop10ByPostIdAndStatusNotOrderByIdDesc(postId, CommentStatus.DELETED)
7272
.stream()
7373
.map(CommentResponseDto::new)
7474
.toList();
7575
} else {
76-
return commentRepository.findTop10ByPostIdAndIdLessThanOrderByIdDesc(postId, lastId)
76+
return commentRepository.findTop10ByPostIdAndIdLessThanAndStatusNotOrderByIdDesc(postId, lastId, CommentStatus.DELETED)
7777
.stream()
7878
.map(CommentResponseDto::new)
7979
.toList();

src/main/java/com/back/domain/post/post/service/PostService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public List<PostResponseDto> getPosts(PostSortScrollRequestDto reqBody) {
116116
}
117117

118118
// 게시글 단건 조회 로직
119-
@Transactional(readOnly = true)
119+
@Transactional
120120
public PostResponseDto getPost(Long postId) {
121121
Post post = postRepository.findById(postId)
122122
.orElseThrow(() -> new NoSuchElementException("해당 게시글을 찾을 수 없습니다. ID: " + postId));

0 commit comments

Comments
 (0)