Skip to content

Commit

Permalink
Default limti to 1000 if pagination is not specified (#1125)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianwium authored Oct 21, 2024
1 parent e000ac0 commit 53bd6a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public async Task<StoreItemCategorySearchResults> SearchStoreItemCategories(Stor

public async Task<StoreSearchResults> SearchStores(StoreSearchFilter filter)
{
//TODO: Client side pagination provided categoryId is specified; not filtered on the server

ArgumentNullException.ThrowIfNull(filter, nameof(filter));

await _storeSearchFilterValidator.ValidateAndThrowAsync(filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class ZltoClient : IRewardProviderClient, IMarketplaceProviderClient
private const string Image_Default_Empty_Value = "default";

private static readonly HttpStatusCode[] StatusCode_WalletNotFound = [HttpStatusCode.NotFound, HttpStatusCode.Conflict];

private const int Limit_Default = 1000;
#endregion

#region Constructor
Expand Down Expand Up @@ -111,8 +113,8 @@ public ZltoClient(AppSettings appSettings, ZltoOptions options,
.SetQueryParam("wallet_id", walletId)
.WithAuthHeaders(await GetAuthHeaders());

if (limit.HasValue && limit.Value > default(int))
query = query.SetQueryParam("limit", limit);
var effectiveLimit = limit.HasValue && limit.Value > default(int) ? limit.Value : Limit_Default;
query = query.SetQueryParam("limit", effectiveLimit);

if (offset.HasValue && offset.Value >= default(int))
query = query.SetQueryParam("offset", offset);
Expand Down Expand Up @@ -242,8 +244,8 @@ public List<string> ListSupportedCountryCodesAlpha2(string? countryCodeAlpha2)
.SetQueryParam("item_state", (int)StoreItemCategoryState.Active)
.WithAuthHeaders(await GetAuthHeaders());

if (limit.HasValue && limit.Value > default(int))
query = query.SetQueryParam("limit", limit);
var effectiveLimit = limit.HasValue && limit.Value > default(int) ? limit.Value : Limit_Default;
query = query.SetQueryParam("limit", effectiveLimit);

if (offset.HasValue && offset.Value >= default(int))
query = query.SetQueryParam("offset", offset);
Expand Down Expand Up @@ -287,8 +289,8 @@ public List<string> ListSupportedCountryCodesAlpha2(string? countryCodeAlpha2)
.SetQueryParam("item_state", (int)StoreItemState.Available)
.WithAuthHeaders(await GetAuthHeaders());

if (limit.HasValue && limit.Value > default(int))
query = query.SetQueryParam("limit", limit);
var effectiveLimit = limit.HasValue && limit.Value > default(int) ? limit.Value : Limit_Default;
query = query.SetQueryParam("limit", effectiveLimit);

if (offset.HasValue && offset.Value >= default(int))
query = query.SetQueryParam("offset", offset);
Expand Down Expand Up @@ -496,9 +498,23 @@ private async Task<WalletAccountInfo> CreateAccount(Domain.Reward.Models.Provide

private async Task<List<Domain.Marketplace.Models.StoreCategory>> ListStoreCategoriesInternal(string CountryCodeAlpha2)
{
var resultSearch = await ListStoresInternal(CountryCodeAlpha2, null, null, null);
int offset = 0;
var items = new List<Models.StoreInfo>();

StoreResponseSearch? resultSearch;
do
{
resultSearch = await ListStoresInternal(CountryCodeAlpha2, null, Limit_Default, offset);

if (resultSearch?.Items == null || resultSearch.Items.Count == 0)
break;

items.AddRange(resultSearch.Items);
offset += Limit_Default;
}
while (resultSearch?.Items?.Count == Limit_Default);

var results = resultSearch?.Items
var results = items
?.GroupBy(store => store.Category.Id)
.Select(group =>
{
Expand All @@ -509,7 +525,7 @@ private async Task<WalletAccountInfo> CreateAccount(Domain.Reward.Models.Provide
{
Id = firstItem.Category.Id,
Name = firstItem.Category.CategoryName,
StoreImageURLs = resultSearch?.Items
StoreImageURLs = items
.Where(o => o.Category.Id == firstItem.Category.Id && o.StoreLogo != null && !string.Equals(o.StoreLogo, Image_Default_Empty_Value, StringComparison.InvariantCultureIgnoreCase))
.OrderBy(o => o.StoreName)
.Select(o => o.StoreLogo)
Expand Down Expand Up @@ -553,8 +569,8 @@ private async Task<StoreResponseSearch> ListStoresInternal(string countryCodeAlp

query = query.SetQueryParam("country_owner_id", countryOwnerId);

if (limit.HasValue && limit.Value > default(int))
query = query.SetQueryParam("limit", limit);
var effectiveLimit = limit.HasValue && limit.Value > default(int) ? limit.Value : Limit_Default;
query = query.SetQueryParam("limit", effectiveLimit);

if (offset.HasValue && offset.Value >= default(int))
query = query.SetQueryParam("offset", offset);
Expand Down

0 comments on commit 53bd6a4

Please sign in to comment.