Created
February 9, 2018 13:14
-
-
Save AntonioMontanha/8705da39083c567aa39c61352b76ef35 to your computer and use it in GitHub Desktop.
Método cadastrar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GerenciadorViagemController { | |
@Autowired | |
private ViagemServices viagemService; | |
@PostMapping(path = "/new") | |
public ResponseEntity<Response<Viagem>> cadastrar(@Valid @RequestBody ViagemDto viagemDto, BindingResult result) { | |
Response<Viagem> response = new Response<Viagem>(); | |
if (result.hasErrors()) { | |
result.getAllErrors().forEach(error -> response.getErrors().add(error.getDefaultMessage())); | |
return ResponseEntity.badRequest().body(response); | |
} | |
Viagem viagemSalva = this.viagemService.salvar(viagemDto); | |
URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(viagemDto.getId()) | |
.toUri(); | |
response.setData(viagemSalva); | |
return ResponseEntity.created(location).body(response); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment