implemented deletion of notice
This commit is contained in:
@@ -82,6 +82,17 @@ public ResponseEntity<Object> editNotice(@PathVariable("id") long id, @RequestBo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete/{id}")
|
||||||
|
public ResponseEntity deleteNotice(@PathVariable("id") long id) {
|
||||||
|
if(noticeService.noticeExists(id)) {
|
||||||
|
noticeService.deleteNotice(id);
|
||||||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
} else {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// @GetMapping("/check/{id}")
|
// @GetMapping("/check/{id}")
|
||||||
// public ResponseEntity<String> checkNotice(@PathVariable("id") long id) {
|
// public ResponseEntity<String> checkNotice(@PathVariable("id") long id) {
|
||||||
// if (noticeService.noticeExists(id)) {
|
// if (noticeService.noticeExists(id)) {
|
||||||
|
|||||||
@@ -93,4 +93,14 @@ public NoticeDTO updateNotice(Long id, NoticeDTO dto) {
|
|||||||
|
|
||||||
return toDTO(noticeRepository.save(existingNotice));
|
return toDTO(noticeRepository.save(existingNotice));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteNotice(Long id) {
|
||||||
|
if (noticeExists(id)) {
|
||||||
|
noticeRepository.deleteById(id);
|
||||||
|
} else {
|
||||||
|
throw new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user