Skip to content

Commit

Permalink
updateById 수정하기
Browse files Browse the repository at this point in the history
entity 자체를 수정해주었다.
그 결과, Service의 addVisit, setStarRating 메소드 둘 다 하나의 updateById 메소드를 통해 기능 수행이 가능해졌다.

Related to: #37
  • Loading branch information
ahyoon99 committed Sep 3, 2024
1 parent bce12e8 commit 5935346
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,17 @@ public List<T> listAll() {

@Override
public void updateById(int index, T entity) {
String updateByIdQuery = "update restaurant set isvisit=?, visitcount=? where index=?";
String updateByIdQuery = "update restaurant " +
"set title=?, category=?, address=?, roadAddress=?, homepageLink=?, imageLink=?, isvisit=?, visitCount=?, lastVisitDate=?, starRating=? where index=?";

WishListEntity wishListEntity = (WishListEntity) entity;
jdbcTemplate.update(updateByIdQuery, wishListEntity.isVisit(), wishListEntity.getVisitCount(), index);
}
Object []updateParams = new Object[] {wishListEntity.getTitle(),
wishListEntity.getCategory(), wishListEntity.getAddress(), wishListEntity.getRoadAddress(),
wishListEntity.getHomePageLink(), wishListEntity.getImageLink(), wishListEntity.isVisit(),
wishListEntity.getVisitCount(), wishListEntity.getLastVisitDate(), wishListEntity.getStarRating(), index};

jdbcTemplate.update(updateByIdQuery, updateParams);

public void updateStarRatingById(int index, int starRating){
String updateStarRatingByIdQuery = "update restaurant set starRating = ? where index = ?";
jdbcTemplate.update(updateStarRatingByIdQuery, starRating, index);
}

private RowMapper<WishListEntity> wishListEntityRowMapper(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void setStarRating(int index, int starRating){
if(restaurant.isPresent()){
var restaurantEntity = restaurant.get();
restaurantEntity.setStarRating(starRating);
wishListRepository.updateStarRatingById(index, starRating);
wishListRepository.updateById(index, restaurantEntity);

var result = wishListRepository.findById(index);
System.out.println(result.toString());
Expand Down

0 comments on commit 5935346

Please sign in to comment.