package ar.gob.snr.gestion.incidente.controller; import java.util.List; import javax.inject.Inject; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import ar.gob.snr.gestion.incidente.domain.dao.IncidenteRepository; import ar.gob.snr.gestion.incidente.domain.model.Incidente; import ar.gob.snr.gestion.incidente.domain.service.IncidenteService; @RestController public class IncidenteController { @Autowired IncidenteRepository incidenteRepository; @Autowired private final IncidenteService incidenteService; @Inject public IncidenteController(final IncidenteService incidenteService) { this.incidenteService = incidenteService;// Inject a IncidenteService // codigo en POM } @RequestMapping(value = "/get/incidente/{codename}", method = RequestMethod.GET) @ResponseBody public Object queryIncidente(@PathVariable String codename) { Incidente incidente = incidenteService.getIncidente(codename); if (incidente == null) return "No encontrado"; return incidente;// Metodo para traer todos los incidentes con // determinado codename } @RequestMapping(value = "/get/incidente/", method = RequestMethod.GET) @ResponseBody public Object queryIncidente() { List incidenteL = incidenteRepository.findAll(); return incidenteL; }// Metodo para traer todos los incidentes @RequestMapping(value = "/services/incidente", method = RequestMethod.POST) public Incidente createIncidente(@RequestBody @Valid final Incidente incidente) { return incidenteRepository.save(incidente); } }