From c4b200b7a84eeabeed5a6e3855de7ee0ba516edf Mon Sep 17 00:00:00 2001 From: Bob Sin Date: Mon, 27 May 2024 01:25:04 +0900 Subject: [PATCH] =?UTF-8?q?[KAN-100]=20=EB=82=B4=EA=B0=80=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=ED=95=9C=20=EB=A6=AC=EB=B7=B0,=20=EC=A2=8B=EC=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EA=B0=80=EA=B2=8C=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=EC=8B=9C=20=EA=B8=B0=EB=B3=B8=EC=A0=81=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=B5=9C=EC=8B=A0=EC=88=9C=20=EC=A0=95=EB=A0=AC=EB=A1=9C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=ED=95=9C=EB=8B=A4.=20(#69)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/service/LikeRestaurantService.kt | 2 +- .../controller/LikeRestaurantController.kt | 2 +- .../repository/RestaurantRepositoryCustomImpl.kt | 12 ++++++++++++ .../review/repository/ReviewRepositoryCustomImpl.kt | 7 ++++++- 4 files changed, 20 insertions(+), 3 deletions(-) rename src/main/kotlin/com/restaurant/be/restaurant/{presentation => }/domain/service/LikeRestaurantService.kt (97%) diff --git a/src/main/kotlin/com/restaurant/be/restaurant/presentation/domain/service/LikeRestaurantService.kt b/src/main/kotlin/com/restaurant/be/restaurant/domain/service/LikeRestaurantService.kt similarity index 97% rename from src/main/kotlin/com/restaurant/be/restaurant/presentation/domain/service/LikeRestaurantService.kt rename to src/main/kotlin/com/restaurant/be/restaurant/domain/service/LikeRestaurantService.kt index 7970605..2a697ed 100644 --- a/src/main/kotlin/com/restaurant/be/restaurant/presentation/domain/service/LikeRestaurantService.kt +++ b/src/main/kotlin/com/restaurant/be/restaurant/domain/service/LikeRestaurantService.kt @@ -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 diff --git a/src/main/kotlin/com/restaurant/be/restaurant/presentation/controller/LikeRestaurantController.kt b/src/main/kotlin/com/restaurant/be/restaurant/presentation/controller/LikeRestaurantController.kt index d5e896b..98474d3 100644 --- a/src/main/kotlin/com/restaurant/be/restaurant/presentation/controller/LikeRestaurantController.kt +++ b/src/main/kotlin/com/restaurant/be/restaurant/presentation/controller/LikeRestaurantController.kt @@ -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 diff --git a/src/main/kotlin/com/restaurant/be/restaurant/repository/RestaurantRepositoryCustomImpl.kt b/src/main/kotlin/com/restaurant/be/restaurant/repository/RestaurantRepositoryCustomImpl.kt index 4503669..c3a5027 100644 --- a/src/main/kotlin/com/restaurant/be/restaurant/repository/RestaurantRepositoryCustomImpl.kt +++ b/src/main/kotlin/com/restaurant/be/restaurant/repository/RestaurantRepositoryCustomImpl.kt @@ -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 @@ -128,6 +130,13 @@ class RestaurantRepositoryCustomImpl( userId: Long, pageable: Pageable ): Page { + 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) @@ -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 diff --git a/src/main/kotlin/com/restaurant/be/review/repository/ReviewRepositoryCustomImpl.kt b/src/main/kotlin/com/restaurant/be/review/repository/ReviewRepositoryCustomImpl.kt index 6067bf6..2547b6e 100644 --- a/src/main/kotlin/com/restaurant/be/review/repository/ReviewRepositoryCustomImpl.kt +++ b/src/main/kotlin/com/restaurant/be/review/repository/ReviewRepositoryCustomImpl.kt @@ -72,7 +72,12 @@ class ReviewRepositoryCustomImpl( } override fun findMyReviews(user: User, pageable: Pageable): Page { - 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(