Skip to content

Commit

Permalink
[KAN-100] 내가 작성한 리뷰, 좋아요한 가게 조회시 기본적으로 최신순 정렬로 설정한다. (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkyoungdeok authored May 26, 2024
1 parent b34ebf0 commit c4b200b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.restaurant.be.restaurant.presentation.domain.service
package com.restaurant.be.restaurant.domain.service

import com.restaurant.be.common.exception.NotFoundRestaurantException
import com.restaurant.be.common.exception.NotFoundUserEmailException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.restaurant.be.restaurant.presentation.controller

import com.restaurant.be.common.response.CommonResponse
import com.restaurant.be.restaurant.domain.service.LikeRestaurantService
import com.restaurant.be.restaurant.presentation.controller.dto.GetLikeRestaurantsResponse
import com.restaurant.be.restaurant.presentation.controller.dto.LikeRestaurantRequest
import com.restaurant.be.restaurant.presentation.controller.dto.LikeRestaurantResponse
import com.restaurant.be.restaurant.presentation.domain.service.LikeRestaurantService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.v3.oas.annotations.media.Content
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.restaurant.be.restaurant.repository

import com.querydsl.core.types.dsl.PathBuilderFactory
import com.querydsl.jpa.impl.JPAQueryFactory
import com.restaurant.be.restaurant.domain.entity.QCategory.category
import com.restaurant.be.restaurant.domain.entity.QMenu.menu
import com.restaurant.be.restaurant.domain.entity.QRestaurant.restaurant
import com.restaurant.be.restaurant.domain.entity.QRestaurantCategory.restaurantCategory
import com.restaurant.be.restaurant.domain.entity.QRestaurantLike.restaurantLike
import com.restaurant.be.restaurant.domain.entity.RestaurantLike
import com.restaurant.be.restaurant.repository.dto.RestaurantProjectionDto
import com.restaurant.be.review.domain.entity.QReview.review
import com.restaurant.be.user.domain.entity.QUser.user
Expand Down Expand Up @@ -128,6 +130,13 @@ class RestaurantRepositoryCustomImpl(
userId: Long,
pageable: Pageable
): Page<RestaurantProjectionDto> {
val orderSpecifier = if (pageable.sort.isSorted) {
emptyList()
} else {
val restaurantLikePath = PathBuilderFactory().create(RestaurantLike::class.java)
listOf(restaurantLikePath.getNumber("id", Long::class.java).desc())
}

val myLikeQuery = queryFactory
.select(restaurantLike.restaurantId)
.from(restaurantLike)
Expand All @@ -144,6 +153,9 @@ class RestaurantRepositoryCustomImpl(
.select(restaurant)
.from(restaurant)
.where(restaurant.id.`in`(restaurantIds))
.leftJoin(restaurantLike).on(restaurant.id.eq(restaurantLike.restaurantId))
.orderBy(*orderSpecifier.toTypedArray())
.fetchJoin()
.fetch()

val menus = queryFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ class ReviewRepositoryCustomImpl(
}

override fun findMyReviews(user: User, pageable: Pageable): Page<ReviewWithLikesDto> {
val orderSpecifier = setOrderSpecifier(pageable)
val orderSpecifier = if (pageable.sort.isSorted) {
setOrderSpecifier(pageable)
} else {
val reviewPath = PathBuilderFactory().create(Review::class.java)
listOf(reviewPath.getNumber("id", Long::class.java).desc())
}

val reviewsWithLikes = queryFactory
.select(
Expand Down

0 comments on commit c4b200b

Please sign in to comment.