using AnalyticsBLL.BICatalog; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AnalyticsSL.EndPoints.BI { // Computed-field picker for the config UI, scoped to one dataset — sibling of // GetDimensionsForDataset/GetMeasuresForDataset. See BICatalogBLL.GetComputedFieldsForDataset. public class GetComputedFieldsForDataset : BaseEndpoint> { private readonly IBICatalogBLL _bll; public GetComputedFieldsForDataset(IBICatalogBLL bll) => _bll = bll; public override void Configure() { Get("/BI/GetComputedFieldsForDataset"); AllowAnonymous(); } public record Params( [property: QueryParam] int BICatalogId, [property: FromHeader] string Login ); // "-computed" suffix is load-bearing, same reason GetMeasuresForDataset's own "-measures" // suffix is: BaseEndpoint's cache key has no route/endpoint-type component, so without a // distinguishing suffix this collides with GetDimensionsForDataset/GetMeasuresForDataset // for the same BICatalogId. protected override string? GetCacheKey(Params req, LoginDTO login) => KeyGenerator.KeyGeneration($"{req.BICatalogId}-computed", EntityConstant.OBJECTBICATALOG, CacheKeyLevel.CLIENT_LEVEL, login); protected override async Task> ExecuteAsync( Params req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetComputedFieldsForDataset(req.BICatalogId, login, ct).ConfigureAwait(false); return await GB5Shared.ResponseStandard.Response .CreateSuccessResponse(result, CacheKeyLevel.CLIENT_LEVEL, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError(ex, CacheKeyLevel.CLIENT_LEVEL, login, ex.Message, 500); } } } }