using FastEndpoints; using FrameworkBLL.LoadTemplate; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.LoadTemplate { public class GetLoadTemplate : BaseEndpoint { private readonly ILoadTemplateBLL _LoadTemplateBLL; public GetLoadTemplate(ILoadTemplateBLL LoadTemplateBLL) { _LoadTemplateBLL = LoadTemplateBLL; } public override void Configure() { Get("/LoadTemplate/GetLoadTemplate"); AllowAnonymous(); } public record GetLoadTemplateParameters( [property: QueryParam] int LoadTemplateId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetLoadTemplateParameters GetLoadTemplateParameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(GetLoadTemplateParameters.LoadTemplateId!, EntityConstant.OBJECTLOADTEMPLATE, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetLoadTemplateParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _LoadTemplateBLL.GetLoadTemplate(parameters.LoadTemplateId, 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); } } } }