Skip to content

Commit

Permalink
Merge pull request #139 from jyjyjy25/refactor/#137-rating
Browse files Browse the repository at this point in the history
Refactor/#137 rating
  • Loading branch information
jyjyjy25 authored Feb 11, 2024
2 parents d1fbf18 + d84744d commit 57432f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public class UserProfileDTO {
@ApiModelProperty(value = "이메일")
private String email;

@ApiModelProperty(value = "내 리뷰 평균 평점")
@ApiModelProperty(value = "내 리뷰 평균 별점")
private double averageRating;

@ApiModelProperty(value = "작성한 리뷰 리스트")
@ApiModelProperty(value = "작성한 리뷰의 별점 리스트")
private UserReviewRatingListDTO ratingList;

@ApiModelProperty(value = "1순위 취향 장르")
Expand Down
33 changes: 22 additions & 11 deletions src/main/java/tavebalak/OTTify/user/service/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ public class UserServiceImpl implements UserService {
private final ReplyRepository replyRepository;
private final AWSS3Service awss3Service;

private static final double RATING_ZERO_DOT_FIVE = 0.5;
private static final double RATING_ONE = 1.0;
private static final double RATING_ONE_DOT_FIVE = 1.5;
private static final double RATING_TWO = 2.0;
private static final double RATING_TWO_DOT_FIVE = 2.5;
private static final double RATING_THREE = 3.0;
private static final double RATING_THREE_DOT_FIVE = 3.5;
private static final double RATING_FOUR = 4.0;
private static final double RATING_FOUR_DOT_FIVE = 4.5;
private static final double RATING_FIVE = 5.0;

@Override
public UserProfileDTO getUserProfile(Long userId) {
User user = userRepository.findById(userId)
Expand All @@ -93,7 +104,7 @@ public UserProfileDTO getUserProfile(Long userId) {
// 별점 리스트 가져오기
HashMap<Double, Integer> ratingList = new HashMap<Double, Integer>();
ArrayList<Double> ratingSet = new ArrayList<>(
Arrays.asList(0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0));
Arrays.asList(RATING_ZERO_DOT_FIVE, RATING_ONE, RATING_ONE_DOT_FIVE, RATING_TWO, RATING_TWO_DOT_FIVE, RATING_THREE, RATING_THREE_DOT_FIVE, RATING_FOUR, RATING_FOUR_DOT_FIVE, RATING_FIVE));

List<Double> reviewRatingList = new ArrayList<>();
reviewRepository.findByUserId(userId).stream()
Expand All @@ -110,16 +121,16 @@ public UserProfileDTO getUserProfile(Long userId) {

UserReviewRatingListDTO userReviewRatingListDTO = UserReviewRatingListDTO.builder()
.totalCnt(reviewRatingList.size())
.pointFiveCnt(ratingList.get(0.5))
.oneCnt(ratingList.get(1.0))
.oneDotFiveCnt(ratingList.get(1.5))
.twoCnt(ratingList.get(2.0))
.twoDotFiveCnt(ratingList.get(2.5))
.threeCnt(ratingList.get(3.0))
.threeDotFiveCnt(ratingList.get(3.5))
.fourCnt(ratingList.get(4.0))
.fourDotFiveCnt(ratingList.get(4.5))
.fiveCnt(ratingList.get(5.0))
.pointFiveCnt(ratingList.get(RATING_ZERO_DOT_FIVE))
.oneCnt(ratingList.get(RATING_ONE))
.oneDotFiveCnt(ratingList.get(RATING_ONE_DOT_FIVE))
.twoCnt(ratingList.get(RATING_TWO))
.twoDotFiveCnt(ratingList.get(RATING_TWO_DOT_FIVE))
.threeCnt(ratingList.get(RATING_THREE))
.threeDotFiveCnt(ratingList.get(RATING_THREE_DOT_FIVE))
.fourCnt(ratingList.get(RATING_FOUR))
.fourDotFiveCnt(ratingList.get(RATING_FOUR_DOT_FIVE))
.fiveCnt(ratingList.get(RATING_FIVE))
.build();

// OTT 리스트 가져오기
Expand Down

0 comments on commit 57432f7

Please sign in to comment.