diff --git a/src/main/java/stackpot/stackpot/pot/repository/PotRepository.java b/src/main/java/stackpot/stackpot/pot/repository/PotRepository.java index 89eb4d5..01e6ea0 100644 --- a/src/main/java/stackpot/stackpot/pot/repository/PotRepository.java +++ b/src/main/java/stackpot/stackpot/pot/repository/PotRepository.java @@ -15,21 +15,20 @@ import java.util.Optional; public interface PotRepository extends JpaRepository { - Page findByRecruitmentDetails_RecruitmentRole(Role recruitmentRole, Pageable pageable); - Optional findPotWithRecruitmentDetailsByPotId(Long potId); List findByPotApplication_User_Id(Long userId); - List findByUserId(Long userId); - Page findAll(Pageable pageable); List findByPotMembers_UserIdAndPotStatusOrderByCreatedAtDesc(Long userId, String status); List findByUserIdAndPotStatus(Long userId, String status); - Page findByUserIdAndPotStatus(Long userId, String potStatus, Pageable pageable); + @Query("SELECT p FROM Pot p WHERE p.user.id = :userId AND p.potStatus = :potStatus ORDER BY p.createdAt DESC") + Page findByUserIdAndPotStatusOrderByCreatedAtDesc(@Param("userId") Long userId, + @Param("potStatus") String potStatus, + Pageable pageable); @Query("SELECT p FROM Pot p " + "WHERE LOWER(p.potName) LIKE LOWER(CONCAT('%', :keyword, '%')) " + @@ -49,33 +48,26 @@ public interface PotRepository extends JpaRepository { "SELECT pm FROM PotMember pm WHERE pm.pot = p AND pm.user.id = :userId)") List findCompletedPotsByUserId(@Param("userId") Long userId); - List findByPotMembers_User_Id(Long potMembersUserId); - @Query("SELECT p FROM Pot p WHERE p.user.id = :userId AND p.potStatus = 'COMPLETED' AND (:cursor IS NULL OR p.potId < :cursor) ORDER BY p.potId DESC") List findCompletedPotsCreatedByUser(@Param("userId") Long userId, @Param("cursor") Long cursor); - @Modifying - @Query("DELETE FROM Pot f WHERE f.user.id = :userId") - void deleteByUserId(@Param("userId") Long userId); -// @Modifying -// @Query("DELETE FROM Pot p WHERE p.user.id = :userId AND p.potId IN :potIds AND p.potStatus = 'RECRUITING'") -// void deleteByUserIdAndPotIds(@Param("userId") Long userId, @Param("potIds") List potIds); boolean existsByUserId(Long userId); // 지원자 수 기준으로 모든 Pot 정렬 @Query("SELECT p FROM Pot p LEFT JOIN PotApplication pa ON p = pa.pot " + + "WHERE p.potStatus = :potStatus " + "GROUP BY p " + - "ORDER BY COUNT(pa.applicationId) DESC, p.createdAt DESC") - Page findAllOrderByApplicantsCountDesc(Pageable pageable); + "ORDER BY p.createdAt DESC, COUNT(pa.applicationId) DESC ") + Page findAllOrderByApplicantsCountDesc(@Param("potStatus") String potStatus, Pageable pageable); /// 여러 Role을 기준으로 지원자 수 많은 순 정렬 @Query("SELECT p FROM Pot p " + "LEFT JOIN PotRecruitmentDetails prd ON p = prd.pot " + "LEFT JOIN PotApplication pa ON p = pa.pot " + - "WHERE prd.recruitmentRole IN :roles " + + "WHERE prd.recruitmentRole IN :roles AND p.potStatus = :potStatus " + "GROUP BY p " + - "ORDER BY COUNT(pa.applicationId) DESC, p.createdAt DESC") - Page findByRecruitmentRolesInOrderByApplicantsCountDesc(@Param("roles") List roles, Pageable pageable); + "ORDER BY p.createdAt DESC, COUNT(pa.applicationId) DESC ") + Page findByRecruitmentRolesInOrderByApplicantsCountDesc(@Param("roles") List roles, @Param("potStatus") String potStatus, Pageable pageable); List findByPotMembers_UserIdOrderByCreatedAtDesc(Long userId); diff --git a/src/main/java/stackpot/stackpot/pot/service/pot/PotQueryServiceImpl.java b/src/main/java/stackpot/stackpot/pot/service/pot/PotQueryServiceImpl.java index 99e51b7..f39bca1 100644 --- a/src/main/java/stackpot/stackpot/pot/service/pot/PotQueryServiceImpl.java +++ b/src/main/java/stackpot/stackpot/pot/service/pot/PotQueryServiceImpl.java @@ -131,7 +131,7 @@ public Map getMyRecruitingPotsWithPaging(Integer page, Integer s User user = authService.getCurrentUser(); Pageable pageable = PageRequest.of(page - 1, size); - Page potPage = potRepository.findByUserIdAndPotStatus(user.getId(), "RECRUITING", pageable); + Page potPage = potRepository.findByUserIdAndPotStatusOrderByCreatedAtDesc(user.getId(), "RECRUITING", pageable); List pots = potPage.getContent(); @@ -264,12 +264,12 @@ public Map getAllPotsWithPaging(List roles, int page, int Page potPage; if (onlyMine != null && onlyMine && user != null) { - potPage = potRepository.findByUserIdAndPotStatus(user.getId(), "RECRUITING", pageable); + potPage = potRepository.findByUserIdAndPotStatusOrderByCreatedAtDesc(user.getId(), "RECRUITING", pageable); } else { if (roles == null || roles.isEmpty()) { - potPage = potRepository.findAllOrderByApplicantsCountDesc(pageable); + potPage = potRepository.findAllOrderByApplicantsCountDesc("RECRUITING", pageable); } else { - potPage = potRepository.findByRecruitmentRolesInOrderByApplicantsCountDesc(roles, pageable); + potPage = potRepository.findByRecruitmentRolesInOrderByApplicantsCountDesc(roles, "RECRUITING", pageable); } }