public async Task <List <TModel> > FilterAndGetAllAsync <TModel>(string queryString, string cursor = null, CancellationToken ct = default(CancellationToken)) where TModel : ModelBase { var endpoint = _endpointResolver.WithSearchAfter <TModel>(100, cursor); _logger.Debug($"Filtering resource '{typeof(TModel).Name}' from URL '{endpoint}' with query '{queryString}'."); var response = await GetAsync($"{endpoint}{queryString}", ct); if (!response.IsSuccessStatusCode) { throw new HttpRequestException($"Error while executing GET reques: {endpoint}{queryString}"); } PaginationResult <TModel> paginationResult = await response.Content.ReadAsJsonAsync <PaginationResult <TModel> >(); paginationResult.Code = response.StatusCode; List <TModel> items = paginationResult.GetItems(); var nextCursor = paginationResult.Links.GetCursor(); if (nextCursor != null) { var nextItems = await FilterAndGetAllAsync <TModel>(queryString, nextCursor, ct); items.AddRange(nextItems); } return(items); }
public async Task <List <TModel> > GetAllAsync <TModel>(string cursor = null, CancellationToken ct = default(CancellationToken)) where TModel : ModelBase { var endpoint = _endpointResolver.WithSearchAfter <TModel>(100, cursor); _logger.Debug($"Getting multiple resource '{typeof(TModel).Name}' from URL '{endpoint}'."); var response = await GetAsync(endpoint, ct); if (!response.IsSuccessStatusCode) { return(new List <TModel>()); } PaginationResult <TModel> paginationResult = await response.Content.ReadAsJsonAsync <PaginationResult <TModel> >(); var items = paginationResult.GetItems(); var nextCursor = paginationResult.Links.GetCursor(); if (nextCursor != null) { var nextItems = await GetAllAsync <TModel>(nextCursor, ct); items.AddRange(nextItems); } return(items); }