Skip to content

Commit

Permalink
addVisit() 수정하기
Browse files Browse the repository at this point in the history
addVisit()에서 하는 일
- 최초 방문 시, isVisit을 true로 수정해주기
- visitCount 1 증가시켜주기
- starRating을 최근에 받은 값으로 수정해주기

Related to: #37
  • Loading branch information
ahyoon99 committed Sep 3, 2024
1 parent d2c589a commit ba41fda
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@ public void delete(@PathVariable int index){
}

@PostMapping("/{index}")
public void addVisit(@PathVariable int index){
wishListService.addVisit(index);
public void addVisit(@PathVariable int index, @RequestParam int starRating){
wishListService.addVisit(index, starRating);
}

@PatchMapping("/{index}")
public void setStarRating(@PathVariable int index, @RequestParam int starRating){
wishListService.setStarRating(index, starRating);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,23 @@ public WishListDto find(int index) {
}
return entityToDto(wishListEntity.get()); // wishListEntity에 값이 있으면 wishListDto로 변환하여 리턴하기
}

public void addVisit(int index) {
var restaurant = wishListRepository.findById(index);
if (restaurant.isPresent()){
var restaurnatEntity = restaurant.get();
restaurnatEntity.setVisit(true);
restaurnatEntity.setVisitCount(restaurnatEntity.getVisitCount()+1);
wishListRepository.updateById(index, restaurnatEntity);
}
}

public void setStarRating(int index, int starRating){
public void addVisit(int index, int starRating) {
var restaurant = wishListRepository.findById(index);
if(restaurant.isPresent()){
if (restaurant.isPresent()){
var restaurantEntity = restaurant.get();
if(!restaurantEntity.isVisit()){ // 방문한 적 없는 식당인 경우, isVisit을 true로 변경해주기
restaurantEntity.setVisit(true);
}
restaurantEntity.setVisitCount(restaurantEntity.getVisitCount()+1);
restaurantEntity.setStarRating(starRating);
wishListRepository.updateById(index, restaurantEntity);

var result = wishListRepository.findById(index);
System.out.println(result.toString());
}
else{ // index에 해당하는 WishListEntity가 존재하지 않을 때

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void addVisitTest(){

var saveEntity = wishListService.add(wishListDto);

wishListService.addVisit(1);
wishListService.addVisit(1, 3);

List<WishListDto> wishList = wishListService.findAll();

Expand Down

0 comments on commit ba41fda

Please sign in to comment.