Skip to content

Commit

Permalink
Merge pull request #185 from PSR-Co/fix/#184-avgOfReviewRating
Browse files Browse the repository at this point in the history
[fix] 상품 메인 조회 리뷰 평균 별점 소수점 1자리까지 수정
  • Loading branch information
sojungpp committed Oct 21, 2023
2 parents 9537c51 + 6b1192e commit 597b36f
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.psr.psr.user.entity.Category
import com.psr.psr.user.entity.User
import com.querydsl.core.types.ExpressionUtils
import com.querydsl.core.types.dsl.Expressions
import com.querydsl.core.types.dsl.MathExpressions
import com.querydsl.jpa.JPAExpressions
import com.querydsl.jpa.impl.JPAQueryFactory
import org.springframework.data.domain.Page
Expand All @@ -35,7 +36,7 @@ class ProductRepositoryImpl(
product.price,
ExpressionUtils.`as`(product.likeNum.size(), "numOfLike"),
Expressions.asBoolean(JPAExpressions.selectFrom(productLike).where(productLike.user.eq(target).and(productLike.product.eq(product)).and(productLike.status.eq(ACTIVE_STATUS))).exists()),
ExpressionUtils.`as`(JPAExpressions.select(review.rating.avg()).from(review).where(review.product.eq(product).and(review.status.eq(ACTIVE_STATUS))), "avgOfRating"),
ExpressionUtils.`as`(JPAExpressions.select(MathExpressions.round(review.rating.avg(),1)).from(review).where(review.product.eq(product).and(review.status.eq(ACTIVE_STATUS))), "avgOfRating"),
ExpressionUtils.`as`(product.reviews.size(), "numOfReview")
))
.from(product)
Expand Down

0 comments on commit 597b36f

Please sign in to comment.