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