From 9cbac3712ce957ccd6e1ee9537c164062f3b0c9d Mon Sep 17 00:00:00 2001 From: sungHeeLee <70899677+hee9841@users.noreply.github.com> Date: Thu, 24 Oct 2024 20:51:36 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=EB=B1=83=EC=A7=80=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20API=20=EC=9D=91=EB=8B=B5?= =?UTF-8?q?=ED=98=95=EC=8B=9D=20=EB=B3=80=EA=B2=BD=20(#277)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: 뱃지 성취 날짜 응답값에 추가 - BadgeWithAchievedStatus에 LocalDateTime achievedAt 값 추가 - BadgeWithAchieveStatusAndAchievedAt의 achievedAt 타입 OffsetDateTime에서 LocalDateTime으로 변경 - BadgeWithAchieveStatusAndAchievedAt의 achievedAt 타입변경으로 서비스 단 isRecent함수 criterionDate 인자타입 LocalDateTime으로 변경 * Test: todayMidnight의 타입을 OffsetDateTime에서 LocalDateTime으로 변경 --- .../com/dnd/runus/application/badge/BadgeService.java | 9 +++++---- .../badge/BadgeWithAchieveStatusAndAchievedAt.java | 5 +++-- .../v1/badge/dto/response/AllBadgesListResponse.java | 9 ++++++--- .../dnd/runus/application/badge/BadgeServiceTest.java | 5 ++--- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/dnd/runus/application/badge/BadgeService.java b/src/main/java/com/dnd/runus/application/badge/BadgeService.java index 6a28a8d7..73789eff 100644 --- a/src/main/java/com/dnd/runus/application/badge/BadgeService.java +++ b/src/main/java/com/dnd/runus/application/badge/BadgeService.java @@ -12,7 +12,7 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; -import java.time.OffsetDateTime; +import java.time.LocalDateTime; import java.util.Collections; import java.util.EnumMap; import java.util.List; @@ -42,10 +42,11 @@ public AllBadgesListResponse getListOfAllBadges(long memberId) { List allBadges = badgeRepository.findAllBadgesWithAchieveStatusByMemberId(memberId); - OffsetDateTime oneWeekAgo = LocalDate.now(SERVER_TIMEZONE_ID) + LocalDateTime oneWeekAgo = LocalDate.now(SERVER_TIMEZONE_ID) .atStartOfDay(SERVER_TIMEZONE_ID) .toOffsetDateTime() - .minusDays(7); + .minusDays(7) + .toLocalDateTime(); EnumMap> badgeMap = allBadges.stream() .collect(Collectors.groupingBy( @@ -67,7 +68,7 @@ public AllBadgesListResponse getListOfAllBadges(long memberId) { badgeMap.getOrDefault(BadgeType.LEVEL, Collections.emptyList())); } - private boolean isRecent(BadgeWithAchieveStatusAndAchievedAt badge, OffsetDateTime criterionDate) { + private boolean isRecent(BadgeWithAchieveStatusAndAchievedAt badge, LocalDateTime criterionDate) { return badge.isAchieved() && criterionDate.isBefore(badge.achievedAt()); } } diff --git a/src/main/java/com/dnd/runus/domain/badge/BadgeWithAchieveStatusAndAchievedAt.java b/src/main/java/com/dnd/runus/domain/badge/BadgeWithAchieveStatusAndAchievedAt.java index c61cf9f6..78cd4d4d 100644 --- a/src/main/java/com/dnd/runus/domain/badge/BadgeWithAchieveStatusAndAchievedAt.java +++ b/src/main/java/com/dnd/runus/domain/badge/BadgeWithAchieveStatusAndAchievedAt.java @@ -2,10 +2,11 @@ import jakarta.validation.constraints.NotNull; +import java.time.LocalDateTime; import java.time.OffsetDateTime; -public record BadgeWithAchieveStatusAndAchievedAt(@NotNull Badge badge, boolean isAchieved, OffsetDateTime achievedAt) { +public record BadgeWithAchieveStatusAndAchievedAt(@NotNull Badge badge, boolean isAchieved, LocalDateTime achievedAt) { public BadgeWithAchieveStatusAndAchievedAt(Badge badge, OffsetDateTime achievedAt) { - this(badge, achievedAt != null, achievedAt); + this(badge, achievedAt != null, achievedAt != null ? achievedAt.toLocalDateTime() : null); } } diff --git a/src/main/java/com/dnd/runus/presentation/v1/badge/dto/response/AllBadgesListResponse.java b/src/main/java/com/dnd/runus/presentation/v1/badge/dto/response/AllBadgesListResponse.java index 1d201065..58c6c9a2 100644 --- a/src/main/java/com/dnd/runus/presentation/v1/badge/dto/response/AllBadgesListResponse.java +++ b/src/main/java/com/dnd/runus/presentation/v1/badge/dto/response/AllBadgesListResponse.java @@ -3,6 +3,7 @@ import com.dnd.runus.domain.badge.Badge; import com.dnd.runus.domain.badge.BadgeWithAchieveStatusAndAchievedAt; import io.swagger.v3.oas.annotations.media.Schema; +import java.time.LocalDateTime; import java.util.List; public record AllBadgesListResponse( @@ -21,18 +22,20 @@ public record AllBadgesListResponse( ) { public record BadgeWithAchievedStatus( @Schema(description = "뱃지 id") - long id, + long badgeId, @Schema(description = "뱃지 이름") String name, @Schema(description = "뱃지 이미지 url") String imageUrl, @Schema(description = "뱃지 달성 여부") - boolean isAchieved + boolean isAchieved, + @Schema(description = "배지 달성 날짜") + LocalDateTime achievedAt ) { public static BadgeWithAchievedStatus from( BadgeWithAchieveStatusAndAchievedAt badgeWithAchievedStatus) { Badge badge = badgeWithAchievedStatus.badge(); - return new BadgeWithAchievedStatus(badge.badgeId(), badge.name(), badge.imageUrl(), badgeWithAchievedStatus.isAchieved()); + return new BadgeWithAchievedStatus(badge.badgeId(), badge.name(), badge.imageUrl(), badgeWithAchievedStatus.isAchieved(), badgeWithAchievedStatus.achievedAt()); } } } diff --git a/src/test/java/com/dnd/runus/application/badge/BadgeServiceTest.java b/src/test/java/com/dnd/runus/application/badge/BadgeServiceTest.java index 21e23343..ee5632e9 100644 --- a/src/test/java/com/dnd/runus/application/badge/BadgeServiceTest.java +++ b/src/test/java/com/dnd/runus/application/badge/BadgeServiceTest.java @@ -17,6 +17,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.OffsetDateTime; import java.util.List; @@ -82,9 +83,7 @@ void getAchievedBadges_Empty() { void findAllBadges() { // given long memberId = 1L; - OffsetDateTime todayMidnight = LocalDate.now(SERVER_TIMEZONE_ID) - .atStartOfDay(SERVER_TIMEZONE_ID) - .toOffsetDateTime(); + LocalDateTime todayMidnight = LocalDate.now(SERVER_TIMEZONE_ID).atTime(0, 0, 0); given(badgeRepository.findAllBadgesWithAchieveStatusByMemberId(memberId)) .willReturn(List.of( new BadgeWithAchieveStatusAndAchievedAt(