From bc6c64894f48cbb5b76ec8e727435d6ef7773edf Mon Sep 17 00:00:00 2001 From: ahyoon99 Date: Wed, 21 Aug 2024 16:16:23 +0900 Subject: [PATCH] =?UTF-8?q?updateById=20=EC=9E=91=EC=84=B1=ED=95=98?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related to: #37 --- .../naverrestaurant/db/H2DbRepositoryAbstract.java | 8 ++++++++ .../example/naverrestaurant/db/MemoryDbRepositoryIfs.java | 1 + .../naverrestaurant/wishlist/service/WishListService.java | 1 + 3 files changed, 10 insertions(+) diff --git a/src/main/java/com/example/naverrestaurant/db/H2DbRepositoryAbstract.java b/src/main/java/com/example/naverrestaurant/db/H2DbRepositoryAbstract.java index 2471975..dda561f 100644 --- a/src/main/java/com/example/naverrestaurant/db/H2DbRepositoryAbstract.java +++ b/src/main/java/com/example/naverrestaurant/db/H2DbRepositoryAbstract.java @@ -68,6 +68,14 @@ public List listAll() { return (List) result; } + @Override + public void updateById(int index, T entity) { + String updateByIdQuery = "update restaurant set isvisit=?, visitcount=? where index=?"; + + WishListEntity wishListEntity = (WishListEntity) entity; + jdbcTemplate.update(updateByIdQuery, wishListEntity.isVisit(), wishListEntity.getVisitCount(), index); + } + private RowMapper wishListEntityRowMapper(){ return ((rs, rowNum) -> { WishListEntity wishListEntity = new WishListEntity(); diff --git a/src/main/java/com/example/naverrestaurant/db/MemoryDbRepositoryIfs.java b/src/main/java/com/example/naverrestaurant/db/MemoryDbRepositoryIfs.java index b57d979..df7a750 100644 --- a/src/main/java/com/example/naverrestaurant/db/MemoryDbRepositoryIfs.java +++ b/src/main/java/com/example/naverrestaurant/db/MemoryDbRepositoryIfs.java @@ -9,5 +9,6 @@ public interface MemoryDbRepositoryIfs { T save(T entity); void deleteById(int index); List listAll(); + void updateById(int index, T entity); } 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 81e15f0..089c448 100644 --- a/src/main/java/com/example/naverrestaurant/wishlist/service/WishListService.java +++ b/src/main/java/com/example/naverrestaurant/wishlist/service/WishListService.java @@ -112,6 +112,7 @@ public void addVisit(int index) { var restaurnatEntity = restaurant.get(); restaurnatEntity.setVisit(true); restaurnatEntity.setVisitCount(restaurnatEntity.getVisitCount()+1); + wishListRepository.updateById(index, restaurnatEntity); } }