Skip to content

Commit

Permalink
#60 [feat] INDEX 증가 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
sohyundoh committed Jan 11, 2024
1 parent bded66f commit 757b549
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,22 @@ public class RecommendService {
public RecommendResponse getRandomRecommendation() {
return RecommendResponse.of(getRandomContentDaily());
}

@Scheduled(cron = "0 0 0 * * *")
private String getRandomContentDaily() {
return recommendRepository.findById(GROUND_ID + INDEX).orElseGet(() -> {
return recommendRepository.findById(increaseId()).orElseGet(() -> {
resetGroundId();
return recommendRepository.findById(GROUND_ID + INDEX).orElseThrow(
return recommendRepository.findById(increaseId()).orElseThrow(
() -> new NotFoundException(ErrorMessage.RECCOMEND_NOT_FOUND)
);
}).getContent();
}

private Long increaseId() {
GROUND_ID += INDEX;
return GROUND_ID;
}

private void resetGroundId() {
GROUND_ID = 0L;
}
Expand Down

0 comments on commit 757b549

Please sign in to comment.