implemented deletion of notice

This commit is contained in:
2025-04-14 10:08:26 +02:00
parent b0f47b475a
commit f17b97eaf9
2 changed files with 21 additions and 0 deletions

View File

@@ -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}")
// public ResponseEntity<String> checkNotice(@PathVariable("id") long id) {
// if (noticeService.noticeExists(id)) {

View File

@@ -93,4 +93,14 @@ public NoticeDTO updateNotice(Long id, NoticeDTO dto) {
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);
}
}
}