diff --git a/be/src/main/java/com/airbnb3/codesquad/airbnb3/controller/AirbnbControllerHamill.java b/be/src/main/java/com/airbnb3/codesquad/airbnb3/controller/AirbnbControllerHamill.java index 8c089ce..d0eca91 100644 --- a/be/src/main/java/com/airbnb3/codesquad/airbnb3/controller/AirbnbControllerHamill.java +++ b/be/src/main/java/com/airbnb3/codesquad/airbnb3/controller/AirbnbControllerHamill.java @@ -85,13 +85,13 @@ public ResponseEntity> findAllSaved(@RequestParam Long return new ResponseEntity<>(airbnbServiceHamill.findAllSaved(userId), HttpStatus.OK); } - @PutMapping("/saved/{id}") + @PutMapping("/saved/{propertyId}") public ResponseEntity savedTheProperties( - @PathVariable Long id, + @PathVariable Long propertyId, @RequestParam Long userId) { - airbnbServiceHamill.savedTheProperties(id, userId); - return new ResponseEntity<>(getMessage("200", "즐겨찾기 성공"), HttpStatus.OK); + airbnbServiceHamill.savedTheProperties(propertyId, userId); + return new ResponseEntity<>(getMessage("200", "즐겨찾기 추가"), HttpStatus.OK); } private CommonMessage getMessage(String statusCode, String message) { @@ -101,4 +101,13 @@ private CommonMessage getMessage(String statusCode, String message) { .message(message) .build(); } + + @DeleteMapping("/saved/{propertyId}") + public ResponseEntity cancelThePropertiesSaved( + @PathVariable Long propertyId) { + + airbnbServiceHamill.cancelThePropertiesSaved(propertyId); + return new ResponseEntity<>(getMessage("200", "즐겨찾기 취소"), HttpStatus.OK); + + } } diff --git a/be/src/main/java/com/airbnb3/codesquad/airbnb3/dao/PropertiesDaoHamill.java b/be/src/main/java/com/airbnb3/codesquad/airbnb3/dao/PropertiesDaoHamill.java index 39524f5..c585d34 100644 --- a/be/src/main/java/com/airbnb3/codesquad/airbnb3/dao/PropertiesDaoHamill.java +++ b/be/src/main/java/com/airbnb3/codesquad/airbnb3/dao/PropertiesDaoHamill.java @@ -339,9 +339,16 @@ public List findAllSaved(Long userId) { ,userId); } - public void updatedTheProperties(Long propertiesId) { + public void updatedThePropertiesSaved(Long propertyId) { + String sql = "UPDATE properties SET saved = true WHERE id = ?"; - jdbcTemplate.update(sql, propertiesId); + jdbcTemplate.update(sql, propertyId); + } + + public void cancelThePropertiesSaved(Long propertyId) { + + String sql = "DELETE FROM bookmarks WHERE properties_id = ?"; + jdbcTemplate.update(sql, propertyId); } } diff --git a/be/src/main/java/com/airbnb3/codesquad/airbnb3/service/AirbnbServiceHamill.java b/be/src/main/java/com/airbnb3/codesquad/airbnb3/service/AirbnbServiceHamill.java index 11d9802..e862bea 100644 --- a/be/src/main/java/com/airbnb3/codesquad/airbnb3/service/AirbnbServiceHamill.java +++ b/be/src/main/java/com/airbnb3/codesquad/airbnb3/service/AirbnbServiceHamill.java @@ -86,7 +86,7 @@ public void cancelTheProperties(Long propertiesId) { public void savedTheProperties(Long propertyId, Long userId) { propertiesDaoHamill.savedTheProperties(propertyId, userId); - propertiesDaoHamill.updatedTheProperties(propertyId); + propertiesDaoHamill.updatedThePropertiesSaved(propertyId); } // 즐겨찾기 목록 출력 @@ -95,6 +95,13 @@ public List findAllSaved(Long userId) { return propertiesDaoHamill.findAllSaved(userId); } + // 즐겨찾기 삭제 + public void cancelThePropertiesSaved(Long propertyId) { + + propertiesDaoHamill.cancelThePropertiesSaved(propertyId); + } + + private Integer parseStringToIntegerOffset(String offset) { if (offset == null) {