From 53bd6a4bff0f62faf0118cfaf3e060c8539b48d1 Mon Sep 17 00:00:00 2001 From: adrianwium <82496337+adrianwium@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:33:53 +0200 Subject: [PATCH] Default limti to 1000 if pagination is not specified (#1125) --- .../Services/MarketPlaceService.cs | 2 + .../Client/ZltoClient.cs | 38 +++++++++++++------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/api/src/domain/Yoma.Core.Domain/Marketplace/Services/MarketPlaceService.cs b/src/api/src/domain/Yoma.Core.Domain/Marketplace/Services/MarketPlaceService.cs index 7e93f2315..929698862 100644 --- a/src/api/src/domain/Yoma.Core.Domain/Marketplace/Services/MarketPlaceService.cs +++ b/src/api/src/domain/Yoma.Core.Domain/Marketplace/Services/MarketPlaceService.cs @@ -137,6 +137,8 @@ public async Task SearchStoreItemCategories(Stor public async Task 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); diff --git a/src/api/src/infrastructure/Yoma.Core.Infrastructure.Zlto/Client/ZltoClient.cs b/src/api/src/infrastructure/Yoma.Core.Infrastructure.Zlto/Client/ZltoClient.cs index 08d301f58..6c02a0813 100644 --- a/src/api/src/infrastructure/Yoma.Core.Infrastructure.Zlto/Client/ZltoClient.cs +++ b/src/api/src/infrastructure/Yoma.Core.Infrastructure.Zlto/Client/ZltoClient.cs @@ -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 @@ -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); @@ -242,8 +244,8 @@ public List 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); @@ -287,8 +289,8 @@ public List 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); @@ -496,9 +498,23 @@ private async Task CreateAccount(Domain.Reward.Models.Provide private async Task> ListStoreCategoriesInternal(string CountryCodeAlpha2) { - var resultSearch = await ListStoresInternal(CountryCodeAlpha2, null, null, null); + int offset = 0; + var items = new List(); + + 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 => { @@ -509,7 +525,7 @@ private async Task 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) @@ -553,8 +569,8 @@ private async Task 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);