I try to access a route from my controller and it returns a 404 error instead of returning the entity in a JSON with POSTMAN
This is my controller
package com.main.CitaMedica.Controller;
import com.main.CitaMedica.DTO.CitaDTO;
import com.main.CitaMedica.DTO.MedicoDTO;
import com.main.CitaMedica.DTO.PacienteDTO;
import com.main.CitaMedica.Service.CitaService;
import com.main.CitaMedica.Service.MedicoService;
import com.main.CitaMedica.Service.PacienteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("/citas")
public class CitaController {
@Autowired CitaService citaService;
@Autowired MedicoService medicoService;
@Autowired PacienteService pacienteService;
@GetMapping("mostrarTodos")
public ResponseEntity<CitaDTO> showCitas(){
List<CitaDTO> citas = citaService.findAll();
return new ResponseEntity(citas, HttpStatus.OK);
}
@GetMapping("mostrarUno/{citaID}")
public ResponseEntity<CitaDTO> showCita(@PathVariable("citaID") int citaID){
CitaDTO cita = citaService.findById(citaID);
return new ResponseEntity(cita,HttpStatus.OK);
}
/*
@GetMapping("mostrar/porFecha/{fecha}")
public ResponseEntity<Cita> showCitaFechaHora(@PathVariable("fecha")Date fecha){
List<Cita> cita = citaService.findByFechaHora(fecha);
return new ResponseEntity(cita,HttpStatus.OK);
}
*/
@PostMapping("create")
public ResponseEntity<CitaDTO> crearCita(){
MedicoDTO medico = medicoService.findById(5);
PacienteDTO paciente = pacienteService.findById(3);
CitaDTO cita = new CitaDTO();
cita.setMedico(medico);
cita.setPaciente(paciente);
cita.setFechaHora(new Date());
cita.setMotivoCita("Prueba");
citaService.save(cita);
return new ResponseEntity(HttpStatus.OK);
}
@PutMapping("update/{citaID}")
public ResponseEntity<CitaDTO> actualizarCita(@PathVariable("citaID") int citaID){
CitaDTO cita = citaService.findById(citaID);
cita.setMotivoCita("Enfermedad");
citaService.save(cita);
return new ResponseEntity(HttpStatus.OK);
}
@DeleteMapping("delete/{citaID}")
public ResponseEntity<CitaDTO> delete(@PathVariable("citaID") int citaID){
citaService.delete(citaID);
return new ResponseEntity(HttpStatus.OK);
}
}
And this is the error that POSTMAN gives me when I try to access that route and I have the server started by port 8090
{
"timestamp": "2023-02-06T17:00:50.592+00:00",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/citas/mostrarTodos"
}
Before it worked for me and it returned all the data when I did not have DTO and MapperStructure but since I have implemented it now in all the routes it gives me that
Ask me for any information
I solved my problem by adding @Mapper(componentModel="spring") in all mappers it was my mistake