Skip to content

Commit

Permalink
[BE] feat : 즐겨찾기 삭제 기능 구현
Browse files Browse the repository at this point in the history
- issue : #9
  • Loading branch information
hanurii committed Jun 1, 2020
1 parent 321a6f1 commit 50a0164
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ public ResponseEntity<List<PropertiesDtoHamill>> findAllSaved(@RequestParam Long
return new ResponseEntity<>(airbnbServiceHamill.findAllSaved(userId), HttpStatus.OK);
}

@PutMapping("/saved/{id}")
@PutMapping("/saved/{propertyId}")
public ResponseEntity<CommonMessage> 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) {
Expand All @@ -101,4 +101,13 @@ private CommonMessage getMessage(String statusCode, String message) {
.message(message)
.build();
}

@DeleteMapping("/saved/{propertyId}")
public ResponseEntity<CommonMessage> cancelThePropertiesSaved(
@PathVariable Long propertyId) {

airbnbServiceHamill.cancelThePropertiesSaved(propertyId);
return new ResponseEntity<>(getMessage("200", "즐겨찾기 취소"), HttpStatus.OK);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,16 @@ public List<PropertiesDtoHamill> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

// 즐겨찾기 목록 출력
Expand All @@ -95,6 +95,13 @@ public List<PropertiesDtoHamill> findAllSaved(Long userId) {
return propertiesDaoHamill.findAllSaved(userId);
}

// 즐겨찾기 삭제
public void cancelThePropertiesSaved(Long propertyId) {

propertiesDaoHamill.cancelThePropertiesSaved(propertyId);
}


private Integer parseStringToIntegerOffset(String offset) {

if (offset == null) {
Expand Down

0 comments on commit 50a0164

Please sign in to comment.