Skip to content
This repository was archived by the owner on Jan 11, 2026. It is now read-only.
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
4 changes: 4 additions & 0 deletions src/main/java/com/example/spot/repository/PostRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface PostRepository extends JpaRepository<Post, Long>, PostRepositoryCustom {
// 정렬
Page<Post> findByBoardAndPostReportListIsEmptyOrderByCreatedAtDesc(Board board, Pageable pageable);
Page<Post> findByBoardAndPostReportListIsEmpty(Board board, Pageable pageable);

// 정렬 조건 필요
Page<Post> findByPostReportListIsEmptyOrderByCreatedAtDesc(Pageable pageable);
Page<Post> findByPostReportListIsEmpty(Pageable pageable); // 모든 게시글 조회

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public PostPagingResponse getPagingPosts(String type, Pageable pageable) {
Page<Post> postPage;
if (boardType == Board.ALL) {
// ALL 타입일 경우 모든 게시글 조회
postPage = postRepository.findByPostReportListIsEmpty(pageable);
postPage = postRepository.findByPostReportListIsEmptyOrderByCreatedAtDesc(pageable);
} else {
// 특정 게시판 타입의 게시글 조회
postPage = postRepository.findByBoardAndPostReportListIsEmpty(boardType, pageable);
postPage = postRepository.findByBoardAndPostReportListIsEmptyOrderByCreatedAtDesc(boardType, pageable);
}

// PostPagingDetailResponse를 묶어서 응답 리스트 생성 (좋아요 수, 좋아요여부, 스크랩 수, 스크랩여부 포함)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void getPagingPosts_All_Success() {
List<Post> posts = List.of(post1, post2);
postPage = new PageImpl<>(posts, pageable, 2);

when(postRepository.findByPostReportListIsEmpty(pageable)).thenReturn(postPage);
when(postRepository.findByPostReportListIsEmptyOrderByCreatedAtDesc(pageable)).thenReturn(postPage);

// when
PostPagingResponse result = postQueryService.getPagingPosts("ALL", pageable);
Expand All @@ -292,7 +292,7 @@ void getPagingPosts_Type_Success() {
List<Post> posts = List.of(post2);
postPage = new PageImpl<>(posts, pageable, 1);

when(postRepository.findByBoardAndPostReportListIsEmpty(Board.INFORMATION_SHARING, pageable)).thenReturn(postPage);
when(postRepository.findByBoardAndPostReportListIsEmptyOrderByCreatedAtDesc(Board.INFORMATION_SHARING, pageable)).thenReturn(postPage);

// when
PostPagingResponse result = postQueryService.getPagingPosts("INFORMATION_SHARING", pageable);
Expand Down
Loading