Skip to content

Commit

Permalink
Merge pull request #133 from Mojacknong/bug_132/루틴-스케줄러
Browse files Browse the repository at this point in the history
[fix] 루틴 스케줄러 로직 변경 -> 루틴 완료 시 주기만큼의 새로운 루틴 추가
  • Loading branch information
Ryeolee authored Sep 18, 2024
2 parents 1458bae + 4acd165 commit be6f843
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public void checkVeggieRoutine(Long routineId) {
routineRepository.updateRoutineComplete(routine.get(), routineId);
}
@Transactional
public void addRoutineOneDay(Long routineId) {
public void addRoutine(Long routineId, int day) {
Optional<Routine> routine = routineRepository.findRoutineById(routineId);
verifyRoutine(routine);
Date addedDate = DateManager.addDate(routine.get().getDate(), 1);
Date addedDate = DateManager.addDate(routine.get().getDate(), day);
addVeggieRoutine(routine.get().getMyVeggie().getId(), routine.get().getContent(), routine.get().getPeriod(), addedDate);
}
public void verifyRoutine(Optional<Routine> routine){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class RoutineScheduler {
private final RoutineRepository routineRepository;
private final MyVeggieRoutineService myVeggieRoutineService;

@Scheduled(cron = "2 0 0 * * *")
@Scheduled(cron = "2 0 0 * * *")
public void run() {
List<Routine> routineList = routineRepository.findRoutine();
addRoutine(routineList);
Expand All @@ -38,14 +38,14 @@ private void addRoutine(List<Routine> routineList){
private void complete(List<Routine> routineList){
if (routineList != null && !routineList.isEmpty()) {
routineList
.forEach(routine -> myVeggieRoutineService.checkVeggieRoutine(routine.getId()));
.forEach(routine -> myVeggieRoutineService.addRoutine(routine.getId(), routine.getPeriod()));
}
}

private void notComplete(List<Routine> routineList){
if (routineList != null && !routineList.isEmpty()) {
routineList
.forEach(routine -> myVeggieRoutineService.addRoutineOneDay(routine.getId()));
.forEach(routine -> myVeggieRoutineService.addRoutine(routine.getId(),1));
}
}
}

0 comments on commit be6f843

Please sign in to comment.