using AdminBLL.Period; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AdminSL.EndPoints.Period { public class GetPeriod : BaseEndpoint { private readonly IPeriodBLL _PeriodBLL; public GetPeriod(IPeriodBLL IPeriodBLL) { _PeriodBLL = IPeriodBLL; } public override void Configure() { Get("/Period/GetPeriod"); AllowAnonymous(); } public record GetPeriodParameters( [property: QueryParam] int PeriodId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetPeriodParameters GetPeriodParameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(GetPeriodParameters.PeriodId!, EntityConstant.GBPERIOD, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetPeriodParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _PeriodBLL.GetPeriod(req.PeriodId, 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); } } } }