using FastEndpoints; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.TeamCalendar; using System; using System.Threading; using System.Threading.Tasks; namespace PayRollSL.EndPoints.TeamCalendar { public class GetFiltersTeamCalendar : BaseEndpoint> { private readonly ITeamCalendarBLL _teamCalendarBLL; public GetFiltersTeamCalendar(ITeamCalendarBLL teamCalendarBLL) { _teamCalendarBLL = teamCalendarBLL; } public override void Configure() { Post("/TeamCalendar/GetFiltersTeamCalendar"); AllowAnonymous(); } public record GetFiltersTeamCalendarParameters( [property: QueryParam] long EmployeeId, [property: QueryParam] int EmployeeLevel, [property: QueryParam] string FromDate, [property: QueryParam] string ToDate, [property: QueryParam] bool Team, [property: QueryParam] string OUId, [property: QueryParam] bool ShowAllEmployees, [property: QueryParam] byte EmployeeStatus, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxNumber, [property: FromHeader] string Login ); protected override async Task> ExecuteAsync( GetFiltersTeamCalendarParameters req, LoginDTO loginDTO, CancellationToken ct) { try { if (!DateTime.TryParse(req.FromDate, out var fromDate)) throw new ArgumentException("Invalid FromDate"); if (!DateTime.TryParse(req.ToDate, out var toDate)) throw new ArgumentException("Invalid ToDate"); var result = await _teamCalendarBLL.GetFiltersTeamCalendar( req.EmployeeId, req.EmployeeLevel, fromDate, toDate, req.ShowAllEmployees, req.OUId, req.EmployeeStatus, req.Team, req.FirstNumber, req.MaxNumber, new CriteriaDTO(), loginDTO); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result, GB5Shared.GB5Constant.Constant.CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, GB5Shared.GB5Constant.Constant.CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }