From 449681228d69adef6d0367dcb9cef0fa334abbc3 Mon Sep 17 00:00:00 2001 From: sungHeeLee <70899677+hee9841@users.noreply.github.com> Date: Wed, 18 Sep 2024 09:26:29 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20=EA=B1=B0=EB=A6=AC,=20=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EA=B4=80=EB=A0=A8=20=EB=B3=80=ED=99=98=20=EA=B0=92?= =?UTF-8?q?=EC=9D=84=20constant=EA=B0=92=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20(#201)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refactor: 시간관련 변환 값 constant 값으로 변경 * Refactor: 거리 관련 변환 값 constant 값으로 변경 --- .../com/dnd/runus/application/scale/ScaleService.java | 5 ++++- .../java/com/dnd/runus/domain/challenge/Challenge.java | 7 +++++-- src/main/java/com/dnd/runus/domain/common/Pace.java | 8 +++++--- .../runus/domain/goalAchievement/GoalAchievement.java | 9 ++++++--- src/main/java/com/dnd/runus/domain/level/Level.java | 4 +++- .../runus/global/constant/MetricsConversionFactor.java | 1 - .../runus/presentation/config/ObjectMapperConfig.java | 8 +++++--- .../response/RunningRecordMonthlySummaryResponse.java | 4 +++- .../presentation/v1/scale/dto/ScaleCoursesResponse.java | 8 +++++--- 9 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/dnd/runus/application/scale/ScaleService.java b/src/main/java/com/dnd/runus/application/scale/ScaleService.java index 7dc6066a..a7502d4a 100644 --- a/src/main/java/com/dnd/runus/application/scale/ScaleService.java +++ b/src/main/java/com/dnd/runus/application/scale/ScaleService.java @@ -11,6 +11,8 @@ import java.time.OffsetDateTime; import java.util.List; +import static com.dnd.runus.global.constant.MetricsConversionFactor.METERS_IN_A_KILOMETER; + @Service @RequiredArgsConstructor public class ScaleService { @@ -70,7 +72,8 @@ private ScaleCoursesResponse.CurrentCourse calculateCurrentScaleLeftMeter( .mapToInt(log -> log.scale().sizeMeter()) .sum(); - double remainingKm = (currentScale.scale().sizeMeter() + achievedCourseMeterSum - memberRunMeterSum) / 1000.0; + double remainingKm = + (currentScale.scale().sizeMeter() + achievedCourseMeterSum - memberRunMeterSum) / METERS_IN_A_KILOMETER; String message = String.format("%s까지 %.1fkm 남았어요!", currentScale.scale().endName(), remainingKm); diff --git a/src/main/java/com/dnd/runus/domain/challenge/Challenge.java b/src/main/java/com/dnd/runus/domain/challenge/Challenge.java index 12ad2759..3b704a51 100644 --- a/src/main/java/com/dnd/runus/domain/challenge/Challenge.java +++ b/src/main/java/com/dnd/runus/domain/challenge/Challenge.java @@ -1,5 +1,8 @@ package com.dnd.runus.domain.challenge; +import static com.dnd.runus.global.constant.MetricsConversionFactor.SECONDS_PER_HOUR; +import static com.dnd.runus.global.constant.MetricsConversionFactor.SECONDS_PER_MINUTE; + public record Challenge(long challengeId, String name, int expectedTime, String imageUrl, ChallengeType challengeType) { public Challenge(long challengeId, String name, String imageUrl, ChallengeType challengeType) { @@ -11,8 +14,8 @@ public boolean isDefeatYesterdayChallenge() { } public String formatExpectedTime() { - int hour = expectedTime / 3600; - int minute = (expectedTime % 3600) / 60; + int hour = expectedTime / SECONDS_PER_HOUR; + int minute = (expectedTime % SECONDS_PER_HOUR) / SECONDS_PER_MINUTE; StringBuilder sb = new StringBuilder(); if (hour != 0) { diff --git a/src/main/java/com/dnd/runus/domain/common/Pace.java b/src/main/java/com/dnd/runus/domain/common/Pace.java index 64fda97e..c4ab28d0 100644 --- a/src/main/java/com/dnd/runus/domain/common/Pace.java +++ b/src/main/java/com/dnd/runus/domain/common/Pace.java @@ -3,6 +3,8 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; +import static com.dnd.runus.global.constant.MetricsConversionFactor.SECONDS_PER_MINUTE; + /** * 러닝 페이스를 나타내는 클래스 * @@ -11,8 +13,8 @@ */ public record Pace(int minute, int second) { public static Pace ofSeconds(int seconds) { - int minute = seconds / 60; - int second = seconds % 60; + int minute = seconds / SECONDS_PER_MINUTE; + int second = seconds % SECONDS_PER_MINUTE; return new Pace(minute, second); } @@ -29,6 +31,6 @@ public String getPace() { } public int toSeconds() { - return minute * 60 + second; + return minute * SECONDS_PER_MINUTE + second; } } diff --git a/src/main/java/com/dnd/runus/domain/goalAchievement/GoalAchievement.java b/src/main/java/com/dnd/runus/domain/goalAchievement/GoalAchievement.java index ca26cf14..ecefd422 100644 --- a/src/main/java/com/dnd/runus/domain/goalAchievement/GoalAchievement.java +++ b/src/main/java/com/dnd/runus/domain/goalAchievement/GoalAchievement.java @@ -6,6 +6,9 @@ import java.text.DecimalFormat; import static com.dnd.runus.domain.challenge.GoalMetricType.DISTANCE; +import static com.dnd.runus.global.constant.MetricsConversionFactor.METERS_IN_A_KILOMETER; +import static com.dnd.runus.global.constant.MetricsConversionFactor.SECONDS_PER_HOUR; +import static com.dnd.runus.global.constant.MetricsConversionFactor.SECONDS_PER_MINUTE; import static com.dnd.runus.global.constant.RunningResultComment.FAILURE; import static com.dnd.runus.global.constant.RunningResultComment.SUCCESS; @@ -26,7 +29,7 @@ public GoalAchievement(RunningRecord runningRecord, GoalMetricType goalMetricTyp public String getTitle() { if (goalMetricType == DISTANCE) { - return KILO_METER_FORMATTER.format(achievementValue / 1000.0) + " 달성"; + return KILO_METER_FORMATTER.format(achievementValue / METERS_IN_A_KILOMETER) + " 달성"; } return formatSecondToKoreanHHMM(achievementValue) + " 달성"; @@ -41,8 +44,8 @@ public String getIconUrl() { } private String formatSecondToKoreanHHMM(int second) { - int hour = second / 3600; - int minute = (second % 3600) / 60; + int hour = second / SECONDS_PER_HOUR; + int minute = (second % SECONDS_PER_HOUR) / SECONDS_PER_MINUTE; StringBuilder sb = new StringBuilder(); if (hour != 0) { diff --git a/src/main/java/com/dnd/runus/domain/level/Level.java b/src/main/java/com/dnd/runus/domain/level/Level.java index dc857de3..0b0b472c 100644 --- a/src/main/java/com/dnd/runus/domain/level/Level.java +++ b/src/main/java/com/dnd/runus/domain/level/Level.java @@ -2,11 +2,13 @@ import java.text.DecimalFormat; +import static com.dnd.runus.global.constant.MetricsConversionFactor.METERS_IN_A_KILOMETER; + public record Level(long levelId, int expRangeStart, int expRangeEnd, String imageUrl) { private static final DecimalFormat KILO_METER_FORMATTER = new DecimalFormat("0.##km"); public static String formatExp(int exp) { - return KILO_METER_FORMATTER.format(exp / 1000.0); + return KILO_METER_FORMATTER.format(exp / METERS_IN_A_KILOMETER); } public static String formatLevelName(long level) { diff --git a/src/main/java/com/dnd/runus/global/constant/MetricsConversionFactor.java b/src/main/java/com/dnd/runus/global/constant/MetricsConversionFactor.java index 591451a6..00aae0ba 100644 --- a/src/main/java/com/dnd/runus/global/constant/MetricsConversionFactor.java +++ b/src/main/java/com/dnd/runus/global/constant/MetricsConversionFactor.java @@ -6,7 +6,6 @@ private MetricsConversionFactor() {} public static final int SECONDS_PER_HOUR = 3600; public static final int SECONDS_PER_MINUTE = 60; - public static final int MINUTE_PER_HOUR = 60; public static final double METERS_IN_A_KILOMETER = 1000.0; } diff --git a/src/main/java/com/dnd/runus/presentation/config/ObjectMapperConfig.java b/src/main/java/com/dnd/runus/presentation/config/ObjectMapperConfig.java index b45cd8d2..acd146c5 100644 --- a/src/main/java/com/dnd/runus/presentation/config/ObjectMapperConfig.java +++ b/src/main/java/com/dnd/runus/presentation/config/ObjectMapperConfig.java @@ -15,6 +15,8 @@ import java.time.format.DateTimeFormatter; import java.time.*; +import static com.dnd.runus.global.constant.MetricsConversionFactor.SECONDS_PER_HOUR; +import static com.dnd.runus.global.constant.MetricsConversionFactor.SECONDS_PER_MINUTE; import static com.dnd.runus.global.constant.TimeConstant.*; import static java.time.format.DateTimeFormatter.ofPattern; @@ -55,9 +57,9 @@ public static class CustomDurationSerializer extends JsonSerializer { public void serialize(Duration duration, JsonGenerator generator, SerializerProvider provider) throws IOException { long totalSeconds = duration.getSeconds(); - long hours = totalSeconds / 3600; - long minutes = (totalSeconds % 3600) / 60; - long seconds = totalSeconds % 60; + long hours = totalSeconds / SECONDS_PER_HOUR; + long minutes = (totalSeconds % SECONDS_PER_HOUR) / SECONDS_PER_MINUTE; + long seconds = totalSeconds % SECONDS_PER_MINUTE; // HH:mm:ss or HHH:mm:ss String formattedDuration = String.format("%s:%02d:%02d", (hours < 10 ? "0" + hours : hours), minutes, seconds); diff --git a/src/main/java/com/dnd/runus/presentation/v1/running/dto/response/RunningRecordMonthlySummaryResponse.java b/src/main/java/com/dnd/runus/presentation/v1/running/dto/response/RunningRecordMonthlySummaryResponse.java index dee376f5..29d794e0 100644 --- a/src/main/java/com/dnd/runus/presentation/v1/running/dto/response/RunningRecordMonthlySummaryResponse.java +++ b/src/main/java/com/dnd/runus/presentation/v1/running/dto/response/RunningRecordMonthlySummaryResponse.java @@ -1,5 +1,7 @@ package com.dnd.runus.presentation.v1.running.dto.response; +import static com.dnd.runus.global.constant.MetricsConversionFactor.METERS_IN_A_KILOMETER; + import io.swagger.v3.oas.annotations.media.Schema; import java.text.DecimalFormat; @@ -17,6 +19,6 @@ public record RunningRecordMonthlySummaryResponse( private static final DecimalFormat KILO_METER_FORMATTER = new DecimalFormat("0.##km"); public RunningRecordMonthlySummaryResponse(int monthValue, int monthlyTotalMeter, String nextLevelName, String nextLevelKm) { - this(monthValue + "월", KILO_METER_FORMATTER.format(monthlyTotalMeter / 1000.0), nextLevelName, nextLevelKm); + this(monthValue + "월", KILO_METER_FORMATTER.format(monthlyTotalMeter / METERS_IN_A_KILOMETER), nextLevelName, nextLevelKm); } } diff --git a/src/main/java/com/dnd/runus/presentation/v1/scale/dto/ScaleCoursesResponse.java b/src/main/java/com/dnd/runus/presentation/v1/scale/dto/ScaleCoursesResponse.java index fcd13ce3..8c46842e 100644 --- a/src/main/java/com/dnd/runus/presentation/v1/scale/dto/ScaleCoursesResponse.java +++ b/src/main/java/com/dnd/runus/presentation/v1/scale/dto/ScaleCoursesResponse.java @@ -1,5 +1,7 @@ package com.dnd.runus.presentation.v1.scale.dto; +import static com.dnd.runus.global.constant.MetricsConversionFactor.METERS_IN_A_KILOMETER; + import io.swagger.v3.oas.annotations.media.Schema; import java.text.DecimalFormat; @@ -24,7 +26,7 @@ public Info( int totalCourses, int totalMeter ) { - this(totalCourses, KILO_METER_FORMATTER.format(totalMeter / 1000.0)); + this(totalCourses, KILO_METER_FORMATTER.format(totalMeter / METERS_IN_A_KILOMETER)); } } @@ -41,7 +43,7 @@ public AchievedCourse( int totalMeter, LocalDate achievedAt ) { - this(name, KILO_METER_FORMATTER.format(totalMeter / 1000.0), achievedAt); + this(name, KILO_METER_FORMATTER.format(totalMeter / METERS_IN_A_KILOMETER), achievedAt); } } @@ -61,7 +63,7 @@ public CurrentCourse( int achievedMeter, String message ) { - this(name, KILO_METER_FORMATTER.format(totalMeter / 1000.0), achievedMeter + "m", message); + this(name, KILO_METER_FORMATTER.format(totalMeter / METERS_IN_A_KILOMETER), achievedMeter + "m", message); } } }