Skip to content
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

[BE] feat: 상품 랭킹 기능 추가 #204

Merged
merged 11 commits into from
Aug 2, 2023
Merged

[BE] feat: 상품 랭킹 기능 추가 #204

merged 11 commits into from
Aug 2, 2023

Conversation

Go-Jaecheol
Copy link
Collaborator

Issue

✨ 구현한 기능

상품 랭킹을 조회하는 기능 구현

$$ RankingScore = AvgRating - (AvgRating - 3.0)*2^{-log_{10}(Total Reviews + 1)} $$

  • 1.0 ~ 5.0의 AvgRating이 나오게 되므로 그 중간에 있는 3.0을 기준으로 기준치 선정
  • 평점이 3.0 보다 큰 상품에 대해서만 랭킹에 포함될 수 있도록 정책 변경

📢 논의하고 싶은 내용

  • ProductRepositoryfindAllProductsAndReviewCountByAverageRatingGreaterThan3() 메서드 명 이대로 괜찮은가..!
  • ProductService에서 stream 한 번만 돌면서 각 Product의 랭킹 점수 구하고, 내림차순 정렬해서 상위 3개에 해당하는 dto 구하도록 했는데 괜찮나용
  • Product 도메인에서 랭킹 점수를 구하는 비즈니스 로직을 처리하도록 하기 위해, ProductReviewCountDto에서 Product 엔티티를 필드로 가지도록 했는데 괜찮은지..!

⏰ 일정

  • 추정 시간 : 2h
  • 걸린 시간 : 4h

@github-actions
Copy link

github-actions bot commented Aug 1, 2023

Unit Test Results

67 tests   67 ✔️  10s ⏱️
34 suites    0 💤
34 files      0

Results for commit 2df0347.

♻️ This comment has been updated with latest results.

Copy link
Member

@70825 70825 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

랭킹 기능 점수 계산하는거 최고 👍👍

Comment on lines 38 to 43
@Query("SELECT new com.funeat.product.dto.ProductReviewCountDto(p, COUNT(r.id)) "
+ "FROM Product p "
+ "LEFT JOIN Review r ON r.product.id = p.id "
+ "WHERE p.averageRating > 3.0 "
+ "GROUP BY p.id")
List<ProductReviewCountDto> findAllProductsAndReviewCountByAverageRatingGreaterThan3();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저 궁금한 점이 생겼는데, 만약 서비스를 시작하고 나서 누군가의 계략으로 모든 상품의 평균 평점이 3.0 이하로 만들어버리면 리뷰 랭킹 기능은 상품을 보여줄 수 없는건가요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 개인적으로 평점이 3.0보다 작은 상품들은 랭킹에 노출될 필요가 없다고 생각해요
이 부분은 서비스 정책에 관한 거라 다 같이 얘기해보죠!

+ "LEFT JOIN Review r ON r.product.id = p.id "
+ "WHERE p.averageRating > 3.0 "
+ "GROUP BY p.id")
List<ProductReviewCountDto> findAllProductsAndReviewCountByAverageRatingGreaterThan3();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이미 반환값을 알고 있기때문에 findAllByAverageRatingGreaterThan3 도 괜찮아보여요!!

+ "LEFT JOIN Review r ON r.product.id = p.id "
+ "WHERE p.averageRating > 3.0 "
+ "GROUP BY p.id")
List<ProductReviewCountDto> findAllProductsAndReviewCountByAverageRatingGreaterThan3();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProductRepository의 findAllProductsAndReviewCountByAverageRatingGreaterThan3() 메서드 명 이대로 괜찮은가..!

반환값 이미 알고 있으니까 위 메소드랑 비슷하게 findAllByAverageRatingGreaterThan3 좋을 것 같아요~~

Copy link
Member

@70825 70825 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍👍👍

@Go-Jaecheol Go-Jaecheol merged commit 9164774 into develop Aug 2, 2023
3 checks passed
@Go-Jaecheol Go-Jaecheol deleted the feat/issue-142 branch August 2, 2023 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BE] 상품 랭킹 기능 추가
4 participants