Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<Comment, Long> {

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

List<Comment> findTop10ByPostIdAndIdLessThanOrderByIdDesc(Long postId, Long lastId);
// 무한스크롤 (lastId != null)
List<Comment> findTop10ByPostIdAndIdLessThanAndStatusNotOrderByIdDesc(Long postId, Long id, CommentStatus status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public CommentResponseDto createComment(Long postId, CommentCreateRequestDto req
@Transactional(readOnly = true)
public List<CommentResponseDto> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public List<PostResponseDto> getPosts(PostSortScrollRequestDto reqBody) {
}

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