Skip to content

Commit

Permalink
addVisit 수정하기
Browse files Browse the repository at this point in the history
- 별점 변수를 int 타입에서 double 타입으로 수정하기

Related to: #37
  • Loading branch information
ahyoon99 committed Sep 6, 2024
1 parent 865b769 commit 1c1d74f
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private RowMapper<WishListEntity> wishListEntityRowMapper(){
if(rs.getTimestamp("lastVisitDate") != null){ // lastVisitDate가 null이 아닐 때만 set 해주기
wishListEntity.setLastVisitDate(rs.getTimestamp("lastVisitDate").toLocalDateTime());
}
wishListEntity.setStarRating((rs.getInt("starRating")));
wishListEntity.setStarRating((rs.getDouble("starRating")));
return wishListEntity;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ public class WishListDto {
private boolean isVisit; // 방문 여부
private int visitCount; // 방문 횟수
private LocalDateTime lastVisitDate; // 마지막 방문 날짜
private int starRating; // 별점
private double starRating; // 별점
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public class WishListEntity extends MemoryDbEntity {
private boolean isVisit; // 방문 여부
private int visitCount; // 방문 횟수
private LocalDateTime lastVisitDate; // 마지막 방문 날짜
private int starRating; // 별점
private double starRating; // 별점
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ public void addVisit(int index, int starRating) {
int restaurantEntityVisitCount = restaurantEntity.getVisitCount();
double restaurantEntityStarRating = restaurantEntity.getStarRating();

starRating = (int) (restaurantEntityStarRating*restaurantEntityVisitCount+starRating)/(restaurantEntityVisitCount+1);
restaurantEntityStarRating = (Math.round(((restaurantEntityStarRating*restaurantEntityVisitCount+starRating)/(restaurantEntityVisitCount+1))*100)/100.0);

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

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/h2/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ CREATE TABLE RESTAURANT
isVisit BOOLEAN NOT NULL, -- 방문 여부
visitCount INTEGER NOT NULL, -- 방문 횟수
lastVisitDate TIMESTAMP, -- 마지막 방문 날짜
starRating INTEGER -- 별점
starRating DOUBLE -- 별점
);

0 comments on commit 1c1d74f

Please sign in to comment.