From c11acb18d554cdc88ace6502c73a0d00bc0cfc95 Mon Sep 17 00:00:00 2001 From: seongwoo Date: Mon, 16 Oct 2023 15:56:01 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=B0=B0=ED=8B=80=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EB=A7=8C=20=ED=95=98=EA=B3=A0=20=EA=B8=B0=EB=A1=9D=EC=9D=B4=20?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/mypage/dto/MyPageRunningResponse.java | 12 +++++++++++- .../domain/mypage/dto/MyPageTotalResponse.java | 7 ++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/online/partyrun/partyrunbattleservice/domain/mypage/dto/MyPageRunningResponse.java b/src/main/java/online/partyrun/partyrunbattleservice/domain/mypage/dto/MyPageRunningResponse.java index 741d2ab..6d0c846 100644 --- a/src/main/java/online/partyrun/partyrunbattleservice/domain/mypage/dto/MyPageRunningResponse.java +++ b/src/main/java/online/partyrun/partyrunbattleservice/domain/mypage/dto/MyPageRunningResponse.java @@ -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, @@ -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); diff --git a/src/main/java/online/partyrun/partyrunbattleservice/domain/mypage/dto/MyPageTotalResponse.java b/src/main/java/online/partyrun/partyrunbattleservice/domain/mypage/dto/MyPageTotalResponse.java index c8a9ee3..c6421e9 100644 --- a/src/main/java/online/partyrun/partyrunbattleservice/domain/mypage/dto/MyPageTotalResponse.java +++ b/src/main/java/online/partyrun/partyrunbattleservice/domain/mypage/dto/MyPageTotalResponse.java @@ -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) { @@ -31,11 +32,11 @@ public static MyPageTotalResponse of(String memberId, List 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();