using FastEndpoints; using FrameworkBLL.Formula; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using System.Threading; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.Formula { public class GetFormula : BaseEndpoint { private readonly IFormulaBLL _formulaBLL; public GetFormula(IFormulaBLL formulaBLL) { _formulaBLL = formulaBLL; } public override void Configure() { Get("/Formula/GetFormula"); AllowAnonymous(); } public record GetFormulaParameters( [property: QueryParam] int FormulaId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetFormulaParameters GetFormulaParameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(GetFormulaParameters.FormulaId!, EntityConstant.OBJECTFORMULA, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetFormulaParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _formulaBLL.GetFormula(parameters.FormulaId, loginDTO!); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.USER_LEVEL, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.USER_LEVEL, loginDTO, ex.Message, 500); } } } }