Skip to content

Commit

Permalink
merge: 케이크 인기순 조회 groupby #132
Browse files Browse the repository at this point in the history
[FIX] 케이크 인기순 조회 groupby #132
  • Loading branch information
sjk4618 authored Jan 22, 2025
2 parents 27ac8a6 + b7da5a0 commit af65894
Showing 1 changed file with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ public List<CakeInfoDto> findPopularLikedCakesByUser(final long userId,
)
.from(cake)
.join(store).on(cake.storeId.eq(store.id))
.join(cakeLikes).on(cakeLikes.cakeId.eq(cake.id).and(cakeLikes.userId.eq(userId)));
.join(cakeLikes).on(cakeLikes.cakeId.eq(cake.id).and(cakeLikes.userId.eq(userId)))
.groupBy(cake.id);

/// 조건 처리
if (cakeLikesCursor == null && cakeIdCursor == null) {
Expand Down Expand Up @@ -537,12 +538,6 @@ public List<CakeInfoDto> findPopularCakesByCategoryAndTheme(final DayCategory da
QCakeLikes cakeLikes = QCakeLikes.cakeLikes;
QStore store = QStore.store;

/// 좋아요 개수를 계산하는 서브쿼리
// final JPQLQuery<Integer> cakeLikesCountSubQuery = JPAExpressions
// .select(cakeLikes.count().intValue())
// .from(cakeLikes)
// .where(cakeLikes.cakeId.eq(cake.id));

/// 좋아요 개수를 정렬 가능한 표현식으로 변환
final NumberExpression<Integer> cakeLikesOrderExpression = Expressions.asNumber(JPAExpressions
.select(cakeLikes.count().intValue())
Expand Down Expand Up @@ -573,8 +568,8 @@ public List<CakeInfoDto> findPopularCakesByCategoryAndTheme(final DayCategory da
)
.from(cake)
.join(store).on(cake.storeId.eq(store.id))
.leftJoin(cakeTheme).on(cake.id.eq(cakeTheme.cakeId)); // CakeTheme 조인

.leftJoin(cakeTheme).on(cake.id.eq(cakeTheme.cakeId)) // CakeTheme 조인
.groupBy(cake.id);
/// 조건 추가
query.where(cake.dayCategory.eq(dayCategory)); // dayCategory는 필수 조건

Expand Down Expand Up @@ -686,8 +681,8 @@ public List<CakeInfoDto> findPopularCakesLikedByUser(final long userId,
)
.from(cake)
.join(store).on(cake.storeId.eq(store.id))
.join(storeLikes).on(store.id.eq(storeLikes.storeId).and(storeLikes.userId.eq(userId))); /// 유저가 좋아요한 스토어만

.join(storeLikes).on(store.id.eq(storeLikes.storeId).and(storeLikes.userId.eq(userId))) /// 유저가 좋아요한 스토어만
.groupBy(cake.id);
/// 조건 처리
if (cakeLikesCursor == null && cakeIdCursor == null) {
/// 1. 아이디커서와 좋아요커서 둘 다 없을 때
Expand Down

0 comments on commit af65894

Please sign in to comment.