diff --git a/Aspnet/Controllers/LogsController.cs b/Aspnet/Controllers/LogsController.cs new file mode 100644 index 0000000..fa3544c --- /dev/null +++ b/Aspnet/Controllers/LogsController.cs @@ -0,0 +1,52 @@ +using Entidades.Dto; +using Microsoft.AspNetCore.Mvc; +using Modelo; + +namespace AlquilaFacil.Controllers; + +[ApiController] +public class LogsController: ControllerBase { + + [HttpGet("/api/Logs")] + public IActionResult ObtenerLogs([FromHeader(Name = "Auth")] string Auth, long pag=1) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Informes"); + if (validacion1 == false) return Unauthorized(); + if (pag<=0) return BadRequest(new { message = "no puede haber una pagina 0 o menor"}); + + pag-=1; + + var l = RepositorioLogs.Singleton.ObtenerLogsPaginado(pag); + List ll = new(); + foreach (var i in l) { + ll.Add(new LogDto{ + Fecha = i.Fecha, + Accion = i.Accion, + Dniusuario = i.Dniusuario, + }); + } + return Ok(ll); + } + + [HttpGet("/api/Logs/detalle")] + public IActionResult ObtenerLogs([FromHeader(Name = "Auth")] string Auth, [FromQuery]DateTime fecha, [FromQuery]long idusuario) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Informes"); + if (validacion1 == false) return Unauthorized(); + if (idusuario<=0) return BadRequest(new { message = "no puede haber un id 0 o menor"}); + + var l = RepositorioLogs.Singleton.ObtenerDetallesLogs(fecha, idusuario); + List ll = new(); + foreach (var i in l) { + ll.Add(new LogDetalleDto{ + Fecha = i.Fecha, + Dniusuario = i.Dniusuario, + NombreTabla = i.NombreTabla, + Columna = i.Columna, + ValorAnterior = i.ValorAnterior, + ValorNuevo = i.ValorNuevo, + }); + } + return Ok(ll); + } +} \ No newline at end of file diff --git a/Entidades/Logs/LogDetalleDto.cs b/Entidades/Logs/LogDetalleDto.cs new file mode 100644 index 0000000..195d831 --- /dev/null +++ b/Entidades/Logs/LogDetalleDto.cs @@ -0,0 +1,9 @@ +namespace Entidades.Dto; +public class LogDetalleDto { + public DateTime Fecha { get; set; } + public long Dniusuario { get; set; } + public string NombreTabla { get; set; } = null!; + public string Columna { get; set; } = null!; + public string? ValorAnterior { get; set; } + public string? ValorNuevo { get; set; } +} \ No newline at end of file diff --git a/Entidades/Logs/LogDto.cs b/Entidades/Logs/LogDto.cs new file mode 100644 index 0000000..998ac45 --- /dev/null +++ b/Entidades/Logs/LogDto.cs @@ -0,0 +1,7 @@ +namespace Entidades.Dto; +public class LogDto { + public DateTime Fecha { get; set; } + public long Dniusuario { get; set; } + public string Accion { get; set; } = null!; +} + diff --git a/Modelo/RepositorioLogs.cs b/Modelo/RepositorioLogs.cs new file mode 100644 index 0000000..18f2d8f --- /dev/null +++ b/Modelo/RepositorioLogs.cs @@ -0,0 +1,19 @@ +using System.Linq; +using Entidades; +using Microsoft.EntityFrameworkCore; + +namespace Modelo; +public class RepositorioLogs: RepositorioBase { + public ICollection ObtenerDetallesLogs(DateTime fecha, long idusuario) { + var con = Context; + var d = con.Logs.Include(x=>x.LogDetalles) + .FirstOrDefault(x => x.Fecha == fecha && x.Dniusuario == idusuario); + return d.LogDetalles; + } + + public IQueryable? ObtenerLogsPaginado(int pag) { + var con = Context; + var l = con.Logs.Skip(10*pag).Take(10); + return l; + } +} \ No newline at end of file