using FastEndpoints; using FrameworkBLL.AuditQuery; using FrameworkDAL.DTO.AuditQuery; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using System; using System.Threading; using System.Threading.Tasks; using static FrameworkDAL.Constant.Constant; namespace FrameworkSL.Endpoints.Audit { public class GetAuditByEntity : BaseEndpoint> { private readonly IAuditQueryBLL _bll; public GetAuditByEntity(IAuditQueryBLL bll) => _bll = bll; public override void Configure() { Get("/Audit/GetAuditByEntity"); AllowAnonymous(); } public record Params( [property: FromHeader] string Login, [property: QueryParam] int EntityType, [property: QueryParam] int EntityId, [property: QueryParam] int PageOffset = 0, [property: QueryParam] int PageSize = 50 ); protected override async Task> ExecuteAsync( Params req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetByEntityAsync( req.EntityType, req.EntityId, req.PageOffset, req.PageSize, login, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result, CacheKeyLevel.UserLevel, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.UserLevel, login, ex.Message, 500); } } } }