Skip to content

Commit

Permalink
refactor: jpa query method로 인기 행사 리스트 조회 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzwv committed Nov 26, 2023
1 parent 0589c4f commit 3c0676a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ List<Program> findTop3ByCategoryAndIsOpenAndDeadlineAfterAndProgramIdNotOrderByD
@Query(value = "select p from Program p join fetch Heart h on h.program=p where h.member=?1")
Page<Program> findAllProgramLiked(Member member, Pageable pageable);

List<Program> findAllByIsOpenOrderByLikeNumberDesc(Boolean isOpen);
List<Program> findTop5ByIsOpenAndDeadlineAfterOrderByLikeNumberDesc(Boolean isOpen, LocalDateTime deadline);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -192,25 +191,9 @@ public ProgramListResponseDto findProgramList(int page, ProgramListRequestDto re
}

public List<ProgramOutlineResponseDto> findProgramPopular() {
List<Program> popularProgramList = programRepository.findAllByIsOpenOrderByLikeNumberDesc(true);
List<Program> filteredPopularProgramList = getProgramByRemainingDays(popularProgramList, 5);
return convertToProgramOutlineResponseDtoList(filteredPopularProgramList, null);
}

public List<Program> getProgramByRemainingDays(List<Program> programList, int size) {
List<Program> 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<Program> popularProgramList =
programRepository.findTop5ByIsOpenAndDeadlineAfterOrderByLikeNumberDesc(true, LocalDateTime.now());
return convertToProgramOutlineResponseDtoList(popularProgramList, null);
}

public Member isLoggedIn(String username) {
Expand Down

0 comments on commit 3c0676a

Please sign in to comment.