From 357066d42b1cbc79f6ab6c3e98fe8dade25d7842 Mon Sep 17 00:00:00 2001 From: lsn5963 Date: Sun, 18 Aug 2024 16:27:11 +0900 Subject: [PATCH] =?UTF-8?q?[REFACTOR]=20=EC=98=A4=EB=8A=98=20=EB=A7=8C?= =?UTF-8?q?=EB=93=A0=20=ED=80=98=EC=8A=A4=ED=8A=B8=EB=93=A4=EC=9D=98=20?= =?UTF-8?q?=EA=B2=BD=ED=97=98=EC=B9=98=20=EB=84=98=EA=B2=A8=EC=A3=BC?= =?UTF-8?q?=EA=B8=B0=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../quest/application/QuestService.java | 20 +++++++++++++++++++ .../dto/res/RetrieveLevelAndTodayExpRes.java | 2 ++ .../quest/repository/QuestRepository.java | 5 +++++ 3 files changed, 27 insertions(+) diff --git a/src/main/java/com/noplanb/domain/quest/application/QuestService.java b/src/main/java/com/noplanb/domain/quest/application/QuestService.java index 87a54b7..0ef5b3d 100644 --- a/src/main/java/com/noplanb/domain/quest/application/QuestService.java +++ b/src/main/java/com/noplanb/domain/quest/application/QuestService.java @@ -28,6 +28,8 @@ import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -79,8 +81,25 @@ public ResponseEntity retrieveQuest(LocalDate localDate, UserPrincipal userPr } public ResponseEntity retrieveLevelAndTodayExp(UserPrincipal userPrincipal) { + // 오늘의 날짜 가져오기 + LocalDate today = LocalDate.now(); + + // 오늘의 시작(LocalDateTime)과 끝(LocalDateTime) 설정 + LocalDateTime startOfDay = today.atStartOfDay(); + LocalDateTime endOfDay = today.atTime(LocalTime.MAX); + Character character = characterRepository.findByUserId(userPrincipal.getId()).orElseThrow(CharacterNotFoundException::new); + // 오늘 만든 퀘스트들 가져오기 + List todayQuests = questRepository.findByCharacterIdAndCreatedTimeBetween(character.getId(), startOfDay, endOfDay); + + Long totQuestExp = 0L; + // 오늘 만든 퀘스트들의 경험치가져오기 + for (Quest todayQuest : todayQuests) { + totQuestExp += todayQuest.getExp(); + } + // 레벨 Long level = character.getLevel(); + // 지금레벨에서 다음레벨까지 필요한 경험치 Long acquireExp = character.getTotalExp() - (((level-1)*level)/2)*10; RetrieveLevelAndTodayExpRes retrieveLevelAndTodayExpRes = RetrieveLevelAndTodayExpRes.builder() @@ -88,6 +107,7 @@ public ResponseEntity retrieveLevelAndTodayExp(UserPrincipal userPrincipal) { .acquireExp(acquireExp) .needExp(level*10) .todayExp(character.getTodayExp()) + .totQuestExp(totQuestExp) .build(); return createApiResponse(retrieveLevelAndTodayExpRes); diff --git a/src/main/java/com/noplanb/domain/quest/dto/res/RetrieveLevelAndTodayExpRes.java b/src/main/java/com/noplanb/domain/quest/dto/res/RetrieveLevelAndTodayExpRes.java index 14b2768..b5f4b2e 100644 --- a/src/main/java/com/noplanb/domain/quest/dto/res/RetrieveLevelAndTodayExpRes.java +++ b/src/main/java/com/noplanb/domain/quest/dto/res/RetrieveLevelAndTodayExpRes.java @@ -15,5 +15,7 @@ public class RetrieveLevelAndTodayExpRes { private Long needExp; @Schema(type = "Long", example = "5", description = "오늘 얻은 경험치") private Long todayExp; + @Schema(type = "Long", example = "3", description = "생성된 퀘스트들의 경험치 합") + private Long totQuestExp; } diff --git a/src/main/java/com/noplanb/domain/quest/repository/QuestRepository.java b/src/main/java/com/noplanb/domain/quest/repository/QuestRepository.java index 40cbd33..8649fa6 100644 --- a/src/main/java/com/noplanb/domain/quest/repository/QuestRepository.java +++ b/src/main/java/com/noplanb/domain/quest/repository/QuestRepository.java @@ -4,6 +4,11 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; + @Repository public interface QuestRepository extends JpaRepository { + List findByCharacterIdAndCreatedTimeBetween(Long id, LocalDateTime startOfDay, LocalDateTime endOfDay); }