Skip to content

Commit

Permalink
Merge pull request #49 from lsn5963/feat/quest
Browse files Browse the repository at this point in the history
[REFACTOR] 오늘 만든 퀘스트들의 경험치 넘겨주기 로직 추가
  • Loading branch information
EunbeenDev authored Aug 18, 2024
2 parents 6ecf78c + 357066d commit 61022eb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,15 +81,33 @@ 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<Quest> 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()
.level(level)
.acquireExp(acquireExp)
.needExp(level*10)
.todayExp(character.getTodayExp())
.totQuestExp(totQuestExp)
.build();

return createApiResponse(retrieveLevelAndTodayExpRes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Quest,Long> {
List<Quest> findByCharacterIdAndCreatedTimeBetween(Long id, LocalDateTime startOfDay, LocalDateTime endOfDay);
}

0 comments on commit 61022eb

Please sign in to comment.