diff --git a/module-api/src/main/java/com/mile/ApiApplication.java b/module-api/src/main/java/com/mile/ApiApplication.java index a0d50f17..abb1571d 100644 --- a/module-api/src/main/java/com/mile/ApiApplication.java +++ b/module-api/src/main/java/com/mile/ApiApplication.java @@ -6,9 +6,11 @@ import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.FeignAutoConfiguration; import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.scheduling.annotation.EnableScheduling; @EnableAspectJAutoProxy +@EnableScheduling @EnableFeignClients @SpringBootApplication @ImportAutoConfiguration(FeignAutoConfiguration.class) diff --git a/module-common/src/main/java/com/mile/exception/message/ErrorMessage.java b/module-common/src/main/java/com/mile/exception/message/ErrorMessage.java index 93fdf1cd..4c0279d3 100644 --- a/module-common/src/main/java/com/mile/exception/message/ErrorMessage.java +++ b/module-common/src/main/java/com/mile/exception/message/ErrorMessage.java @@ -25,7 +25,7 @@ public enum ErrorMessage { KEYWORD_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 글모임의 글감 키워드가 존재하지 않습니다."), WRITERS_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 모임의 작가가 요청한 개수 이상 존재하지 않습니다"), WRITER_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 작가는 존재하지 않습니다."), - RECCOMEND_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "추천 글감을 받아오는데 실패했습니다."), + RECOMMEND_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "추천 글감을 받아오는데 실패했습니다."), MOIM_TOPIC_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 모임의 글감이 존재하지 않습니다."), TOPIC_POST_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 글감의 글이 존재하지 않습니다."), MOIM_POST_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 모임의 글이 존재하지 않습니다."), diff --git a/module-domain/src/main/java/com/mile/recommend/service/RecommendService.java b/module-domain/src/main/java/com/mile/recommend/service/RecommendService.java index fc9485cf..fb6dddcb 100644 --- a/module-domain/src/main/java/com/mile/recommend/service/RecommendService.java +++ b/module-domain/src/main/java/com/mile/recommend/service/RecommendService.java @@ -13,33 +13,25 @@ public class RecommendService { private final RecommendRepository recommendRepository; private static Long GROUND_ID = 0L; - private static final int INDEX = 1; - private static String recommendContent = "우정과 사랑"; + private static final Long INDEX = 1L; public RecommendResponse getRandomRecommendation() { - return RecommendResponse.of(getRandomContentDaily()); - } - - private String getRandomContentDaily() { - return recommendContent; + return RecommendResponse.of( + recommendRepository.findById(GROUND_ID).orElseGet(() -> { + resetGroundId(); + return recommendRepository.findById(GROUND_ID).orElseThrow( + () -> new NotFoundException(ErrorMessage.RECOMMEND_NOT_FOUND) + ); + } + ).getContent()); } @Scheduled(cron = "0 0 0 * * *") - private void setRandomContentDaily() { - recommendContent = recommendRepository.findById(increaseId()).orElseGet(() -> { - resetGroundId(); - return recommendRepository.findById(increaseId()).orElseThrow( - () -> new NotFoundException(ErrorMessage.RECCOMEND_NOT_FOUND) - ); - }).getContent(); - } - - private Long increaseId() { + private void increaseId() { GROUND_ID += INDEX; - return GROUND_ID; } private void resetGroundId() { - GROUND_ID = 0L; + GROUND_ID = 1L; } } \ No newline at end of file