Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#60 [feat] Scheduling 추천 글감 #63

Merged
merged 5 commits into from
Jan 11, 2024
Merged

#60 [feat] Scheduling 추천 글감 #63

merged 5 commits into from
Jan 11, 2024

Conversation

sohyundoh
Copy link
Member

✒️ 관련 이슈번호

Key Changes 🔑

  1. Recommend 클래스를 추가하여 추천 글감 엔티티를 만들어주었습니다!
  2. Scheduled 어노테이션을 활용하여 자정에 ID + 1이 되어 다른 글감을 조회하도록하였습니다. 기존 ID는 static 변수로 선언하여 전역에서 관리할 수 있게 했습니다.
  3. 만일 findById에서 결과가 나오지 않을 경우 다시 id를 reset하여 51 -> 1으로 바꿔주고, 리턴하는 방식으로 구현했습니다!
    @Scheduled(cron = "0 0 0 * * *")
    private String getRandomContentDaily() {
        return recommendRepository.findById(GROUND_ID + INDEX).orElseGet(() -> {
            resetGroundId();
            return recommendRepository.findById(GROUND_ID + INDEX).orElseThrow(
                    () -> new NotFoundException(ErrorMessage.RECCOMEND_NOT_FOUND)
            );
        }).getContent();
    }

To Reviewers 📢

  • 수정사항있으면 알려주세요!

@sohyundoh sohyundoh self-assigned this Jan 11, 2024
Copy link
Contributor

@parkheeddong parkheeddong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스케줄링 해낸 당신은 천재만재 ✨ 고생하셨어요!

@@ -22,6 +22,7 @@ public enum ErrorMessage {
COMMENT_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 댓글이 존재하지 않습니다."),
CURIOUS_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 궁금해요는 존재하지 않습니다."),
TOPIC_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 주제가 존재하지 않습니다."),
RECCOMEND_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "추천 글감을 받아오는데 실패했습니다."),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 요기 스펠링 오타가 있는 것 같아요!

public RecommendResponse getRandomRecommendation() {
return RecommendResponse.of(getRandomContentDaily());
}
@Scheduled(cron = "0 0 0 * * *")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0시 0분 0초마다 메소드가 실행되는 cron 표현식이군요..! 배워갑니닷

() -> new NotFoundException(ErrorMessage.RECCOMEND_NOT_FOUND)
);
}).getContent();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아예 랜덤한 추천을 찾는 게 아니라 매일 GROUND-ID + INDEX에 해당하는 추천을 가져오는군요! orElseGet으로 resetGroundId를 호출하는 게 좋은 아이디어 같아요!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그런데 INDEX 필드가 매일 1씩 증가해야 하지 않나요!?

@sohyundoh sohyundoh merged commit ae672c9 into develop Jan 11, 2024
1 check passed
@sohyundoh sohyundoh deleted the feat/#60 branch January 11, 2024 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat] GET - 메인뷰 글감 추천
2 participants