UzyTPerfilMenuController.java 2.17 KB
Newer Older
1 2
package ec.edu.espe.movilidad.MovilidadWS.Controller;

3
import ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTPerfilMenu;
4 5 6 7 8 9 10 11 12 13 14 15
import ec.edu.espe.movilidad.MovilidadWS.Service.UzyTPerfilMenu.IServiceUzyTPerfilMenu;
import org.springframework.beans.factory.annotation.Autowired;
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 = "*")
16
@RequestMapping(V1_API_VERSION + "/perfilmenu")
17 18
public class UzyTPerfilMenuController {

19 20
    private final IServiceUzyTPerfilMenu serviceUzyTPerfilMenu;

21
    @Autowired
22 23 24
    public UzyTPerfilMenuController(IServiceUzyTPerfilMenu serviceUzyTPerfilMenu) {
        this.serviceUzyTPerfilMenu = serviceUzyTPerfilMenu;
    }
25 26 27

    @GetMapping("/exampleFindId/{id}")

28
    public ResponseEntity<DtoUzyTPerfilMenu> ListarPorID(@PathVariable Long id) {
29
        return ResponseEntity.ok(serviceUzyTPerfilMenu.ListarPorID(id));
30
    }
31 32

    @GetMapping("/getAll")
33
    public ResponseEntity<List<DtoUzyTPerfilMenu>> ListarRegistros() {
34 35
        return new ResponseEntity<>(serviceUzyTPerfilMenu.ListarRegistros(), HttpStatus.OK);

36 37 38
    }

    @PostMapping("/guardar")
39
    public ResponseEntity<DtoUzyTPerfilMenu> guardar(@RequestBody DtoUzyTPerfilMenu dtoUzyTPerfilMenu) {
40 41
        return new ResponseEntity<>(serviceUzyTPerfilMenu.guardar(dtoUzyTPerfilMenu), HttpStatus.OK);

42 43 44
    }

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

    @PutMapping("/editar/{id}")
    public ResponseEntity<DtoUzyTPerfilMenu> editar(@PathVariable Long id,
                                                    @RequestBody DtoUzyTPerfilMenu dtoUzyTPerfilMenu) {
57 58
        return new ResponseEntity<>(serviceUzyTPerfilMenu.editar(id, dtoUzyTPerfilMenu), HttpStatus.OK);

59 60
    }

61
}