Skip to content

Commit 3739084

Browse files
authored
[Fix/#319] 카테고리별 계절에 맞는 옷 조회 api 수정 (#320)
* fix: 상위카테고리로 입력 변경 * update: test category 수정
1 parent a6c1722 commit 3739084

5 files changed

Lines changed: 13 additions & 8 deletions

File tree

clokey-api/src/main/java/org/clokey/domain/cloth/controller/ClothController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public BaseResponse<SliceResponse<ClothRecommendListResponse>> recommendCategory
4545
@Parameter(description = "이전 페이지의 옷ID (첫 요청 시 생략)") @RequestParam(required = false)
4646
Long lastClothId,
4747
@Parameter(description = "페이지당 조회할 옷 수") @RequestParam @PageSize Integer size,
48-
@Parameter(description = " 카테고리 ID") @RequestParam Long categoryId,
48+
@Parameter(description = "상위 카테고리 ID") @RequestParam Long categoryId,
4949
@Parameter(description = "요청 계절") @RequestParam Season season) {
5050
SliceResponse<ClothRecommendListResponse> response =
5151
clothService.recommendCategoryClothes(lastClothId, size, categoryId, season);

clokey-api/src/main/java/org/clokey/domain/cloth/repository/ClothRepositoryCustom.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public interface ClothRepositoryCustom {
1111

1212
Slice<ClothRecommendListResponse> findAllMemberRecommendClothesByCategoryAndSeason(
13-
Long lastClothId, int size, Long categoryId, Long memberId, Season season);
13+
Long lastClothId, int size, List<Long> categoryIds, Long memberId, Season season);
1414

1515
Slice<ClothListResponse> findAllMemberClothesByCategoriesAndSeasons(
1616
Long lastClothId,

clokey-api/src/main/java/org/clokey/domain/cloth/repository/ClothRepositoryImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ public class ClothRepositoryImpl implements ClothRepositoryCustom {
3030

3131
@Override
3232
public Slice<ClothRecommendListResponse> findAllMemberRecommendClothesByCategoryAndSeason(
33-
Long lastClothId, int size, Long categoryId, Long memberId, Season season) {
33+
Long lastClothId, int size, List<Long> categoryIds, Long memberId, Season season) {
34+
if (categoryIds == null || categoryIds.isEmpty()) {
35+
return new SliceImpl<>(List.of(), PageRequest.of(0, size), false);
36+
}
3437

3538
Season nextSeason = season.next();
3639
Season previousSeason = season.previous();
@@ -65,7 +68,7 @@ public Slice<ClothRecommendListResponse> findAllMemberRecommendClothesByCategory
6568
queryFactory
6669
.selectFrom(cloth)
6770
.where(
68-
cloth.category.id.eq(categoryId),
71+
cloth.category.id.in(categoryIds),
6972
cloth.member.id.eq(memberId),
7073
seasonCondition)
7174
.orderBy(seasonPriority.asc(), cloth.id.asc())

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ public ClothCreateResponse createClothes(ClothCreateRequests request) {
9090
public SliceResponse<ClothRecommendListResponse> recommendCategoryClothes(
9191
Long lastClothId, int size, Long categoryId, Season season) {
9292
final Member currentMember = memberUtil.getCurrentMember();
93+
List<Long> categoryIds = resolveCategoryIds(categoryId);
9394

9495
Slice<ClothRecommendListResponse> result =
9596
clothRepository.findAllMemberRecommendClothesByCategoryAndSeason(
96-
lastClothId, size, categoryId, currentMember.getId(), season);
97+
lastClothId, size, categoryIds, currentMember.getId(), season);
9798

9899
return SliceResponse.from(result);
99100
}

clokey-api/src/test/java/org/clokey/domain/cloth/service/ClothServiceTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,10 @@ void setUp() {
259259
memberRepository.save(member);
260260
given(memberUtil.getCurrentMember()).willReturn(member);
261261

262-
Category category1 = Category.createCategory("testCategory1", null);
263-
Category category2 = Category.createCategory("testCategory2", null);
264-
categoryRepository.saveAll(List.of(category1, category2));
262+
Category parentCategory1 = Category.createCategory("testParentCategory1", null);
263+
Category parentCategory2 = Category.createCategory("testParentCategory2", null);
264+
Category category1 = Category.createCategory("testCategory1", parentCategory1);
265+
categoryRepository.saveAll(List.of(parentCategory1, parentCategory2, category1));
265266

266267
Cloth cloth1 =
267268
Cloth.createCloth(

0 commit comments

Comments
 (0)