get one notice by id
This commit is contained in:
@@ -21,11 +21,20 @@ public class NoticeController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ClientService clientService;
|
private ClientService clientService;
|
||||||
|
|
||||||
@GetMapping("/all")
|
@GetMapping("/get/all")
|
||||||
public List<NoticeDTO> getAllNotices() {
|
public List<NoticeDTO> getAllNotices() {
|
||||||
return noticeService.getAllNotices();
|
return noticeService.getAllNotices();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get/{id}")
|
||||||
|
public ResponseEntity getNoticeById(@PathVariable long id) {
|
||||||
|
if (noticeService.noticeExists(id)) {
|
||||||
|
return ResponseEntity.ok(noticeService.getNoticeById(id));
|
||||||
|
} else {
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
public ResponseEntity<String> addNotice(@RequestBody NoticeDTO dto) {
|
public ResponseEntity<String> addNotice(@RequestBody NoticeDTO dto) {
|
||||||
if (!clientService.clientExists(dto.getClientId())) {
|
if (!clientService.clientExists(dto.getClientId())) {
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ public class NoticeService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NoticeDTO getNoticeById(Long id) {
|
||||||
|
Notice notice = noticeRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id));
|
||||||
|
return toDTO(notice);
|
||||||
|
}
|
||||||
|
|
||||||
public void addNotice(Notice notice) {
|
public void addNotice(Notice notice) {
|
||||||
noticeRepository.save(notice);
|
noticeRepository.save(notice);
|
||||||
}
|
}
|
||||||
@@ -101,6 +107,4 @@ public void deleteNotice(Long id) {
|
|||||||
throw new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id);
|
throw new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user