Skip to content

Commit

Permalink
Merge pull request #59 from TEAM-DHS/feat/program
Browse files Browse the repository at this point in the history
[FIX] 비슷한 행사 리스트, 인기 행사 리스트 로직 수정
  • Loading branch information
xyzwv authored Nov 26, 2023
2 parents ccf9cd8 + 122a545 commit 399f4d3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ProgramOutlineResponseDto {
private String category;
private String thumbnailImage;
private Integer remainingDays;
private Long likeNumber;
private Boolean isOpen;
private GoalDto goal;
private String content;
Expand All @@ -27,6 +28,7 @@ public ProgramOutlineResponseDto(Program program, Integer remainingDays, GoalDto
this.category = Category.to(program.getCategory());
this.thumbnailImage = program.getImages().get(0).getUrl();
this.remainingDays = remainingDays;
this.likeNumber = program.getLikeNumber();
this.isOpen = program.getIsOpen();
this.goal = goal;
this.content = program.getContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@

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

//List<Program> findTop3ByCategoryAndScheduleMonth(Category category, Month month);
List<Program> findTop3ByCategory(Category category);
List<Program> findAllByCategoryAndIsOpenOrderByDeadlineAsc(Category category, Boolean isOpen);

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> findTop5ByOrderByLikeNumberDesc();

List<Program> findAllByIsOpenOrderByLikeNumberDesc(Boolean isOpen);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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 @@ -125,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 @@ -192,13 +197,25 @@ public ProgramListResponseDto findProgramList(int page, ProgramListRequestDto re
}

public List<ProgramOutlineResponseDto> findProgramPopular() {
List<Program> programList = programRepository.findTop5ByOrderByLikeNumberDesc();
return programList.stream().map(program ->
new ProgramOutlineResponseDto(program,
calculateRemainingDays(program.getDeadline()),
findGoalByProgram(program.getTargetNumber(), program.getRegistrantNumber()),
false)
).collect(Collectors.toList());
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;
}

public Member isLoggedIn(String username) {
Expand Down

0 comments on commit 399f4d3

Please sign in to comment.