From 436e93d9e6598eda4bb142cbb79dfeba8247a8b4 Mon Sep 17 00:00:00 2001 From: ls-rain Date: Tue, 22 Jul 2025 22:05:06 +0900 Subject: [PATCH] [refactor/#154] Refactoring Community List API --- .../example/helloworldmvc/repository/CommunityRepository.java | 2 +- .../com/example/helloworldmvc/service/CommunityServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/helloworldmvc/repository/CommunityRepository.java b/src/main/java/com/example/helloworldmvc/repository/CommunityRepository.java index 086fa6b..588314e 100644 --- a/src/main/java/com/example/helloworldmvc/repository/CommunityRepository.java +++ b/src/main/java/com/example/helloworldmvc/repository/CommunityRepository.java @@ -11,7 +11,7 @@ import org.springframework.data.jpa.repository.Query; public interface CommunityRepository extends JpaRepository { - Page findAllByCommunityCategory(CommunityCategory category, Pageable pageable); + Page findAllByCommunityCategoryOrderByCreatedAtDesc(CommunityCategory category, Pageable pageable); // Page findAllByUserId(Long userId, Pageable pageable); @EntityGraph(attributePaths = {"user"}) diff --git a/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java b/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java index 10c5906..ceb13a4 100644 --- a/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java +++ b/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java @@ -50,7 +50,7 @@ public CommunityResponseDTO.CreatedPostDTO createCommunityPost(String userId, Lo public CommunityResponseDTO.PostListDTO getCommunityList(String userId, Long categoryId, Integer page, Integer size) { User user = userRepository.findByEmail(userId).orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND)); CommunityCategory communityCategory = CommunityConverter.toCommunityCategory(categoryId); - Page communityList = communityRepository.findAllByCommunityCategory(communityCategory, PageRequest.of(page, size)); + Page communityList = communityRepository.findAllByCommunityCategoryOrderByCreatedAtDesc(communityCategory, PageRequest.of(page, size)); return CommunityConverter.toPostListDTO(communityList, categoryId); }