diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeJpaRepository.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeJpaRepository.java index 56f1ce01..fc59e683 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeJpaRepository.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeJpaRepository.java @@ -10,5 +10,5 @@ public interface DailyChallengeJpaRepository extends JpaRepository findByChallengeDateAndUserId(LocalDate challengeDate, Long userId); - List findAllByChallengeIdOrderByChallengeDate(Long challengeId); + List findAllByChallengeId(Long challengeId); } diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepository.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepository.java index 50093ab3..26d91fce 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepository.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepository.java @@ -11,7 +11,7 @@ public interface DailyChallengeRepository { Optional findByChallengeDateAndUserId(LocalDate challengeDate, Long userId); - List findAllByChallengeIdOrderByChallengeDate(Long challengeId); + List findAllByChallengeId(Long challengeId); boolean existsByUserIdAndChallengeDateIn(Long userId, List localDates); } \ No newline at end of file diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepositoryImpl.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepositoryImpl.java index 23a4c556..64b5ccd6 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepositoryImpl.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/repository/DailyChallengeRepositoryImpl.java @@ -27,8 +27,8 @@ public Optional findByChallengeDateAndUserId(LocalDate challenge } @Override - public List findAllByChallengeIdOrderByChallengeDate(Long challengeId) { - return dailyChallengeJpaRepository.findAllByChallengeIdOrderByChallengeDate(challengeId); + public List findAllByChallengeId(Long challengeId) { + return dailyChallengeJpaRepository.findAllByChallengeId(challengeId); } @Override diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java index 8c914609..ae44fee0 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeFacade.java @@ -4,7 +4,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import sopt.org.hmh.domain.app.domain.ChallengeApp; import sopt.org.hmh.domain.app.service.HistoryAppService; import sopt.org.hmh.domain.challenge.domain.Challenge; import sopt.org.hmh.domain.challenge.service.ChallengeService; @@ -28,13 +27,13 @@ public List addFinishedDailyChallengeHistory(Long userId, FinishedDailyC Challenge challenge = challengeService.findByIdOrElseThrow(userService.getCurrentChallengeIdByUserId(userId)); request.finishedDailyChallenges().forEach(challengeRequest -> { - DailyChallenge dailyChallenge = - challenge.getHistoryDailyChallenges().get(challengeRequest.challengePeriodIndex()); + DailyChallenge dailyChallenge = dailyChallengeService + .findDailyChallengeByChallengePeriodIndex(challenge, challengeRequest.challengePeriodIndex()); dailyChallengeService.changeStatusByCurrentStatus(dailyChallenge); historyAppService.addHistoryApp(challenge.getApps(), challengeRequest.apps(), dailyChallenge, os); }); - return getHistoryDailyChallengesOrderByChallengeDate(challenge); + return getHistoryDailyChallenges(challenge); } @Transactional @@ -42,8 +41,8 @@ public List changeDailyChallengeStatusByIsSuccess(Long userId, FinishedD Challenge challenge = challengeService.findByIdOrElseThrow(userService.getCurrentChallengeIdByUserId(userId)); request.finishedDailyChallenges().forEach(challengeRequest -> { - DailyChallenge dailyChallenge = - challenge.getHistoryDailyChallenges().get(challengeRequest.challengePeriodIndex()); + DailyChallenge dailyChallenge = dailyChallengeService + .findDailyChallengeByChallengePeriodIndex(challenge, challengeRequest.challengePeriodIndex()); if (challengeRequest.isSuccess()) { dailyChallengeService.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.NONE)); dailyChallenge.changeStatus(Status.UNEARNED); @@ -54,10 +53,10 @@ public List changeDailyChallengeStatusByIsSuccess(Long userId, FinishedD } }); - return getHistoryDailyChallengesOrderByChallengeDate(challenge); + return getHistoryDailyChallenges(challenge); } - private List getHistoryDailyChallengesOrderByChallengeDate(Challenge challenge) { + private List getHistoryDailyChallenges(Challenge challenge) { return challenge.getHistoryDailyChallenges() .stream() .map(DailyChallenge::getStatus) diff --git a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeService.java b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeService.java index ec3d828c..8186daae 100644 --- a/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeService.java +++ b/src/main/java/sopt/org/hmh/domain/dailychallenge/service/DailyChallengeService.java @@ -85,12 +85,12 @@ private List createDailyChallengeByChallengePeriod(Challenge cha .toList(); } - public List getDailyChallengesByChallengeIdOrderByChallengeDate(Long challengeId) { - return dailyChallengeRepository.findAllByChallengeIdOrderByChallengeDate(challengeId); + public List getDailyChallengesByChallengeId(Long challengeId) { + return dailyChallengeRepository.findAllByChallengeId(challengeId); } public void changeInfoOfDailyChallenges(Long challengeId, List statuses, LocalDate challengeDate) { - List dailyChallenges = this.getDailyChallengesByChallengeIdOrderByChallengeDate(challengeId); + List dailyChallenges = this.getDailyChallengesByChallengeId(challengeId); changeStatusOfDailyChallenges(dailyChallenges, statuses); changeChallengeDateOfDailyChallenges(dailyChallenges, challengeDate); }