añadido endpoint para crear permisos
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Entidades.Dto;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Modelo;
|
||||
using System.Text.Json;
|
||||
using Entidades;
|
||||
|
||||
|
||||
namespace AlquilaFacil.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class AccionesController: ControllerBase {
|
||||
|
||||
public class AccionesController : ControllerBase
|
||||
{
|
||||
|
||||
[HttpGet("api/acciones")]
|
||||
public IActionResult ListarAccionesPorUsuario([FromHeader(Name ="Email")] string Email, [FromHeader(Name = "Auth")] string Auth) {
|
||||
public IActionResult ListarAccionesPorUsuario([FromHeader(Name = "Email")] string Email, [FromHeader(Name = "Auth")] string Auth)
|
||||
{
|
||||
if (Email == "" || Email == null) return BadRequest();
|
||||
|
||||
if (Auth == "") return Unauthorized(new { esValido = false});
|
||||
|
||||
if (Auth == "") return Unauthorized(new { esValido = false });
|
||||
|
||||
bool esValido = RepositorioUsuarios.Singleton.CheckToken(Email, Auth);
|
||||
if (!esValido) return Unauthorized();
|
||||
@@ -37,4 +37,34 @@ public class AccionesController: ControllerBase {
|
||||
var permisos = RepositorioGrupos.Singleton.ListarPermisosDeGrupo(req.Grupo);
|
||||
return Ok(permisos);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("api/acciones/crear")]
|
||||
public IActionResult CrearAcciones([FromHeader(Name = "Auth")] string Auth,
|
||||
[FromBody] CrearAccionesDto req)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Auth)) return BadRequest();
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
var ret = RepositorioPermisos.Singleton.CheckPermisos(Auth, 1); //wip lo voy a usar para crear el permiso que va
|
||||
if (ret == false) return Unauthorized();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(req.Descripcion))
|
||||
{
|
||||
return BadRequest(new { message = "La descripción no puede estar vacía" });
|
||||
}
|
||||
|
||||
if (req.Descripcion.Length > 25)
|
||||
{
|
||||
return BadRequest(new { message = "La descripción no puede ser mayor a 25 caracteres" });
|
||||
}
|
||||
|
||||
var per = new Permiso
|
||||
{
|
||||
Descripcion = req.Descripcion,
|
||||
}
|
||||
var ret2 = RepositorioPermisos.Singleton.CrearPermiso(per);
|
||||
return ret2 ? Ok(new { message = "se creo correctamente" }) : BadRequest(new { message = "No se pudo crear el permiso" });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user