using System.Text.Json; using FastEndpoints; using FrameworkBLL.WorkFlow; using FrameworkDAL.DTO.Workflow; using FrameworkDAL.Query.Region; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static FrameworkDAL.Constant.Constant; namespace FrameworkSL.Endpoints.WorkFlow { public class GetWorkFlowApprovalList : BaseEndpoint> { private readonly IWorkFlowBLL _IWorkFlowBLL; public GetWorkFlowApprovalList(IWorkFlowBLL IWorkFlowBLL) { _IWorkFlowBLL = IWorkFlowBLL; } public override void Configure() { Post("/WorkFlow/GetWorkFlowApprovalList"); AllowAnonymous(); } public record GetWorkFlowApprovalListParameters( [property: FromHeader] string Login, [property: QueryParam] int WorkflowType, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult, [property: FromBody] CriteriaDTO CriteriaDTO ); protected override async Task> ExecuteAsync(GetWorkFlowApprovalListParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _IWorkFlowBLL.WorkFlowApprovalList(req.WorkflowType, req.FirstNumber, req.MaxResult, req.CriteriaDTO, LoginDTO); int total = result.FirstOrDefault()?.TotalCount ?? 0; int first = req.FirstNumber + 1; int last = req.FirstNumber + result.Count; int previous = req.FirstNumber > 0 ? Math.Max(1, first - req.MaxResult) : 0; int next = last < total ? last + 1 : 0; var response = await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.NotRequired, LoginDTO); response.Total = total; response.First = first.ToString(); response.Last = last.ToString(); response.Previous = previous.ToString(); response.Next = next.ToString(); return response; } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NotRequired, LoginDTO, ex.Message, 500); } } } }