Skip to content

Commit

Permalink
Fix: 뱃지 리스트 조회 API 응답형식 변경 (#277)
Browse files Browse the repository at this point in the history
* Fix: 뱃지 성취 날짜 응답값에 추가

- BadgeWithAchievedStatus에 LocalDateTime achievedAt 값 추가
- BadgeWithAchieveStatusAndAchievedAt의 achievedAt 타입 OffsetDateTime에서 LocalDateTime으로 변경
- BadgeWithAchieveStatusAndAchievedAt의 achievedAt 타입변경으로 서비스 단 isRecent함수 criterionDate 인자타입 LocalDateTime으로 변경

* Test: todayMidnight의 타입을 OffsetDateTime에서 LocalDateTime으로 변경
  • Loading branch information
hee9841 authored Oct 24, 2024
1 parent 6f1b69a commit 9cbac37
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,10 +42,11 @@ public AllBadgesListResponse getListOfAllBadges(long memberId) {
List<BadgeWithAchieveStatusAndAchievedAt> 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<BadgeType, List<BadgeWithAchievedStatus>> badgeMap = allBadges.stream()
.collect(Collectors.groupingBy(
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9cbac37

Please sign in to comment.