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