Skip to content

Commit c9813e8

Browse files
authored
Merge pull request #311 from Clokey-dev/fix/#310-lookbook-query
[fix/#310] 룩북 쿼리 및 계절 추천 쿼리 오류 해결
1 parent 6fdc1e1 commit c9813e8

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,22 @@ public Slice<ClothRecommendListResponse> findAllMemberRecommendClothesByCategory
3535
Season nextSeason = season.next();
3636
Season previousSeason = season.previous();
3737
Season oppositeSeason = season.next().next();
38+
List<Season> targetSeasons = List.of(season, nextSeason, previousSeason, oppositeSeason);
3839

3940
// 우선 순위에 맞게 페이징 합니다.
4041
// - Category는 고정입니다.
4142
// - 계절은 요청한 계절에 가까운 순서대로 페이징을 진행합니다.
4243
NumberExpression<Integer> seasonPriority =
4344
new CaseBuilder()
44-
.when(cloth.seasons.contains(season))
45+
.when(cloth.seasons.any().in(List.of(season)))
4546
.then(1)
4647
.when(
4748
cloth.seasons
48-
.contains(nextSeason)
49-
.or(cloth.seasons.contains(previousSeason)))
49+
.any()
50+
.in(List.of(nextSeason))
51+
.or(cloth.seasons.any().in(List.of(previousSeason))))
5052
.then(2)
51-
.when(cloth.seasons.contains(oppositeSeason))
53+
.when(cloth.seasons.any().in(List.of(oppositeSeason)))
5254
.then(3)
5355
.otherwise(4);
5456

@@ -58,11 +60,7 @@ public Slice<ClothRecommendListResponse> findAllMemberRecommendClothesByCategory
5860
.where(
5961
cloth.category.id.eq(categoryId),
6062
cloth.member.id.eq(memberId),
61-
cloth.seasons
62-
.contains(season)
63-
.or(cloth.seasons.contains(nextSeason))
64-
.or(cloth.seasons.contains(previousSeason))
65-
.or(cloth.seasons.contains(oppositeSeason)))
63+
cloth.seasons.any().in(targetSeasons))
6664
.orderBy(seasonPriority.asc(), cloth.id.asc())
6765
.fetch();
6866

clokey-api/src/main/java/org/clokey/domain/lookbook/repository/LookBookRepositoryImpl.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.querydsl.jpa.impl.JPAQueryFactory;
1010
import java.util.List;
1111
import lombok.RequiredArgsConstructor;
12+
import org.clokey.coordinate.entity.QCoordinate;
1213
import org.clokey.domain.lookbook.dto.response.LookBookListResponse;
1314
import org.clokey.global.paging.SortDirection;
1415
import org.springframework.data.domain.PageRequest;
@@ -25,6 +26,8 @@ public class LookBookRepositoryImpl implements LookBookRepositoryCustom {
2526
@Override
2627
public Slice<LookBookListResponse> findAllLookBookByMemberId(
2728
Long currentMemberId, Long lastLookBookId, int size, SortDirection direction) {
29+
QCoordinate firstCoordinate = new QCoordinate("firstCoordinate");
30+
2831
List<LookBookListResponse> results =
2932
queryFactory
3033
.select(
@@ -35,12 +38,15 @@ public Slice<LookBookListResponse> findAllLookBookByMemberId(
3538
JPAExpressions.select(coordinate.count())
3639
.from(coordinate)
3740
.where(coordinate.lookBook.id.eq(lookBook.id)),
38-
JPAExpressions.select(coordinate.imageUrl)
39-
.from(coordinate)
40-
.where(coordinate.lookBook.id.eq(lookBook.id))
41-
.orderBy(coordinate.id.asc())
42-
.limit(1)))
41+
firstCoordinate.imageUrl))
4342
.from(lookBook)
43+
.leftJoin(firstCoordinate)
44+
.on(
45+
firstCoordinate.lookBook.id.eq(lookBook.id),
46+
firstCoordinate.id.eq(
47+
JPAExpressions.select(coordinate.id.min())
48+
.from(coordinate)
49+
.where(coordinate.lookBook.id.eq(lookBook.id))))
4450
.where(
4551
lookBook.member.id.eq(currentMemberId),
4652
lastLookBookIdCondition(lastLookBookId, direction))

0 commit comments

Comments
 (0)