From 39525095612b4fdeec9ed2f6507e962e14038e4f Mon Sep 17 00:00:00 2001 From: hee9841 Date: Thu, 19 Dec 2024 20:21:12 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Rename:=20=ED=81=B4=EB=9E=98=EC=8A=A4=20Run?= =?UTF-8?q?ningRecordAddResultResponse=20->=20RunningRecordAddResultRespon?= =?UTF-8?q?seV1=20=EC=9C=BC=EB=A1=9C,=20=ED=95=A8=EC=88=98=20addRunningRec?= =?UTF-8?q?ord=20->=20addRunningRecordV1=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/running/RunningRecordService.java | 8 ++++---- .../v1/running/RunningRecordController.java | 4 ++-- ....java => RunningRecordAddResultResponseV1.java} | 12 ++++++------ .../running/RunningRecordServiceTest.java | 14 +++++++------- 4 files changed, 19 insertions(+), 19 deletions(-) rename src/main/java/com/dnd/runus/presentation/v1/running/dto/response/{RunningRecordAddResultResponse.java => RunningRecordAddResultResponseV1.java} (83%) diff --git a/src/main/java/com/dnd/runus/application/running/RunningRecordService.java b/src/main/java/com/dnd/runus/application/running/RunningRecordService.java index b5c91268..dc67045e 100644 --- a/src/main/java/com/dnd/runus/application/running/RunningRecordService.java +++ b/src/main/java/com/dnd/runus/application/running/RunningRecordService.java @@ -168,7 +168,7 @@ public RunningRecordWeeklySummaryResponse getWeeklySummary( } @Transactional - public RunningRecordAddResultResponse addRunningRecord(long memberId, RunningRecordRequest request) { + public RunningRecordAddResultResponseV1 addRunningRecordV1(long memberId, RunningRecordRequest request) { Member member = memberRepository.findById(memberId).orElseThrow(() -> new NotFoundException(Member.class, memberId)); @@ -201,14 +201,14 @@ public RunningRecordAddResultResponse addRunningRecord(long memberId, RunningRec case CHALLENGE -> { ChallengeAchievement challengeAchievement = handleChallengeMode(request.challengeId(), memberId, record); - return RunningRecordAddResultResponse.of(record, challengeAchievement); + return RunningRecordAddResultResponseV1.of(record, challengeAchievement); } case GOAL -> { GoalAchievement goalAchievement = handleGoalMode(record, request.goalDistance(), request.goalTime()); - return RunningRecordAddResultResponse.of(record, goalAchievement); + return RunningRecordAddResultResponseV1.of(record, goalAchievement); } } - return RunningRecordAddResultResponse.from(record); + return RunningRecordAddResultResponseV1.from(record); } @Transactional(readOnly = true) diff --git a/src/main/java/com/dnd/runus/presentation/v1/running/RunningRecordController.java b/src/main/java/com/dnd/runus/presentation/v1/running/RunningRecordController.java index d1f02ffe..f244191b 100644 --- a/src/main/java/com/dnd/runus/presentation/v1/running/RunningRecordController.java +++ b/src/main/java/com/dnd/runus/presentation/v1/running/RunningRecordController.java @@ -66,9 +66,9 @@ public RunningRecordSummaryResponse getRunningRecordSummaries( }) @PostMapping @ResponseStatus(HttpStatus.OK) - public RunningRecordAddResultResponse addRunningRecord( + public RunningRecordAddResultResponseV1 addRunningRecord( @MemberId long memberId, @Valid @RequestBody RunningRecordRequest request) { - return runningRecordService.addRunningRecord(memberId, request); + return runningRecordService.addRunningRecordV1(memberId, request); } @Operation( diff --git a/src/main/java/com/dnd/runus/presentation/v1/running/dto/response/RunningRecordAddResultResponse.java b/src/main/java/com/dnd/runus/presentation/v1/running/dto/response/RunningRecordAddResultResponseV1.java similarity index 83% rename from src/main/java/com/dnd/runus/presentation/v1/running/dto/response/RunningRecordAddResultResponse.java rename to src/main/java/com/dnd/runus/presentation/v1/running/dto/response/RunningRecordAddResultResponseV1.java index 8a08aaf9..844d015e 100644 --- a/src/main/java/com/dnd/runus/presentation/v1/running/dto/response/RunningRecordAddResultResponse.java +++ b/src/main/java/com/dnd/runus/presentation/v1/running/dto/response/RunningRecordAddResultResponseV1.java @@ -13,7 +13,7 @@ import java.time.LocalDateTime; -public record RunningRecordAddResultResponse( +public record RunningRecordAddResultResponseV1( long runningRecordId, @Schema(description = "러닝 시작 시간") LocalDateTime startAt, @@ -32,11 +32,11 @@ public record RunningRecordAddResultResponse( @NotNull RunningRecordMetricsDto runningData ) { - public static RunningRecordAddResultResponse from(RunningRecord runningRecord) { + public static RunningRecordAddResultResponseV1 from(RunningRecord runningRecord) { return buildResponse(runningRecord, null, null, RunningAchievementMode.NORMAL); } - public static RunningRecordAddResultResponse of(RunningRecord runningRecord, ChallengeAchievement achievement) { + public static RunningRecordAddResultResponseV1 of(RunningRecord runningRecord, ChallengeAchievement achievement) { return buildResponse(runningRecord, new ChallengeDto( achievement.challenge().challengeId(), @@ -50,7 +50,7 @@ public static RunningRecordAddResultResponse of(RunningRecord runningRecord, Cha ); } - public static RunningRecordAddResultResponse of(RunningRecord runningRecord, GoalAchievement achievement) { + public static RunningRecordAddResultResponseV1 of(RunningRecord runningRecord, GoalAchievement achievement) { return buildResponse(runningRecord, null, new GoalResultDto( @@ -63,8 +63,8 @@ public static RunningRecordAddResultResponse of(RunningRecord runningRecord, Goa ); } - private static RunningRecordAddResultResponse buildResponse(RunningRecord runningRecord, ChallengeDto challenge, GoalResultDto goal, RunningAchievementMode achievementMode) { - return new RunningRecordAddResultResponse( + private static RunningRecordAddResultResponseV1 buildResponse(RunningRecord runningRecord, ChallengeDto challenge, GoalResultDto goal, RunningAchievementMode achievementMode) { + return new RunningRecordAddResultResponseV1( runningRecord.runningId(), runningRecord.startAt().toLocalDateTime(), runningRecord.endAt().toLocalDateTime(), diff --git a/src/test/java/com/dnd/runus/application/running/RunningRecordServiceTest.java b/src/test/java/com/dnd/runus/application/running/RunningRecordServiceTest.java index 97ddc055..5d6bd7d8 100644 --- a/src/test/java/com/dnd/runus/application/running/RunningRecordServiceTest.java +++ b/src/test/java/com/dnd/runus/application/running/RunningRecordServiceTest.java @@ -21,7 +21,7 @@ import com.dnd.runus.presentation.v1.running.dto.request.RunningAchievementMode; import com.dnd.runus.presentation.v1.running.dto.request.RunningRecordRequest; import com.dnd.runus.presentation.v1.running.dto.request.RunningRecordWeeklySummaryType; -import com.dnd.runus.presentation.v1.running.dto.response.RunningRecordAddResultResponse; +import com.dnd.runus.presentation.v1.running.dto.response.RunningRecordAddResultResponseV1; import com.dnd.runus.presentation.v1.running.dto.response.RunningRecordMonthlySummaryResponse; import com.dnd.runus.presentation.v1.running.dto.response.RunningRecordQueryResponse; import com.dnd.runus.presentation.v1.running.dto.response.RunningRecordWeeklySummaryResponse; @@ -217,7 +217,7 @@ void addRunningRecord_challenge() { given(challengeAchievementRepository.save(challengeAchievement)).willReturn(challengeAchievement); // when - RunningRecordAddResultResponse response = runningRecordService.addRunningRecord(1L, request); + RunningRecordAddResultResponseV1 response = runningRecordService.addRunningRecordV1(1L, request); // then assertEquals(request.startAt(), response.startAt()); @@ -250,7 +250,7 @@ void addRunningRecord_goal_time_success() { given(goalAchievementRepository.save(goalAchievement)).willReturn(goalAchievement); // when - RunningRecordAddResultResponse response = runningRecordService.addRunningRecord(1L, request); + RunningRecordAddResultResponseV1 response = runningRecordService.addRunningRecordV1(1L, request); // then assertEquals(request.startAt(), response.startAt()); @@ -289,7 +289,7 @@ void addRunningRecord_goal_time_fail() { given(goalAchievementRepository.save(goalAchievement)).willReturn(goalAchievement); // when - RunningRecordAddResultResponse response = runningRecordService.addRunningRecord(1L, request); + RunningRecordAddResultResponseV1 response = runningRecordService.addRunningRecordV1(1L, request); // then assertEquals(request.startAt(), response.startAt()); @@ -328,7 +328,7 @@ void addRunningRecord_goal_distance() { given(goalAchievementRepository.save(goalAchievement)).willReturn(goalAchievement); // when - RunningRecordAddResultResponse response = runningRecordService.addRunningRecord(1L, request); + RunningRecordAddResultResponseV1 response = runningRecordService.addRunningRecordV1(1L, request); // then assertEquals(request.startAt(), response.startAt()); @@ -367,7 +367,7 @@ void addRunningRecord_goal_distance_same_value() { given(goalAchievementRepository.save(goalAchievement)).willReturn(goalAchievement); // when - RunningRecordAddResultResponse response = runningRecordService.addRunningRecord(1L, request); + RunningRecordAddResultResponseV1 response = runningRecordService.addRunningRecordV1(1L, request); // then assertEquals(request.startAt(), response.startAt()); @@ -402,7 +402,7 @@ void addRunningRecord_check_cal_pace() { given(runningRecordRepository.save(expected)).willReturn(expected); // when - RunningRecordAddResultResponse response = runningRecordService.addRunningRecord(1L, request); + RunningRecordAddResultResponseV1 response = runningRecordService.addRunningRecordV1(1L, request); // then assertEquals(new Pace(8, 28), response.runningData().averagePace()); From 56a54101ebc83abeee85bb2e308ff9a318bca8f8 Mon Sep 17 00:00:00 2001 From: hee9841 Date: Thu, 19 Dec 2024 20:23:46 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Refactor:=20getMonthlyRunningSummery=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD(?= =?UTF-8?q?=EC=BB=A8=EB=B2=A4=EC=85=98=20=EA=B7=9C=EC=B9=99=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=9D=BC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../running/RunningRecordService.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/dnd/runus/application/running/RunningRecordService.java b/src/main/java/com/dnd/runus/application/running/RunningRecordService.java index dc67045e..5d5ae590 100644 --- a/src/main/java/com/dnd/runus/application/running/RunningRecordService.java +++ b/src/main/java/com/dnd/runus/application/running/RunningRecordService.java @@ -167,6 +167,19 @@ public RunningRecordWeeklySummaryResponse getWeeklySummary( avgValue / conversionFactor); } + @Transactional(readOnly = true) + public RunningRecordMonthlySummaryResponse getMonthlyRunningSummery(long memberId) { + + OffsetDateTime startDateOfMonth = + OffsetDateTime.now(ZoneId.of(SERVER_TIMEZONE)).withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS); + OffsetDateTime startDateOfNextMonth = startDateOfMonth.plusMonths(1); + return RunningRecordMonthlySummaryResponse.builder() + .month(startDateOfMonth.getMonthValue()) + .monthlyTotalMeter(runningRecordRepository.findTotalDistanceMeterByMemberIdWithRangeDate( + memberId, startDateOfMonth, startDateOfNextMonth)) + .build(); + } + @Transactional public RunningRecordAddResultResponseV1 addRunningRecordV1(long memberId, RunningRecordRequest request) { Member member = @@ -211,19 +224,6 @@ public RunningRecordAddResultResponseV1 addRunningRecordV1(long memberId, Runnin return RunningRecordAddResultResponseV1.from(record); } - @Transactional(readOnly = true) - public RunningRecordMonthlySummaryResponse getMonthlyRunningSummery(long memberId) { - - OffsetDateTime startDateOfMonth = - OffsetDateTime.now(ZoneId.of(SERVER_TIMEZONE)).withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS); - OffsetDateTime startDateOfNextMonth = startDateOfMonth.plusMonths(1); - return RunningRecordMonthlySummaryResponse.builder() - .month(startDateOfMonth.getMonthValue()) - .monthlyTotalMeter(runningRecordRepository.findTotalDistanceMeterByMemberIdWithRangeDate( - memberId, startDateOfMonth, startDateOfNextMonth)) - .build(); - } - private ChallengeAchievement handleChallengeMode(Long challengeId, long memberId, RunningRecord runningRecord) { if (challengeId == null) { throw new NotFoundException("Challenge ID is required for CHALLENGE mode"); From db65112b8e3a2c74b99157e80b79cba28d7ab119 Mon Sep 17 00:00:00 2001 From: hee9841 Date: Thu, 19 Dec 2024 20:29:51 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Rename:=20RunningRecordRequest=20->=20Runni?= =?UTF-8?q?ngRecordRequestV1=EC=9C=BC=EB=A1=9C=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../running/RunningRecordService.java | 4 ++-- .../v1/running/RunningRecordController.java | 4 ++-- ...dRequest.java => RunningRecordRequestV1.java} | 4 ++-- .../running/RunningRecordServiceTest.java | 16 ++++++++-------- 4 files changed, 14 insertions(+), 14 deletions(-) rename src/main/java/com/dnd/runus/presentation/v1/running/dto/request/{RunningRecordRequest.java => RunningRecordRequestV1.java} (97%) diff --git a/src/main/java/com/dnd/runus/application/running/RunningRecordService.java b/src/main/java/com/dnd/runus/application/running/RunningRecordService.java index 5d5ae590..d3146fad 100644 --- a/src/main/java/com/dnd/runus/application/running/RunningRecordService.java +++ b/src/main/java/com/dnd/runus/application/running/RunningRecordService.java @@ -20,7 +20,7 @@ import com.dnd.runus.domain.running.RunningRecordRepository; import com.dnd.runus.global.exception.NotFoundException; import com.dnd.runus.presentation.v1.running.dto.WeeklyRunningRatingDto; -import com.dnd.runus.presentation.v1.running.dto.request.RunningRecordRequest; +import com.dnd.runus.presentation.v1.running.dto.request.RunningRecordRequestV1; import com.dnd.runus.presentation.v1.running.dto.request.RunningRecordWeeklySummaryType; import com.dnd.runus.presentation.v1.running.dto.response.*; import org.springframework.beans.factory.annotation.Value; @@ -181,7 +181,7 @@ public RunningRecordMonthlySummaryResponse getMonthlyRunningSummery(long memberI } @Transactional - public RunningRecordAddResultResponseV1 addRunningRecordV1(long memberId, RunningRecordRequest request) { + public RunningRecordAddResultResponseV1 addRunningRecordV1(long memberId, RunningRecordRequestV1 request) { Member member = memberRepository.findById(memberId).orElseThrow(() -> new NotFoundException(Member.class, memberId)); diff --git a/src/main/java/com/dnd/runus/presentation/v1/running/RunningRecordController.java b/src/main/java/com/dnd/runus/presentation/v1/running/RunningRecordController.java index f244191b..a323050f 100644 --- a/src/main/java/com/dnd/runus/presentation/v1/running/RunningRecordController.java +++ b/src/main/java/com/dnd/runus/presentation/v1/running/RunningRecordController.java @@ -7,7 +7,7 @@ import com.dnd.runus.global.exception.type.ErrorType; import com.dnd.runus.presentation.annotation.MemberId; import com.dnd.runus.presentation.v1.member.dto.response.MyProfileResponse; -import com.dnd.runus.presentation.v1.running.dto.request.RunningRecordRequest; +import com.dnd.runus.presentation.v1.running.dto.request.RunningRecordRequestV1; import com.dnd.runus.presentation.v1.running.dto.request.RunningRecordWeeklySummaryType; import com.dnd.runus.presentation.v1.running.dto.response.*; import io.swagger.v3.oas.annotations.Operation; @@ -67,7 +67,7 @@ public RunningRecordSummaryResponse getRunningRecordSummaries( @PostMapping @ResponseStatus(HttpStatus.OK) public RunningRecordAddResultResponseV1 addRunningRecord( - @MemberId long memberId, @Valid @RequestBody RunningRecordRequest request) { + @MemberId long memberId, @Valid @RequestBody RunningRecordRequestV1 request) { return runningRecordService.addRunningRecordV1(memberId, request); } diff --git a/src/main/java/com/dnd/runus/presentation/v1/running/dto/request/RunningRecordRequest.java b/src/main/java/com/dnd/runus/presentation/v1/running/dto/request/RunningRecordRequestV1.java similarity index 97% rename from src/main/java/com/dnd/runus/presentation/v1/running/dto/request/RunningRecordRequest.java rename to src/main/java/com/dnd/runus/presentation/v1/running/dto/request/RunningRecordRequestV1.java index 5cccd691..3aff3c96 100644 --- a/src/main/java/com/dnd/runus/presentation/v1/running/dto/request/RunningRecordRequest.java +++ b/src/main/java/com/dnd/runus/presentation/v1/running/dto/request/RunningRecordRequestV1.java @@ -10,7 +10,7 @@ import java.time.LocalDateTime; -public record RunningRecordRequest( +public record RunningRecordRequestV1( @NotNull LocalDateTime startAt, @NotNull @@ -36,7 +36,7 @@ public record RunningRecordRequest( @NotNull RunningRecordMetricsForAddDto runningData ) { - public RunningRecordRequest { + public RunningRecordRequestV1 { if (startAt.isAfter(endAt)) { throw new BusinessException(ErrorType.START_AFTER_END, startAt + " ~ " + endAt); } diff --git a/src/test/java/com/dnd/runus/application/running/RunningRecordServiceTest.java b/src/test/java/com/dnd/runus/application/running/RunningRecordServiceTest.java index 5d6bd7d8..b97b1f66 100644 --- a/src/test/java/com/dnd/runus/application/running/RunningRecordServiceTest.java +++ b/src/test/java/com/dnd/runus/application/running/RunningRecordServiceTest.java @@ -19,7 +19,7 @@ import com.dnd.runus.presentation.v1.running.dto.RunningRecordMetricsForAddDto; import com.dnd.runus.presentation.v1.running.dto.WeeklyRunningRatingDto; import com.dnd.runus.presentation.v1.running.dto.request.RunningAchievementMode; -import com.dnd.runus.presentation.v1.running.dto.request.RunningRecordRequest; +import com.dnd.runus.presentation.v1.running.dto.request.RunningRecordRequestV1; import com.dnd.runus.presentation.v1.running.dto.request.RunningRecordWeeklySummaryType; import com.dnd.runus.presentation.v1.running.dto.response.RunningRecordAddResultResponseV1; import com.dnd.runus.presentation.v1.running.dto.response.RunningRecordMonthlySummaryResponse; @@ -188,7 +188,7 @@ void getRunningRecord_challenge() { @DisplayName("CHALLENGE 모드의 러닝 기록 추가 요청시, challengeId에 해당하는 챌린지가 있을 경우, 정상적으로 러닝 기록이 추가된다.") void addRunningRecord_challenge() { // given - RunningRecordRequest request = new RunningRecordRequest( + RunningRecordRequestV1 request = new RunningRecordRequestV1( LocalDateTime.of(2021, 1, 1, 12, 10, 30), LocalDateTime.of(2021, 1, 1, 13, 12, 10), "start location", @@ -228,7 +228,7 @@ void addRunningRecord_challenge() { @DisplayName("GOAL 모드의 러닝 기록 추가 시,goalTime이 null이 아니고 목표값보다 실제값이 더 크다면, 성공한 goalAchievement와 함께 정상적으로 러닝 기록이 추가된다.") void addRunningRecord_goal_time_success() { // given - RunningRecordRequest request = new RunningRecordRequest( + RunningRecordRequestV1 request = new RunningRecordRequestV1( LocalDateTime.of(2021, 1, 1, 12, 10, 30), LocalDateTime.of(2021, 1, 1, 13, 12, 10), "start location", @@ -267,7 +267,7 @@ void addRunningRecord_goal_time_success() { "GOAL 모드의 러닝 기록 추가 시, goalTime이 null이 아니고 목표값보다 실제값이 더 낮다면, 실패한 goalAchievement와 함께 정상적으로 러닝 기록이 추가된다.") void addRunningRecord_goal_time_fail() { // given - RunningRecordRequest request = new RunningRecordRequest( + RunningRecordRequestV1 request = new RunningRecordRequestV1( LocalDateTime.of(2021, 1, 1, 12, 10, 30), LocalDateTime.of(2021, 1, 1, 13, 12, 10), "start location", @@ -306,7 +306,7 @@ void addRunningRecord_goal_time_fail() { "GOAL 모드의 러닝 기록 추가 요청시, goalDistance가 null이 아니고 목표값보다 실제값이 더 높다면 성공한 goalAchievement와 함께 정상적으로 러닝 기록이 추가된다.") void addRunningRecord_goal_distance() { // given - RunningRecordRequest request = new RunningRecordRequest( + RunningRecordRequestV1 request = new RunningRecordRequestV1( LocalDateTime.of(2021, 1, 1, 12, 10, 30), LocalDateTime.of(2021, 1, 1, 13, 12, 10), "start location", @@ -345,7 +345,7 @@ void addRunningRecord_goal_distance() { "GOAL 모드의 러닝 기록 추가 요청시, goalDistance가 null이 아니고 목표값보다 실제값과 같다면 성공한 goalAchievement와 함께 정상적으로 러닝 기록이 추가된다.") void addRunningRecord_goal_distance_same_value() { // given - RunningRecordRequest request = new RunningRecordRequest( + RunningRecordRequestV1 request = new RunningRecordRequestV1( LocalDateTime.of(2021, 1, 1, 12, 10, 30), LocalDateTime.of(2021, 1, 1, 13, 12, 10), "start location", @@ -383,7 +383,7 @@ void addRunningRecord_goal_distance_same_value() { @DisplayName("러닝의 페이스가 올바르게 계산되었는지 확인한다.") void addRunningRecord_check_cal_pace() { // given - RunningRecordRequest request = new RunningRecordRequest( + RunningRecordRequestV1 request = new RunningRecordRequestV1( LocalDateTime.of(2021, 1, 1, 12, 10, 30), LocalDateTime.of(2021, 1, 1, 13, 12, 10), "start location", @@ -502,7 +502,7 @@ void getWeeklySummary_Duration() { assertThat(response.lastWeekAvgValue()).isEqualTo(expectedRunningDurationHour); } - private RunningRecord createRunningRecord(RunningRecordRequest request, Member member) { + private RunningRecord createRunningRecord(RunningRecordRequestV1 request, Member member) { return RunningRecord.builder() .member(member)