Last active
November 24, 2022 15:36
-
-
Save eliasnogueira/4a2377e9c29825817b505bd2c31acfca to your computer and use it in GitHub Desktop.
[JavaAdvent] Simulation controller example for the POST method
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
@PostMapping("/") | |
@ResponseStatus(HttpStatus.CREATED) | |
public ResponseEntity<Simulation> newSimulation(@Valid @RequestBody SimulationDto simulation) { | |
checkForRestriction(simulation.getCpf()); | |
Simulation createdSimulation = repository.save(new ModelMapper().map(simulation, Simulation.class)); | |
URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{cpf}"). | |
buildAndExpand(createdSimulation.getCpf()).toUri(); | |
return ResponseEntity.created(location).build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment