Skip to content

Commit

Permalink
[Add] 마감임박과 인기 챌린지 more 추가 (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
genieu99 committed Nov 27, 2023
1 parent 41b359b commit eb1a70c
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@ public List<MainPageResponseDto> getImminentChallenge() {
return mainPageService.findImminentPost();
}

@GetMapping("/imminent/all")
public List<MainPageResponseDto> getImminentChallengeAll() {
return mainPageService.findImminentPostAll();
}

@GetMapping("/hot")
public List<MainPageResponseDto> getHotInProcessChallenge() {
return mainPageService.findHotInProcessPost();
return mainPageService.findHotBeforeStartPost();
}

@GetMapping("/hot/all")
public List<MainPageResponseDto> getHotInProcessChallengeAll() {
return mainPageService.findHotBeforeStartPostAll();
}

@GetMapping("/category")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,28 @@ public class MainPageService {

private LocalDate today = LocalDate.now();
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
private String formatedToday = today.format(formatter);
private String formattedToday = today.format(formatter);

private final ChallengeRepository challengeRepository;

public List<MainPageResponseDto> findImminentPost() {
List<Challenge> challenges = challengeRepository.findImminent(formatedToday);
return challenges.stream().limit(4)
.map(MainPageResponseDto::new)
.collect(Collectors.toList());
List<Challenge> challenges = challengeRepository.findImminent(formattedToday);
return findPosts(challenges, 4);
}

public List<MainPageResponseDto> findHotInProcessPost() {
List<Challenge> challenges = challengeRepository.findBeforeStartHot(formatedToday);
return challenges.stream().limit(8)
.map(MainPageResponseDto::new)
.collect(Collectors.toList());
public List<MainPageResponseDto> findImminentPostAll() {
List<Challenge> challenges = challengeRepository.findImminent(formattedToday);
return findPosts(challenges, Integer.MAX_VALUE);
}

public List<MainPageResponseDto> findHotBeforeStartPost() {
List<Challenge> challenges = challengeRepository.findBeforeStartHot(formattedToday);
return findPosts(challenges, 8);
}

public List<MainPageResponseDto> findHotBeforeStartPostAll() {
List<Challenge> challenges = challengeRepository.findBeforeStartHot(formattedToday);
return findPosts(challenges, Integer.MAX_VALUE);
}

public List<ChallengeListResponseDto> findByCategory(String category) {
Expand All @@ -43,4 +49,11 @@ public List<ChallengeListResponseDto> findByCategory(String category) {
.map(ChallengeListResponseDto::new)
.collect(Collectors.toList());
}

public List<MainPageResponseDto> findPosts(List<Challenge> challenges, int limit) {
return challenges.stream()
.limit(limit)
.map(MainPageResponseDto::new)
.collect(Collectors.toList());
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit eb1a70c

Please sign in to comment.