UzyTavObjetivosEstraInstiController.java 2.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
package ec.edu.espe.movilidad.MovilidadWS.Controller;
import ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTavObjetivosEstraInsti;
import ec.edu.espe.movilidad.MovilidadWS.Service.UzyTavObjetivosEstraInsti.IServiceUzyTavObjetivosEstraInsti;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

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+"/objetivosEstraInsti")
public class UzyTavObjetivosEstraInstiController {

    private final IServiceUzyTavObjetivosEstraInsti serviceUzyTavObjetivosEstraInsti;

    public UzyTavObjetivosEstraInstiController(IServiceUzyTavObjetivosEstraInsti serviceUzyTavObjetivosEstraInsti) {
        this.serviceUzyTavObjetivosEstraInsti = serviceUzyTavObjetivosEstraInsti;
    }

    @GetMapping("/exampleFindId/{id}")
    public ResponseEntity<DtoUzyTavObjetivosEstraInsti> ListarPorID(@PathVariable Long id) {
        return new ResponseEntity<>(serviceUzyTavObjetivosEstraInsti.ListarPorID(id), HttpStatus.OK);
    }

    @GetMapping("/obtenerEstraInstiPadre")
    public ResponseEntity<List<DtoUzyTavObjetivosEstraInsti>> obtenerEstraInstiPadre() {
        return new ResponseEntity<>(serviceUzyTavObjetivosEstraInsti.obtenerEstraInstiPadre(), HttpStatus.OK);
    }

    @GetMapping("/getAll")
    public ResponseEntity<List<DtoUzyTavObjetivosEstraInsti>> ListarRegistros() {
        return new ResponseEntity<>(serviceUzyTavObjetivosEstraInsti.ListarRegistros(), HttpStatus.OK);
    }

39 40 41 42 43
    @GetMapping("/obtenerPorPadreId/{padreId}")
    public ResponseEntity<List<DtoUzyTavObjetivosEstraInsti>> obtenerPorPadreId(@PathVariable Long padreId) {
        return new ResponseEntity<>(serviceUzyTavObjetivosEstraInsti.obtenerPorPadreId(padreId), HttpStatus.OK);
    }

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70


    @PostMapping("/guardar")
    public ResponseEntity<DtoUzyTavObjetivosEstraInsti> guardar(@Valid @RequestBody DtoUzyTavObjetivosEstraInsti dtoUzyTavObjetivosEstraInsti) {
        DtoUzyTavObjetivosEstraInsti savedDto = serviceUzyTavObjetivosEstraInsti.guardar(dtoUzyTavObjetivosEstraInsti);
        return ResponseEntity.ok(savedDto);
    }




    @PutMapping("/editar/{id}")
    public ResponseEntity<DtoUzyTavObjetivosEstraInsti> editar(@PathVariable Long id, @RequestBody DtoUzyTavObjetivosEstraInsti dtoUzyTavObjetivosEstraInsti) {
        return new ResponseEntity<>(serviceUzyTavObjetivosEstraInsti.editar(id, dtoUzyTavObjetivosEstraInsti), HttpStatus.OK);
    }


    @DeleteMapping("/eliminar/{id}")
    public ResponseEntity<String> eliminar(@PathVariable Long id){
        boolean eliminado = serviceUzyTavObjetivosEstraInsti.eliminar(id);
        if (eliminado) {
            return ResponseEntity.ok("El registro se eliminó exitosamente.");
        } else {
            return ResponseEntity.notFound().build();
        }
    }
}