Skip to content

Commit

Permalink
addVisit 수정하기
Browse files Browse the repository at this point in the history
- 맛집에 방문할 때마다, 그동안 받은 별점들의 평균을 계산해서 넣어주기

Related to: #37
  • Loading branch information
ahyoon99 committed Sep 6, 2024
1 parent 2cbbc5f commit 865b769
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ public void addVisit(int index, int starRating) {
if(!restaurantEntity.isVisit()){ // 방문한 적 없는 식당인 경우, isVisit을 true로 변경해주기
restaurantEntity.setVisit(true);
}
restaurantEntity.setVisitCount(restaurantEntity.getVisitCount()+1);

// 평균 별점 계산해주기
int restaurantEntityVisitCount = restaurantEntity.getVisitCount();
double restaurantEntityStarRating = restaurantEntity.getStarRating();

starRating = (int) (restaurantEntityStarRating*restaurantEntityVisitCount+starRating)/(restaurantEntityVisitCount+1);

restaurantEntity.setVisitCount(restaurantEntityVisitCount+1);
restaurantEntity.setStarRating(starRating);
restaurantEntity.setLastVisitDate(LocalDateTime.now());
wishListRepository.updateById(index, restaurantEntity);
Expand Down

0 comments on commit 865b769

Please sign in to comment.