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(