UzyTavCabComcaController.java 2.06 KB
Newer Older
1
package ec.edu.espe.movilidad.MovilidadWS.Controller;
2

3 4
import ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTavCabComca;

5
import ec.edu.espe.movilidad.MovilidadWS.Service.UzyTavCabComca.IServiceUzyTavCabComca;
6 7 8 9 10 11 12 13 14 15 16 17
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+"/cabcomca")
public class UzyTavCabComcaController {
18 19 20 21 22
    private final IServiceUzyTavCabComca serviceUzyTavCabComca;

    public UzyTavCabComcaController(IServiceUzyTavCabComca serviceUzyTavCabComca) {
        this.serviceUzyTavCabComca = serviceUzyTavCabComca;
    }
23 24 25


    @GetMapping("/exampleFindId/{id}")
26
    public ResponseEntity<DtoUzyTavCabComca> ListarPorID(@PathVariable Long id) {
27 28 29 30
        return new ResponseEntity<>(serviceUzyTavCabComca.ListarPorID(id), HttpStatus.OK);
    }

    @GetMapping("/getAll")
31
    public ResponseEntity<List<DtoUzyTavCabComca>> ListarRegistros() {
32 33 34 35 36
        return new ResponseEntity<>(serviceUzyTavCabComca.ListarRegistros(), HttpStatus.OK);
    }


    @PostMapping("/guardar")
37 38
    public ResponseEntity<DtoUzyTavCabComca> guardar(@RequestBody DtoUzyTavCabComca dtoUzyTavCabComca) {
        return new  ResponseEntity<>(serviceUzyTavCabComca.guardar(dtoUzyTavCabComca), HttpStatus.OK);
39 40 41 42
    }


    @PutMapping("/editar/{id}")
43 44
    public ResponseEntity<DtoUzyTavCabComca> editar(@PathVariable Long id, @RequestBody DtoUzyTavCabComca dtoUzyTavCabComca) {
        return new  ResponseEntity<>(serviceUzyTavCabComca.editar(id, dtoUzyTavCabComca), HttpStatus.OK);
45 46 47
    }


48

49
    @DeleteMapping("/eliminar/{id}")
50 51 52 53 54 55 56
    public ResponseEntity<String> eliminar(@PathVariable Long id){
        boolean eliminado = serviceUzyTavCabComca.eliminar(id);
        if (eliminado) {
            return ResponseEntity.ok("El registro se eliminó exitosamente.");
        } else {
            return ResponseEntity.notFound().build();
        }
57 58
    }
}