Skip to content

Commit

Permalink
fix: 배틀 생성만 하고 기록이 없는 경우 에러 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
seong-wooo committed Oct 16, 2023
1 parent 519c5da commit c11acb1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

public record MyPageRunningResponse(String id,
LocalDateTime startTime,
Expand All @@ -17,8 +18,17 @@ public record MyPageRunningResponse(String id,

public static MyPageRunningResponse of(Battle battle, String memberId) {
final RunnerRecord runnerRecentRecord = battle.getRunnerRecentRecord(memberId);

final LocalDateTime startTime = battle.getStartTime();

if (Objects.isNull(runnerRecentRecord)) {
return new MyPageRunningResponse(
battle.getId(),
startTime,
new RunningTimeResponse(0, 0, 0),
0
);
}

final LocalDateTime endTime = runnerRecentRecord.getTime();
final Duration duration = Duration.between(startTime, endTime);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.time.Duration;
import java.util.List;
import java.util.Objects;

public record MyPageTotalResponse(double totalDistance, double averagePace, RunningTimeResponse totalRunningTime) {

Expand All @@ -31,11 +32,11 @@ public static MyPageTotalResponse of(String memberId, List<Battle> battles, List
final long totalBattleRunningTime = battles.stream()
.mapToLong(
battle -> {
try {
return Duration.between(battle.getCreatedAt(), battle.getRunnerRecentRecord(memberId).getTime()).toSeconds();
} catch (NullPointerException exception) {
final RunnerRecord runnerRecentRecord = battle.getRunnerRecentRecord(memberId);
if (Objects.isNull(runnerRecentRecord)) {
return 0;
}
return Duration.between(battle.getCreatedAt(), runnerRecentRecord.getTime()).toSeconds();
}
)
.sum();
Expand Down

0 comments on commit c11acb1

Please sign in to comment.