Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Metodo Delete não é suportado, (usando relacionamento) Method not allowed 405

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();

}

}

1 resposta
solução!

Já achei o erro, obrigado esqueci o Id do delete Mapping

@DeleteMapping({"id"})

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software