Skip to content

Commit

Permalink
Fix: 어제 기록관련 if 처리 수정, 챌린지 목표값 추가 관련해서 for문에서 스트림으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hee9841 committed Dec 11, 2024
1 parent 78f80f5 commit e8a53ac
Showing 1 changed file with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

import static com.dnd.runus.global.constant.TimeConstant.SERVER_TIMEZONE_ID;

Expand All @@ -37,31 +36,25 @@ public List<ChallengeWithCondition> getChallenges(long memberId) {
List<ChallengeWithCondition> allChallengesWithConditions =
new ArrayList<>(challengeRepository.findAllActiveChallengesWithConditions());

// 어제 기록이 없으면
// 어제 기록이 없으면 어제 기록과 관련된 챌린지 삭제
if (runningRecords.isEmpty()) {
allChallengesWithConditions = allChallengesWithConditions.stream()
allChallengesWithConditions.removeIf(
challengeWithCondition -> challengeWithCondition.challenge().isDefeatYesterdayChallenge());
} else {
// 어제의 기록과 관련된 챌린지면, 챌린지 비교할 값(성공 유무를 위한 목표 값) 재등록
allChallengesWithConditions.stream()
.filter(challengeWithCondition ->
!challengeWithCondition.challenge().isDefeatYesterdayChallenge())
.collect(Collectors.toList());
challengeWithCondition.challenge().isDefeatYesterdayChallenge())
.forEach(challengeWithCondition -> challengeWithCondition
.conditions()
.forEach(condition -> condition.registerComparisonValue(
condition.goalMetricType().getActualValue(runningRecords.getFirst()))));
}

// 랜덤으로 2개 리턴
Random randomWithSeed = new Random(todayMidnight.toEpochSecond());
Collections.shuffle(allChallengesWithConditions, randomWithSeed);
List<ChallengeWithCondition> randomChallengeWithConditions = allChallengesWithConditions.subList(0, 2);

if (!runningRecords.isEmpty()) {
for (ChallengeWithCondition challenge : randomChallengeWithConditions) {
if (challenge.challenge().isDefeatYesterdayChallenge()) {
// 어제의 기록과 관련된 챌린지면, 챌린지 비교할 값(성공 유무를 위한 목표 값) 재등록
challenge
.conditions()
.forEach(condition -> condition.registerComparisonValue(
condition.goalMetricType().getActualValue(runningRecords.getFirst())));
}
}
}

return randomChallengeWithConditions;
return allChallengesWithConditions.subList(0, 2);
}
}

0 comments on commit e8a53ac

Please sign in to comment.