diff --git a/src/main/java/com/efub/dhs/domain/program/repository/ProgramRepository.java b/src/main/java/com/efub/dhs/domain/program/repository/ProgramRepository.java index 637d236..df4a764 100644 --- a/src/main/java/com/efub/dhs/domain/program/repository/ProgramRepository.java +++ b/src/main/java/com/efub/dhs/domain/program/repository/ProgramRepository.java @@ -22,5 +22,5 @@ List findTop3ByCategoryAndIsOpenAndDeadlineAfterAndProgramIdNotOrderByD @Query(value = "select p from Program p join fetch Heart h on h.program=p where h.member=?1") Page findAllProgramLiked(Member member, Pageable pageable); - List findAllByIsOpenOrderByLikeNumberDesc(Boolean isOpen); + List findTop5ByIsOpenAndDeadlineAfterOrderByLikeNumberDesc(Boolean isOpen, LocalDateTime deadline); } diff --git a/src/main/java/com/efub/dhs/domain/program/service/ProgramService.java b/src/main/java/com/efub/dhs/domain/program/service/ProgramService.java index b71be94..f5942f3 100644 --- a/src/main/java/com/efub/dhs/domain/program/service/ProgramService.java +++ b/src/main/java/com/efub/dhs/domain/program/service/ProgramService.java @@ -2,7 +2,6 @@ import java.time.LocalDateTime; import java.time.Period; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -192,25 +191,9 @@ public ProgramListResponseDto findProgramList(int page, ProgramListRequestDto re } public List findProgramPopular() { - List popularProgramList = programRepository.findAllByIsOpenOrderByLikeNumberDesc(true); - List filteredPopularProgramList = getProgramByRemainingDays(popularProgramList, 5); - return convertToProgramOutlineResponseDtoList(filteredPopularProgramList, null); - } - - public List getProgramByRemainingDays(List programList, int size) { - List filteredList = new ArrayList<>(); - - programList.forEach(program -> { - if (filteredList.size() == size) { - return; - } - Integer remainingDays = calculateRemainingDays(program.getDeadline()); - if (remainingDays >= 0) { - filteredList.add(program); - } - }); - - return filteredList; + List popularProgramList = + programRepository.findTop5ByIsOpenAndDeadlineAfterOrderByLikeNumberDesc(true, LocalDateTime.now()); + return convertToProgramOutlineResponseDtoList(popularProgramList, null); } public Member isLoggedIn(String username) {