Пример #1
0
 @Override
 @RequestMapping(method = RequestMethod.POST)
 @ResponseBody
 public ResponseEntity<DataDTO> save(@RequestBody DataDTO data) {
   Data res = dataService.save(DataDTO.from(data));
   URI uri = URI.create("/api/data/" + res.getId());
   return ResponseEntity.created(uri).body(DataDTO.to(res));
 }
Пример #2
0
 @Override
 @RequestMapping(path = "/{id}", method = RequestMethod.GET)
 @ResponseBody
 public ResponseEntity<DataDTO> getData(@PathVariable(value = "id") Long id) {
   return dataService
       .getData(id)
       .map(d -> ResponseEntity.ok(DataDTO.to(d)))
       .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
 }