using AnalyticsBLL.KPIEvaluation; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AnalyticsSL.EndPoints.KPI { // Fast list read off the TKPIVALUE snapshot posted by PostKPIValues -- never a compute-on-read // path. The natural target for the FE's already-built kpi-card-adapter. public class GetKPIValues : BaseEndpoint> { private readonly IKPIEvaluationBLL _bll; public GetKPIValues(IKPIEvaluationBLL bll) => _bll = bll; public override void Configure() { Post("/Analytics/KPI/GetKPIValues"); AllowAnonymous(); } public record GetKPIValuesRequestBody(List? KpiIds, int PeriodDetailId, int OUId); public record GetKPIValuesParameters( [property: FromHeader] string Login, [property: FromBody] GetKPIValuesRequestBody Body ); protected override string? GetCacheKey(GetKPIValuesParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( GetKPIValuesParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetKPIValues(req.Body.KpiIds, req.Body.PeriodDetailId, req.Body.OUId, 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); } } } }