Skip to content

Commit 0ceda57

Browse files
authored
Merge pull request #404 from Clokey-dev/develop
[DEPLOY] 옷 목록 조회 API에서 isTodayCoordinateCloth 필드 추가 배포
2 parents 082681f + 9095983 commit 0ceda57

3 files changed

Lines changed: 54 additions & 4 deletions

File tree

clokey-api/src/main/java/org/clokey/domain/cloth/dto/response/ClothListResponse.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,22 @@ public record ClothListResponse(
88
@Schema(description = "옷 브랜드 이름", example = "나이키") String brand,
99
@Schema(description = "옷 이름", example = "파란색 후드") String name,
1010
@Schema(description = "상위 카테고리 이름", example = "상의") String parentCategory,
11-
@Schema(description = "하위 카테고리 이름", example = "후드티") String category) {}
11+
@Schema(description = "하위 카테고리 이름", example = "후드티") String category,
12+
@Schema(description = "오늘의 코디에 포함된 옷인지 여부", example = "true")
13+
boolean isTodayCoordinateCloth) {
14+
15+
public ClothListResponse(
16+
Long clothId,
17+
String ImageUrl,
18+
String brand,
19+
String name,
20+
String parentCategory,
21+
String category) {
22+
this(clothId, ImageUrl, brand, name, parentCategory, category, false);
23+
}
24+
25+
public ClothListResponse withTodayCoordinateCloth(boolean isTodayCoordinateCloth) {
26+
return new ClothListResponse(
27+
clothId, ImageUrl, brand, name, parentCategory, category, isTodayCoordinateCloth);
28+
}
29+
}

clokey-api/src/main/java/org/clokey/domain/cloth/service/ClothServiceImpl.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.clokey.domain.cloth.service;
22

3+
import java.time.LocalDate;
4+
import java.time.ZoneId;
35
import java.util.List;
46
import java.util.Map;
57
import java.util.Set;
@@ -17,6 +19,7 @@
1719
import org.clokey.domain.cloth.exception.ClothErrorCode;
1820
import org.clokey.domain.cloth.repository.ClothRepository;
1921
import org.clokey.domain.coordinate.repository.CoordinateClothRepository;
22+
import org.clokey.domain.coordinate.repository.CoordinateRepository;
2023
import org.clokey.domain.history.repository.HistoryClothTagRepository;
2124
import org.clokey.domain.image.event.ImageDeleteEvent;
2225
import org.clokey.domain.search.event.ClothDeleteEvent;
@@ -28,19 +31,24 @@
2831
import org.clokey.response.SliceResponse;
2932
import org.clokey.util.S3Util;
3033
import org.springframework.context.ApplicationEventPublisher;
34+
import org.springframework.data.domain.PageRequest;
3135
import org.springframework.data.domain.Slice;
36+
import org.springframework.data.domain.SliceImpl;
3237
import org.springframework.stereotype.Service;
3338
import org.springframework.transaction.annotation.Transactional;
3439

3540
@Service
3641
@RequiredArgsConstructor
3742
public class ClothServiceImpl implements ClothService {
3843

44+
private static final ZoneId KST = ZoneId.of("Asia/Seoul");
45+
3946
private final MemberUtil memberUtil;
4047

4148
private final ClothRepository clothRepository;
4249
private final CategoryRepository categoryRepository;
4350
private final HistoryClothTagRepository historyClothTagRepository;
51+
private final CoordinateRepository coordinateRepository;
4452

4553
private final ApplicationEventPublisher eventPublisher;
4654
private final CoordinateClothRepository coordinateClothRepository;
@@ -115,7 +123,27 @@ public SliceResponse<ClothListResponse> getClothes(
115123
clothRepository.findAllMemberClothesByCategoriesAndSeasons(
116124
lastClothId, size, direction, categoryIds, currentMember.getId(), seasons);
117125

118-
return SliceResponse.from(result);
126+
Set<Long> todayCoordinateClothIds =
127+
coordinateRepository
128+
.findDailyCoordinateByDateAndMemberId(
129+
LocalDate.now(KST), currentMember.getId())
130+
.map(
131+
coordinate ->
132+
coordinate.getCoordinateClothes().stream()
133+
.map(cc -> cc.getCloth().getId())
134+
.collect(Collectors.toSet()))
135+
.orElse(Set.of());
136+
137+
List<ClothListResponse> content =
138+
result.getContent().stream()
139+
.map(
140+
cloth ->
141+
cloth.withTodayCoordinateCloth(
142+
todayCoordinateClothIds.contains(cloth.clothId())))
143+
.toList();
144+
145+
return SliceResponse.from(
146+
new SliceImpl<>(content, PageRequest.of(0, size), result.hasNext()));
119147
}
120148

121149
@Override

clokey-api/src/test/java/org/clokey/domain/cloth/controller/ClothControllerTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,16 @@ class 옷_목록_조회_요청_시 {
376376
"testBrand1",
377377
"testName1",
378378
"testParentCategory1",
379-
"testCategory1"),
379+
"testCategory1",
380+
true),
380381
new ClothListResponse(
381382
2L,
382383
"testImageUrl2",
383384
"testBrand2",
384385
"testName2",
385386
"testParentCategory2",
386-
"testCategory2"));
387+
"testCategory2",
388+
false));
387389

388390
given(clothService.getClothes(null, 2, SortDirection.ASC, 1L, List.of(Season.SPRING)))
389391
.willReturn(new SliceResponse<>(clothListResponses, true));
@@ -401,7 +403,9 @@ class 옷_목록_조회_요청_시 {
401403
.andExpect(jsonPath("$.isSuccess").value(true))
402404
.andExpect(jsonPath("$.code").value("COMMON200"))
403405
.andExpect(jsonPath("$.result.content[0].clothId").value(1))
406+
.andExpect(jsonPath("$.result.content[0].isTodayCoordinateCloth").value(true))
404407
.andExpect(jsonPath("$.result.content[1].clothId").value(2))
408+
.andExpect(jsonPath("$.result.content[1].isTodayCoordinateCloth").value(false))
405409
.andExpect(jsonPath("$.result.isLast").value(true));
406410
}
407411

0 commit comments

Comments
 (0)