using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using GB5Shared.ListQuery; using PIEDAL.DTO.Proposal; using static GB5Shared.GB5Constant.Constant; namespace PIESL.EndPoints.Proposal { public class GetPIEProposalList : BaseEndpoint> { private readonly IListHandler _ListHandler; public GetPIEProposalList(IListHandler listHandler) { _ListHandler = listHandler; } public override void Configure() { Post("/PIE/GetPIEProposalList"); AllowAnonymous(); } public record Params( [property: FromHeader] string Login, [property: QueryParam] Guid? ProfileId = null, [property: QueryParam] short? Status = null, [property: QueryParam] string? ProposalType = null, [property: QueryParam] string? SearchText = null, [property: QueryParam] string? SortBy = null, [property: QueryParam] bool SortDesc = false, [property: QueryParam] int PageOffset = 0, [property: QueryParam] int PageSize = 50 ); protected override string? GetCacheKey(Params req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync(Params req, LoginDTO loginDTO, CancellationToken ct) { var criteria = new PIEProposalListCriteria { ProfileId = req.ProfileId, Status = req.Status, ProposalType = short.TryParse(req.ProposalType, out var proposalType) ? proposalType : null, SearchText = req.SearchText, SortBy = req.SortBy, SortDesc = req.SortDesc, PageOffset = req.PageOffset, PageSize = req.PageSize }; var result = await _ListHandler.HandleAsync(new PIEProposalListQuery(criteria), loginDTO, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, loginDTO); } } }