Skip to content

Commit

Permalink
refactor: 비슷한 행사 리스트와 인기 행사 리스트의 공통 로직을 메서드로 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzwv committed Nov 25, 2023
1 parent 96ff321 commit 122a545
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,13 @@ public ProgramMemberDto findProgramMemberInfo(Program program, Member member) {
}

public List<ProgramOutlineResponseDto> findSimilarPrograms(Program program, Member member) {
List<Program> similarPrograms =
programRepository.findTop3ByCategory(program.getCategory());
return convertToProgramOutlineResponseDtoList(similarPrograms, member);
List<Program> similarProgramList =
programRepository.findAllByCategoryAndIsOpenOrderByDeadlineAsc(program.getCategory(), true);
similarProgramList.remove(program);

List<Program> filteredSimilarProgramList = getProgramByRemainingDays(similarProgramList, 3);

return convertToProgramOutlineResponseDtoList(filteredSimilarProgramList, member);
}

public List<ProgramOutlineResponseDto> convertToProgramOutlineResponseDtoList(
Expand Down Expand Up @@ -191,21 +195,25 @@ public ProgramListResponseDto findProgramList(int page, ProgramListRequestDto re
}

public List<ProgramOutlineResponseDto> findProgramPopular() {
List<Program> programList = programRepository.findAllByIsOpenOrderByLikeNumberDesc(true);
List<ProgramOutlineResponseDto> popularProgramList = new ArrayList<>();
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 (popularProgramList.size() == 5) {
if (filteredList.size() == size) {
return;
}
Integer remainingDays = calculateRemainingDays(program.getDeadline());
if (remainingDays >= 0) {
popularProgramList.add(new ProgramOutlineResponseDto(program, remainingDays,
findGoalByProgram(program.getTargetNumber(), program.getRegistrantNumber()),
false));
filteredList.add(program);
}
});
return popularProgramList;

return filteredList;
}

public Member isLoggedIn(String username) {
Expand Down

0 comments on commit 122a545

Please sign in to comment.