Skip to content

Commit

Permalink
[KAN-76]
Browse files Browse the repository at this point in the history
- review -> 가장 좋아요 많이 받은 리뷰로 변경 필요
- menu, category -> 중복 데이터 제거 필요
  • Loading branch information
sinkyoungdeok committed May 21, 2024
1 parent 578797d commit 9448910
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data class RestaurantDto(
@Schema(description = "식당 영업 종료 시간")
val operatingEndTime: String,
@Schema(description = "식당 대표 리뷰 내용")
val representativeReviewContent: String,
val representativeReviewContent: String?,
@Schema(description = "식당 좋아요 여부(로그인한 유저)")
val isLike: Boolean,
@Schema(description = "식당 할인 내용")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.restaurant.be.restaurant.presentation.domain.entity.QMenu.menu
import com.restaurant.be.restaurant.presentation.domain.entity.QRestaurant.restaurant
import com.restaurant.be.restaurant.presentation.domain.entity.QRestaurantCategory.restaurantCategory
import com.restaurant.be.restaurant.presentation.domain.entity.QRestaurantLike.restaurantLike
import com.restaurant.be.restaurant.presentation.dto.common.CategoryDto
import com.restaurant.be.restaurant.presentation.dto.common.MenuDto
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 All @@ -16,28 +18,50 @@ class RestaurantRepositoryCustomImpl(
private val queryFactory: JPAQueryFactory
) : RestaurantRepositoryCustom {
override fun findDtoById(restaurantId: Long): RestaurantProjectionDto? {
val result = queryFactory
val restaurantInfo = queryFactory
.select(restaurant)
.from(restaurant)
.leftJoin(restaurantLike).on(restaurantLike.restaurantId.eq(restaurant.id))
.where(restaurant.id.eq(restaurantId))
.fetchOne()

val likedUsers = queryFactory
.select(user.id)
.from(restaurantLike)
.leftJoin(user).on(restaurantLike.userId.eq(user.id))
.leftJoin(menu).on(menu.restaurantId.eq(restaurant.id))
.leftJoin(restaurantCategory).on(restaurantCategory.restaurantId.eq(restaurant.id))
.where(restaurantLike.restaurantId.eq(restaurantId))
.fetch()

val menus = queryFactory
.select(menu)
.from(menu)
.where(menu.restaurantId.eq(restaurantId))
.fetch()

val review = queryFactory
.select(review)
.from(review)
.where(review.restaurantId.eq(restaurantId))
.orderBy(review.likeCount.desc())
.limit(1)
.fetchOne()

val categories = queryFactory
.select(category)
.from(restaurantCategory)
.leftJoin(category).on(restaurantCategory.categoryId.eq(category.id))
.leftJoin(review).on(review.restaurantId.eq(restaurant.id))
.where(restaurant.id.eq(restaurantId))
.transform(
GroupBy.groupBy(restaurant.id).list(
Projections.constructor(
RestaurantProjectionDto::class.java,
restaurant,
restaurantLike.userId.isNotNull(),
GroupBy.list(menu),
GroupBy.list(review),
GroupBy.list(category)
)
)
)
.where(restaurantCategory.restaurantId.eq(restaurantId))
.fetch()

return result.firstOrNull()
return if (restaurantInfo != null) {
RestaurantProjectionDto(
restaurantInfo,
likedUsers.isNotEmpty(),
menus,
review,
categories,
)
} else {
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import com.restaurant.be.restaurant.presentation.domain.entity.Restaurant
import com.restaurant.be.restaurant.presentation.dto.common.RestaurantDetailDto
import com.restaurant.be.restaurant.presentation.dto.common.RestaurantDto
import com.restaurant.be.review.domain.entity.Review
import kotlinx.serialization.json.JsonNull.content

data class RestaurantProjectionDto(
val restaurant: Restaurant,
val isLike: Boolean,
val menus: List<Menu>,
val review: List<Review>,
val review: Review?,
val categories: List<Category>
) {
fun toDto(): RestaurantDto {
Expand All @@ -27,7 +26,7 @@ data class RestaurantProjectionDto(
representativeMenu = menus.firstOrNull()?.toDto(),
operatingStartTime = "",
operatingEndTime = "",
representativeReviewContent = review.first().content,
representativeReviewContent = review?.content,
isLike = isLike,
discountContent = restaurant.discountContent,
detailInfo = RestaurantDetailDto(
Expand Down

0 comments on commit 9448910

Please sign in to comment.