Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -28,19 +31,24 @@
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;

@Service
@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;
Expand Down Expand Up @@ -115,7 +123,27 @@ public SliceResponse<ClothListResponse> getClothes(
clothRepository.findAllMemberClothesByCategoriesAndSeasons(
lastClothId, size, direction, categoryIds, currentMember.getId(), seasons);

return SliceResponse.from(result);
Set<Long> 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<ClothListResponse> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,16 @@
"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));
Expand All @@ -401,7 +403,9 @@
.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));
}

Expand Down Expand Up @@ -539,7 +543,7 @@
"testBrand",
List.of(Season.SPRING),
1L);
;

Check warning on line 546 in clokey-api/src/test/java/org/clokey/domain/cloth/controller/ClothControllerTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this empty statement.

See more on https://sonarcloud.io/project/issues?id=Clokey-dev_clokey-server&issues=AZzDwIEGQsCP9UU2MXAh&open=AZzDwIEGQsCP9UU2MXAh&pullRequest=403

// when & then
ResultActions perform =
Expand Down Expand Up @@ -588,7 +592,7 @@
"testBrand",
List.of(Season.SPRING),
null);
;

Check warning on line 595 in clokey-api/src/test/java/org/clokey/domain/cloth/controller/ClothControllerTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this empty statement.

See more on https://sonarcloud.io/project/issues?id=Clokey-dev_clokey-server&issues=AZzDwIEGQsCP9UU2MXAj&open=AZzDwIEGQsCP9UU2MXAj&pullRequest=403

// when & then
ResultActions perform =
Expand Down
Loading