api para obtener datos de los logs
This commit is contained in:
52
Aspnet/Controllers/LogsController.cs
Normal file
52
Aspnet/Controllers/LogsController.cs
Normal file
@@ -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<LogDto> 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<LogDetalleDto> 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);
|
||||
}
|
||||
}
|
||||
9
Entidades/Logs/LogDetalleDto.cs
Normal file
9
Entidades/Logs/LogDetalleDto.cs
Normal file
@@ -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; }
|
||||
}
|
||||
7
Entidades/Logs/LogDto.cs
Normal file
7
Entidades/Logs/LogDto.cs
Normal file
@@ -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!;
|
||||
}
|
||||
|
||||
19
Modelo/RepositorioLogs.cs
Normal file
19
Modelo/RepositorioLogs.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Linq;
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Modelo;
|
||||
public class RepositorioLogs: RepositorioBase<RepositorioLogs> {
|
||||
public ICollection<LogDetalle> 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<Log>? ObtenerLogsPaginado(int pag) {
|
||||
var con = Context;
|
||||
var l = con.Logs.Skip(10*pag).Take(10);
|
||||
return l;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user