package ec.edu.espe.movilidad.MovilidadWS.Controller; import ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTavObjPlanVinvula; import ec.edu.espe.movilidad.MovilidadWS.Service.UzyTavObjPlanVinvula.IServiceUzyTavObjPlanVinvula; import org.springframework.web.bind.annotation.*; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import javax.validation.Valid; import java.util.List; import static ec.edu.espe.movilidad.MovilidadWS.Constant.GlobalConstants.V1_API_VERSION; @RestController @CrossOrigin(origins = "*") @RequestMapping(V1_API_VERSION + "/objplanvinvula") public class UzyTavObjPlanVinvulaController { private final IServiceUzyTavObjPlanVinvula serviceUzyTavObjPlanVinvula; public UzyTavObjPlanVinvulaController(IServiceUzyTavObjPlanVinvula serviceUzyTavObjPlanVinvula) { this.serviceUzyTavObjPlanVinvula = serviceUzyTavObjPlanVinvula; } @GetMapping("/exampleFindId/{id}") public ResponseEntity<DtoUzyTavObjPlanVinvula> ListarPorID(@PathVariable Long id) { return new ResponseEntity<>(serviceUzyTavObjPlanVinvula.ListarPorID(id), HttpStatus.OK); } @GetMapping("/getAll") public ResponseEntity<List<DtoUzyTavObjPlanVinvula>> ListarRegistros() { return new ResponseEntity<>(serviceUzyTavObjPlanVinvula.ListarRegistros(), HttpStatus.OK); } @PostMapping("/guardar") public ResponseEntity<DtoUzyTavObjPlanVinvula> guardar(@Valid @RequestBody DtoUzyTavObjPlanVinvula dtoUzyTavObjPlanVinvula) { DtoUzyTavObjPlanVinvula savedDto = serviceUzyTavObjPlanVinvula.guardar(dtoUzyTavObjPlanVinvula); return ResponseEntity.ok(savedDto); } @PutMapping("/editar/{id}") public ResponseEntity<DtoUzyTavObjPlanVinvula> editar(@PathVariable Long id, @RequestBody DtoUzyTavObjPlanVinvula dtoUzyTavObjPlanVinvula) { return new ResponseEntity<>(serviceUzyTavObjPlanVinvula.editar(id, dtoUzyTavObjPlanVinvula), HttpStatus.OK); } @DeleteMapping("/eliminar/{id}") public ResponseEntity<String> eliminar(@PathVariable Long id) { boolean eliminado = serviceUzyTavObjPlanVinvula.eliminar(id); if (eliminado) { return ResponseEntity.ok("El registro se eliminĂ³ exitosamente."); } else { return ResponseEntity.notFound().build(); } } }