Skip to content

Commit

Permalink
Merge pull request #66 from TEAM-DHS/feat/program
Browse files Browse the repository at this point in the history
[REFACTOR] 비슷한 행사, 인기 행사 리스트 조회
  • Loading branch information
xyzwv authored Nov 26, 2023
2 parents 78a580d + 3c0676a commit f7388d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.efub.dhs.domain.program.repository;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.data.domain.Page;
Expand All @@ -13,12 +14,13 @@

public interface ProgramRepository extends JpaRepository<Program, Long>, ProgramRepositoryCustom {

List<Program> findAllByCategoryAndIsOpenOrderByDeadlineAsc(Category category, Boolean isOpen);
List<Program> findTop3ByCategoryAndIsOpenAndDeadlineAfterAndProgramIdNotOrderByDeadlineAsc(Category category,
Boolean isOpen, LocalDateTime deadline, Long programId);

Page<Program> findAllByHost(Member host, Pageable pageable);

@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 @@ -127,12 +126,9 @@ public ProgramMemberDto findProgramMemberInfo(Program program, Member member) {

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

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

return convertToProgramOutlineResponseDtoList(filteredSimilarProgramList, member);
programRepository.findTop3ByCategoryAndIsOpenAndDeadlineAfterAndProgramIdNotOrderByDeadlineAsc(
program.getCategory(), true, LocalDateTime.now(), program.getProgramId());
return convertToProgramOutlineResponseDtoList(similarProgramList, member);
}

public List<ProgramOutlineResponseDto> convertToProgramOutlineResponseDtoList(
Expand Down Expand Up @@ -197,25 +193,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 f7388d3

Please sign in to comment.