using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using WiBLL.WiAnalytics; using static GB5Shared.GB5Constant.Constant; namespace WiSL.EndPoints.WiAnalytics; public class GetExecutionHistory : BaseEndpoint> { private readonly IWiAnalyticsBLL _bll; public GetExecutionHistory(IWiAnalyticsBLL bll) => _bll = bll; public override void Configure() { Get("/WiAnalytics/GetExecutionHistory"); AllowAnonymous(); } public record Parameters( [property: FromHeader] string Login, [property: QueryParam] int WiId = -1, [property: QueryParam] int WorkstationId = -1, [property: QueryParam] int EmployeeId = -1, [property: QueryParam] DateTime FromDate = default, [property: QueryParam] DateTime ToDate = default ); protected override string? GetCacheKey(Parameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( Parameters req, LoginDTO login, CancellationToken ct) { try { var from = req.FromDate == default ? DateTime.UtcNow.AddMonths(-3) : req.FromDate; var to = req.ToDate == default ? DateTime.UtcNow : req.ToDate; var result = await _bll.GetExecutionHistoryAsync( req.WiId, req.WorkstationId, req.EmployeeId, from, to, login, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 500); } } }