Metodo Post e get funciona normal, já Delete não "error": "Method Not Allowed", "trace": "org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'DELETE' is not supported
@RestController @RequestMapping(value = "/motorista/automoveis") public class AutomovelController {
@Autowired
private AutomovelRepository automovelRepository;
@Autowired
private MotoristaRepository motoristaRepository;
@PostMapping("/{id}")
@Transactional
public ResponseEntity<DetalhesAutomovelDto> cadastrar(@PathVariable Long id,
@RequestBody @Valid AutomovelForm automovelForm,
UriComponentsBuilder uriComponentsBuilder) {
Automovel automovel = automovelForm.cadastrar(motoristaRepository, id);
automovelRepository.save(automovel);
URI uri = uriComponentsBuilder.path("/motorista/automovel/{id}").buildAndExpand(automovel.getId()).toUri();
return ResponseEntity.created(uri).build();
}
@GetMapping("/{id}")
@Transactional
public ResponseEntity<DetalhesMotoristaDto> ConsultaDetalhes(@PathVariable Long id) {
Optional<Motorista> motorista = motoristaRepository.findById(id);
if (motorista.isPresent()) {
return ResponseEntity.ok(new DetalhesMotoristaDto(motorista.get()));
}
return ResponseEntity.notFound().build();
}
@DeleteMapping
@Transactional
public ResponseEntity <?> deletarAutomovel(@PathVariable Long id) {
Optional<Automovel> automovel = automovelRepository.findById(id);
if (automovel.isPresent()) {
automovelRepository.deleteById(id);
return ResponseEntity.ok().build();
}
return ResponseEntity.notFound().build();
}
}