1
My controller
package br.com.clinicamedica.controller.especialidade;
import static org.springframework.http.HttpStatus.CONFLICT;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import java.util.ArrayList;
import java.util.Collection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import br.com.clinicamedica.core.EspecialidadesException;
import br.com.clinicamedica.core.especialidades.EspecialidadesConsultaService;
import br.com.clinicamedica.core.especialidades.EspecialidadesService;
import br.com.clinicamedica.core.especialidades.resource.EspecialidadeListaResource;
import br.com.clinicamedica.core.especialidades.resource.EspecialidadesResource;
import br.com.clinicamedica.utilitario.mensagem.Mensagem;
import lombok.extern.apachecommons.CommonsLog;
@CommonsLog
@RestController
@RequestMapping("/especialidades")
public class EspecialidadeController {
@Autowired
private EspecialidadesService especialidadesService;
@Autowired
private EspecialidadesConsultaService especialidadesConsultaService;
private Collection<Mensagem> mensagens;
@PostMapping(value = "/incluir", produces = APPLICATION_JSON_VALUE)
public ResponseEntity<?> incluir(EspecialidadesResource resource) {
mensagens = new ArrayList<>();
try {
EspecialidadesResource retorno = especialidadesService.incluir(resource, mensagens);
return new ResponseEntity<>(retorno, OK);
} catch (EspecialidadesException e) {
Mensagem m = e.getMensagens().iterator().next();
log.error(m.toString(), e);
return new ResponseEntity<>(e.getMensagens().iterator().next(), CONFLICT);
}
}
}
In the Postman, when I do so, it does not work, because it is a post method, should not pass the object ?
In the Postman, when I do so, it works, this example would not be of a method get ?
The methods GET are functioning normally.
@GetMapping(value = "/buscarPeloId", produces = APPLICATION_JSON_VALUE) public ResponseEntity<?> buscarPeloId(Long id) { EspecialidadesResource retorno = especialidadesConsultaService.buscarPeloId(id); return new ResponseEntity<>(retorno, OK); }
What can it be ?
Thanks that’s right It’s been adjusted and it’s working.
– Guilherme Costa Lopes
@Guilhermecostalopes considering that this answer is a solution to your question, please mark it as an answer by clicking on the "check" below the positive/negative votes. This helps other people to know that the problem has been solved and not waste time trying to solve it again or to try to use the solution if they have a similar problem. I noticed that you did not do this in your other questions as well, I advise to do it in case someone has given the solution :)
– Rafael Tavares
Done and thanks for your help,
– Guilherme Costa Lopes