Skip to content

Commit

Permalink
Merge pull request #174 from kookmin-sw/#130-evaluation
Browse files Browse the repository at this point in the history
#130 evaluation
  • Loading branch information
hyeesw authored May 5, 2024
2 parents 2366d7f + cb4f892 commit 62d4460
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

@Repository
public interface ReviewRepository extends JpaRepository<Review, Long> {

int countByReceiverUserId(Long receiverId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.coffee.backend.domain.company.entity.Company;
import com.coffee.backend.domain.fcm.service.FcmService;
import com.coffee.backend.domain.match.dto.MatchDto;
import com.coffee.backend.domain.match.dto.MatchInfoResponseDto;
import com.coffee.backend.domain.match.dto.MatchIdDto;
import com.coffee.backend.domain.match.dto.MatchInfoDto;
import com.coffee.backend.domain.match.dto.MatchInfoResponseDto;
import com.coffee.backend.domain.match.dto.MatchRequestDto;
import com.coffee.backend.domain.match.dto.MatchStatusDto;
import com.coffee.backend.domain.match.dto.ReviewDto;
Expand Down Expand Up @@ -216,9 +216,28 @@ public Boolean isMatching(MatchIdDto dto) {

@Transactional
public Review saveReview(ReviewDto dto) {
if (dto.getRating() < 1 || dto.getRating() > 5) {
throw new CustomException(ErrorCode.VALUE_ERROR);
}

User sender = userRepository.findByUserId(dto.getSenderId()).orElseThrow();
User receiver = userRepository.findByUserId(dto.getReceiverId()).orElseThrow();

int numberOfReviews = reviewRepository.countByReceiverUserId(receiver.getUserId());
double oldCoffeeBean = receiver.getCoffeeBean();

double baseline = 46.0;
double ratio = 0.1;
double standard = 4.0;

// 46 + (평점 합계 + (새로운 평점 - 기준 평점) * 반영 비율) / (평점 개수 + 1)
double newCoffeeBean =
baseline + ((oldCoffeeBean - baseline) * numberOfReviews + (dto.getRating() - standard) * ratio) /
(numberOfReviews + 1);

receiver.setCoffeeBean(newCoffeeBean);
userRepository.save(receiver);

Review review = new Review();
review.setSender(sender);
review.setReceiver(receiver);
Expand All @@ -228,4 +247,4 @@ public Review saveReview(ReviewDto dto) {
reviewRepository.save(review);
return review;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class User {
private Long kakaoId;
private String loginId;
private String password;
private double coffeeBean = 46.0;

@ManyToOne
@JoinColumn(name = "company_id")
Expand All @@ -37,4 +38,4 @@ public class User {
private String userUUID;
private String introduction;
private String deviceToken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public enum ErrorCode {
REQUEST_NOT_FOUND(HttpStatus.NOT_FOUND, "7404", "해당 요청 정보를 찾을 수 없습니다."),
REQUEST_EXPIRED(HttpStatus.UNAUTHORIZED, "7401", "요청이 만료되었습니다."),

COMPANY_NOT_FOUND(HttpStatus.NOT_FOUND, "8404", "해당 COMPANY를 찾을 수 없습니다.");
COMPANY_NOT_FOUND(HttpStatus.NOT_FOUND, "8404", "해당 COMPANY를 찾을 수 없습니다."),

VALUE_ERROR(HttpStatus.BAD_REQUEST, "9400", "잘못된 값이 입력되었습니다.");

private final HttpStatus status;
private final String code;
Expand Down

0 comments on commit 62d4460

Please sign in to comment.