using FastEndpoints; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.TLeave; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.TLeave { public class GetTotalLeaveTaken : BaseEndpoint> { private readonly ITLeaveBLL _TLeaveBLL; public GetTotalLeaveTaken(ITLeaveBLL tLeaveBLL) { _TLeaveBLL = tLeaveBLL; } public override void Configure() { Post("/TLeave/TotalLeaveTaken"); AllowAnonymous(); } public record GetTotalLeaveTakenParameters( [property: FromHeader] string Login, [property: FromBody] CriteriaDTO CriteriaDTO, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult ); protected override async Task> ExecuteAsync( GetTotalLeaveTakenParameters req, LoginDTO login, CancellationToken ct) { try { var data = await _TLeaveBLL.GetTotalLeaveTaken(req.FirstNumber, req.MaxResult, req.CriteriaDTO, login); var response = await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(data, CacheKeyLevel.NOT_REQUIRED, login); var countResult = await _TLeaveBLL.GetTotalLeaveTaken(req.FirstNumber, req.MaxResult, req.CriteriaDTO, login, true); response.Total = countResult.Count > 0 ? countResult[0].TotalCount : 0; return response; } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 500); } } } }