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 { // The 'KPI Card'/'KPI List' portlet types' own data source (Phase 5) -- resolves "current // period" dynamically (latest posted TKPIVALUE for the requested OU) rather than requiring the // caller to pin a PeriodDetailId, so a dashboard card always reflects whatever was most // recently posted without needing reconfiguration. public class GetKPIValuesForPortlet : BaseEndpoint> { private readonly IKPIEvaluationBLL _bll; public GetKPIValuesForPortlet(IKPIEvaluationBLL bll) => _bll = bll; public override void Configure() { Post("/Analytics/KPI/GetKPIValuesForPortlet"); AllowAnonymous(); } public record GetKPIValuesForPortletRequestBody(List? KpiIds, int OUId); public record GetKPIValuesForPortletParameters( [property: FromHeader] string Login, [property: FromBody] GetKPIValuesForPortletRequestBody Body ); protected override string? GetCacheKey(GetKPIValuesForPortletParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( GetKPIValuesForPortletParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetKPIValuesForPortlet(req.Body.KpiIds, 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); } } } }