From 403718fb3b1b85006d5fc6949d9e1a5d6cd3acdd Mon Sep 17 00:00:00 2001 From: Ssamssamukja <109636635+Ssamssamukja@users.noreply.github.com> Date: Sat, 7 Mar 2026 00:14:00 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20isTodayCoordinateCloth=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cloth/dto/response/ClothListResponse.java | 20 ++++++++++++- .../cloth/service/ClothServiceImpl.java | 30 ++++++++++++++++++- .../cloth/controller/ClothControllerTest.java | 8 +++-- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/clokey-api/src/main/java/org/clokey/domain/cloth/dto/response/ClothListResponse.java b/clokey-api/src/main/java/org/clokey/domain/cloth/dto/response/ClothListResponse.java index 5e698b19..aeffc901 100644 --- a/clokey-api/src/main/java/org/clokey/domain/cloth/dto/response/ClothListResponse.java +++ b/clokey-api/src/main/java/org/clokey/domain/cloth/dto/response/ClothListResponse.java @@ -8,4 +8,22 @@ public record ClothListResponse( @Schema(description = "옷 브랜드 이름", example = "나이키") String brand, @Schema(description = "옷 이름", example = "파란색 후드") String name, @Schema(description = "상위 카테고리 이름", example = "상의") String parentCategory, - @Schema(description = "하위 카테고리 이름", example = "후드티") String category) {} + @Schema(description = "하위 카테고리 이름", example = "후드티") String category, + @Schema(description = "오늘의 코디에 포함된 옷인지 여부", example = "true") + boolean isTodayCoordinateCloth) { + + public ClothListResponse( + Long clothId, + String ImageUrl, + String brand, + String name, + String parentCategory, + String category) { + this(clothId, ImageUrl, brand, name, parentCategory, category, false); + } + + public ClothListResponse withTodayCoordinateCloth(boolean isTodayCoordinateCloth) { + return new ClothListResponse( + clothId, ImageUrl, brand, name, parentCategory, category, isTodayCoordinateCloth); + } +} diff --git a/clokey-api/src/main/java/org/clokey/domain/cloth/service/ClothServiceImpl.java b/clokey-api/src/main/java/org/clokey/domain/cloth/service/ClothServiceImpl.java index fad8c11a..7588931f 100644 --- a/clokey-api/src/main/java/org/clokey/domain/cloth/service/ClothServiceImpl.java +++ b/clokey-api/src/main/java/org/clokey/domain/cloth/service/ClothServiceImpl.java @@ -1,5 +1,7 @@ package org.clokey.domain.cloth.service; +import java.time.LocalDate; +import java.time.ZoneId; import java.util.List; import java.util.Map; import java.util.Set; @@ -17,6 +19,7 @@ import org.clokey.domain.cloth.exception.ClothErrorCode; import org.clokey.domain.cloth.repository.ClothRepository; import org.clokey.domain.coordinate.repository.CoordinateClothRepository; +import org.clokey.domain.coordinate.repository.CoordinateRepository; import org.clokey.domain.history.repository.HistoryClothTagRepository; import org.clokey.domain.image.event.ImageDeleteEvent; import org.clokey.domain.search.event.ClothDeleteEvent; @@ -28,7 +31,9 @@ import org.clokey.response.SliceResponse; import org.clokey.util.S3Util; import org.springframework.context.ApplicationEventPublisher; +import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Slice; +import org.springframework.data.domain.SliceImpl; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -36,11 +41,14 @@ @RequiredArgsConstructor public class ClothServiceImpl implements ClothService { + private static final ZoneId KST = ZoneId.of("Asia/Seoul"); + private final MemberUtil memberUtil; private final ClothRepository clothRepository; private final CategoryRepository categoryRepository; private final HistoryClothTagRepository historyClothTagRepository; + private final CoordinateRepository coordinateRepository; private final ApplicationEventPublisher eventPublisher; private final CoordinateClothRepository coordinateClothRepository; @@ -115,7 +123,27 @@ public SliceResponse getClothes( clothRepository.findAllMemberClothesByCategoriesAndSeasons( lastClothId, size, direction, categoryIds, currentMember.getId(), seasons); - return SliceResponse.from(result); + Set todayCoordinateClothIds = + coordinateRepository + .findDailyCoordinateByDateAndMemberId( + LocalDate.now(KST), currentMember.getId()) + .map( + coordinate -> + coordinate.getCoordinateClothes().stream() + .map(cc -> cc.getCloth().getId()) + .collect(Collectors.toSet())) + .orElse(Set.of()); + + List content = + result.getContent().stream() + .map( + cloth -> + cloth.withTodayCoordinateCloth( + todayCoordinateClothIds.contains(cloth.clothId()))) + .toList(); + + return SliceResponse.from( + new SliceImpl<>(content, PageRequest.of(0, size), result.hasNext())); } @Override diff --git a/clokey-api/src/test/java/org/clokey/domain/cloth/controller/ClothControllerTest.java b/clokey-api/src/test/java/org/clokey/domain/cloth/controller/ClothControllerTest.java index dc8f2eb1..f413d453 100644 --- a/clokey-api/src/test/java/org/clokey/domain/cloth/controller/ClothControllerTest.java +++ b/clokey-api/src/test/java/org/clokey/domain/cloth/controller/ClothControllerTest.java @@ -376,14 +376,16 @@ class 옷_목록_조회_요청_시 { "testBrand1", "testName1", "testParentCategory1", - "testCategory1"), + "testCategory1", + true), new ClothListResponse( 2L, "testImageUrl2", "testBrand2", "testName2", "testParentCategory2", - "testCategory2")); + "testCategory2", + false)); given(clothService.getClothes(null, 2, SortDirection.ASC, 1L, List.of(Season.SPRING))) .willReturn(new SliceResponse<>(clothListResponses, true)); @@ -401,7 +403,9 @@ class 옷_목록_조회_요청_시 { .andExpect(jsonPath("$.isSuccess").value(true)) .andExpect(jsonPath("$.code").value("COMMON200")) .andExpect(jsonPath("$.result.content[0].clothId").value(1)) + .andExpect(jsonPath("$.result.content[0].isTodayCoordinateCloth").value(true)) .andExpect(jsonPath("$.result.content[1].clothId").value(2)) + .andExpect(jsonPath("$.result.content[1].isTodayCoordinateCloth").value(false)) .andExpect(jsonPath("$.result.isLast").value(true)); }