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