Skip to content

Commit

Permalink
Merge pull request #20 from mejaiKR/hanbin
Browse files Browse the repository at this point in the history
fix: 스트릭 갱신이 제대로 되지 않는 문제
  • Loading branch information
kimchijinju authored Oct 7, 2024
2 parents de0814c + 3e7665c commit 8e73fda
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions src/main/java/mejai/mejaigg/matchstreak/service/StreakService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class StreakService {

/**
* 소환사의 게임 횟수 및 승패 조회 (단순 조회만 수행)
*
* @param request 소환사 아이디, 태그, 년도, 월
* @return 소환사의 게임 횟수 및 승패 조회 결과
*/
Expand All @@ -55,6 +56,7 @@ public List<UserStreakDto> getStreak(UserStreakRequest request) {

/**
* 소환사의 게임 횟수 및 승패 업데이트 (라이엇 API를 통해 매치 히스토리를 가져와서 업데이트)
*
* @param request 소환사 아이디, 태그, 년도, 월
* @return 소환사의 게임 횟수 및 승패 업데이트 결과
*/
Expand All @@ -64,32 +66,23 @@ public List<UserStreakDto> refreshStreak(UserStreakRequest request) {
Summoner user = userRepository.findBySummonerNameAndTagLineAllIgnoreCase(request.getId(), request.getTag())
.orElseThrow(() -> new RestApiException(SummonerErrorCode.SUMMONER_NOT_FOUND));
SearchHistory history = searchHistoryRepository.findBySummonerAndDate(user, yearMonth).orElse(null);

if (history == null) { //해당 달의 기록이 없는 경우
history = SearchHistory.builder()
.summoner(user)
.date(yearMonth)
.build();
searchHistoryRepository.save(history);
} else { //이번달 기록인데 아직 2시간이 안 지났거나
if (yearMonth.equals(YearMonth.now())
&& history.getUpdatedAt().plusHours(2).isBefore(LocalDateTime.now())) {
log.info("스트릭 업데이트를 한지 2시간 밖에 지나지 않았습니다");
} else if (history.isDone()) { //이미 검색이 끝났거나
history.setUpdatedAt(LocalDateTime.now());
} else {
if (yearMonth.equals(YearMonth.now())) {
String[] monthHistories = getMonthHistories(yearMonth, user.getPuuid(), 1,
yearMonth.lengthOfMonth());
if (monthHistories == null || monthHistories.length == 0) // 빈 히스토리인 경우
history.setDone(true);
updateStreakData(history, yearMonth, user.getPuuid());
}
}
searchHistoryRepository.save(history);
updateStreakData(history, yearMonth, user.getPuuid());
return getUserStreakDtoList(history);
}
//이번달 기록인데 아직 2시간이 안 지났거나
if (yearMonth.equals(YearMonth.now())
&& history.getUpdatedAt().plusHours(2).isBefore(LocalDateTime.now())) {
log.info("스트릭 업데이트를 한지 2시간 밖에 지나지 않았습니다");
return getUserStreakDtoList(history);
}

updateStreakData(history, yearMonth, user.getPuuid());
// //mathData 저장
return getUserStreakDtoList(history);
}

Expand All @@ -112,7 +105,6 @@ private List<UserStreakDto> getUserStreakDtoList(SearchHistory history) {

private void updateStreakData(SearchHistory history, YearMonth dateYM, String puuid) {
int startDay = history.getLastSuccessDay();
history.setUpdatedAt(LocalDateTime.now());
if (startDay >= dateYM.lengthOfMonth()) {
history.setDone(true);
searchHistoryRepository.save(history);
Expand Down

0 comments on commit 8e73fda

Please sign in to comment.