-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[KAN-99] 리뷰 작성,수정,삭제시 음식점 평균 별점 및 리뷰 개수 반영 #66
Conversation
private fun applyReviewCountAndAvgRating(restaurantId: Long, requestRating: Double) { | ||
val restaurant = restaurantRepository.findById(restaurantId).getOrNull() | ||
?: throw NotFoundRestaurantException() | ||
val beforeCount = restaurant.reviewCount | ||
restaurant.reviewCount = beforeCount + 1 | ||
restaurant.ratingAvg = (restaurant.ratingAvg * beforeCount + requestRating) / (beforeCount + 1) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요 함수는 여기에 추가하지말고, restaurant에 비즈니스 메서드로 추가해서 진행하면 더 좋을 것 같습니다!
private fun applyReviewCountAndAvgRating(restaurantId: Long) { | ||
val restaurant = restaurantRepository.findById(restaurantId).getOrNull() | ||
?: throw NotFoundRestaurantException() | ||
val beforeCount = restaurant.reviewCount | ||
if (beforeCount <= 1) { | ||
restaurant.ratingAvg = 0.0 | ||
restaurant.reviewCount = 0 | ||
} else { | ||
restaurant.ratingAvg = (restaurant.ratingAvg * beforeCount) / (beforeCount - 1) | ||
restaurant.reviewCount = beforeCount - 1 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이것도 마찬가지!
val reviews: List<ReviewResponseDto> | ||
val reviews: List<ReviewResponseDto>, | ||
@Schema(description = "Pagination 정보") | ||
val pageable: Pageable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List가아니라 Page<>로 전달부탁드립니다
No description provided.