public async Task <QueryResponse <string> > Query(KeywordQueryRequest query, CancellationToken cancellationToken = default) { var qr = Data.Keywords.AsQueryable(); if (!string.IsNullOrWhiteSpace(query.Name)) { qr = qr.Where(x => x.Name.Contains(query.Name)); } Pagination pagination = new Pagination { TotalCount = await qr.CountAsync(cancellationToken), }; if (query.Pagination != null) { qr = qr.Skip(query.Pagination.Offset).Take(query.Pagination.CountPerPage); pagination.PageNumber = query.Pagination.PageNumber; pagination.CountPerPage = query.Pagination.CountPerPage; } else { pagination.PageNumber = 0; pagination.CountPerPage = pagination.TotalCount; } return(new QueryResponse <string>(await qr.Select(x => x.Id).ToArrayAsync(cancellationToken), pagination)); }
public async Task <ActionResult <QueryResponse <string> > > Query([FromBody] KeywordQueryRequest query) { if (!await Provider.CanRead()) { return(BadRequest()); } return(Ok(await Provider.Query(query))); }
public virtual async Task <QueryResponse <string> > Query(KeywordQueryRequest query, CancellationToken cancellationToken = default) { query.Pagination ??= new Pagination(); PagingPath?paging = null; paging ??= new PagingPath(Path.Join(RootPath, "pages")); await EnsurePagingConfig(paging, cancellationToken); paging.FillPagination(query.Pagination); var res = new QueryResponse <string>(await GetPagingResult(paging, query.Pagination, cancellationToken), query.Pagination); return(res); }
public override async Task <IEnumerable <string> > All(CancellationToken cancellationToken = default) { List <string> result = new List <string>(); KeywordQueryRequest pq = new KeywordQueryRequest(); while (true) { cancellationToken.ThrowIfCancellationRequested(); var req = await Query(pq, cancellationToken); result.AddRange(req.Results); if (!req.CurrentPage.HasNextPage) { break; } pq.Pagination = req.CurrentPage.NextPage(); } return(result); }