Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

배틀 생성만 하고 기록이 없는 경우 에러 처리 #74

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import online.partyrun.partyrunbattleservice.domain.battle.entity.Battle;
import online.partyrun.partyrunbattleservice.domain.runner.entity.record.RunnerRecord;
import online.partyrun.partyrunbattleservice.domain.runner.exception.InvalidRecentRunnerRecordException;
import online.partyrun.partyrunbattleservice.domain.single.dto.RunningTimeResponse;
import online.partyrun.partyrunbattleservice.domain.single.entity.Single;

Expand All @@ -16,11 +17,27 @@ public static MyPageTotalResponse of(String memberId, List<Battle> battles, List
}

final double totalBattleDistance = battles.stream()
.mapToDouble(battle -> battle.getRunnerRecentDistance(memberId))
.mapToDouble(
battle -> {
try {
return battle.getRunnerRecentDistance(memberId);
} catch (InvalidRecentRunnerRecordException exception) {
return 0;
}
}
)
.sum();

final long totalBattleRunningTime = battles.stream()
.mapToLong(battle -> Duration.between(battle.getCreatedAt(), battle.getRunnerRecentRecord(memberId).getTime()).toSeconds())
.mapToLong(
battle -> {
try {
return Duration.between(battle.getCreatedAt(), battle.getRunnerRecentRecord(memberId).getTime()).toSeconds();
} catch (InvalidRecentRunnerRecordException exception) {
return 0;
}
}
)
.sum();

final double totalSingleDistance = singles.stream()
Expand All @@ -40,7 +57,7 @@ public static MyPageTotalResponse of(String memberId, List<Battle> battles, List

int totalHour = (int) totalRunningTime / 3600;
int totalMinute = (int) (totalRunningTime % 3600) / 60;
int totalSecond = (int) totalRunningTime % 60;
int totalSecond = (int) totalRunningTime % 60;

return new MyPageTotalResponse(totalDistance, totalDistance / totalRunningTime, new RunningTimeResponse(totalHour, totalMinute, totalSecond));
}
Expand Down