Skip to content

Instantly share code, notes, and snippets.

@eliasnogueira
Last active November 24, 2022 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliasnogueira/4a2377e9c29825817b505bd2c31acfca to your computer and use it in GitHub Desktop.
Save eliasnogueira/4a2377e9c29825817b505bd2c31acfca to your computer and use it in GitHub Desktop.
[JavaAdvent] Simulation controller example for the POST method
@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