From ba41fda2f6c6443fedebe531a14aec944d05fc20 Mon Sep 17 00:00:00 2001 From: ahyoon99 Date: Tue, 3 Sep 2024 11:32:20 +0900 Subject: [PATCH] =?UTF-8?q?addVisit()=20=EC=88=98=EC=A0=95=ED=95=98?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit addVisit()에서 하는 일 - 최초 방문 시, isVisit을 true로 수정해주기 - visitCount 1 증가시켜주기 - starRating을 최근에 받은 값으로 수정해주기 Related to: #37 --- .../controller/ApiController.java | 8 ++----- .../wishlist/service/WishListService.java | 22 ++++++++----------- .../wishlist/service/WishListServiceTest.java | 2 +- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/example/naverrestaurant/controller/ApiController.java b/src/main/java/com/example/naverrestaurant/controller/ApiController.java index 591d112..47fe7c5 100644 --- a/src/main/java/com/example/naverrestaurant/controller/ApiController.java +++ b/src/main/java/com/example/naverrestaurant/controller/ApiController.java @@ -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); - } } diff --git a/src/main/java/com/example/naverrestaurant/wishlist/service/WishListService.java b/src/main/java/com/example/naverrestaurant/wishlist/service/WishListService.java index fe5ddcb..60c67a3 100644 --- a/src/main/java/com/example/naverrestaurant/wishlist/service/WishListService.java +++ b/src/main/java/com/example/naverrestaurant/wishlist/service/WishListService.java @@ -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가 존재하지 않을 때 + + } } - } diff --git a/src/test/java/com/example/naverrestaurant/wishlist/service/WishListServiceTest.java b/src/test/java/com/example/naverrestaurant/wishlist/service/WishListServiceTest.java index 867c0e0..d6815de 100644 --- a/src/test/java/com/example/naverrestaurant/wishlist/service/WishListServiceTest.java +++ b/src/test/java/com/example/naverrestaurant/wishlist/service/WishListServiceTest.java @@ -70,7 +70,7 @@ public void addVisitTest(){ var saveEntity = wishListService.add(wishListDto); - wishListService.addVisit(1); + wishListService.addVisit(1, 3); List wishList = wishListService.findAll();