using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.Leave; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.Leave { public class GetLeaveBalanceBasedOnUsercode : BaseEndpoint> { private readonly ILeaveBLL _LeaveBLL; public GetLeaveBalanceBasedOnUsercode(ILeaveBLL leaveBLL) { _LeaveBLL = leaveBLL; } public override void Configure() { Get("/Leave/GetLeaveBalanceBasedOnUsercode"); AllowAnonymous(); } public record GetLeaveBalanceByUsercodeParameters( [property: FromHeader] string Login, [property: QueryParam] DateTime PeriodFrom, [property: QueryParam] DateTime PeriodTo ); protected override async Task> ExecuteAsync(GetLeaveBalanceByUsercodeParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _LeaveBLL.GetLeaveBalanceByUserCodeAsync(req.PeriodFrom, req.PeriodTo, LoginDTO!); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, ex.Message, 500); } } } }