From d58b1d8d3f898c7b07b959836901f9a61869f9c6 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 7 Sep 2023 10:55:36 -0300 Subject: [PATCH 1/3] Add page parameter to Attribute list fetching --- .../wc/product/attributes/ProductAttributeRestClient.kt | 6 +++++- .../wordpress/android/fluxc/store/WCGlobalAttributeStore.kt | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/attributes/ProductAttributeRestClient.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/attributes/ProductAttributeRestClient.kt index e33b8767f9..38bb3f3d48 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/attributes/ProductAttributeRestClient.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/attributes/ProductAttributeRestClient.kt @@ -43,11 +43,15 @@ class ProductAttributeRestClient @Inject constructor(private val wooNetwork: Woo suspend fun fetchAllAttributeTerms( site: SiteModel, attributeID: Long, + page: Int, pageSize: Int ) = WOOCOMMERCE.products.attributes.attribute(attributeID).terms.pathV3 .request>( site = site, - params = mapOf("per_page" to pageSize.toString()) + params = mapOf( + "page" to page.toString(), + "per_page" to pageSize.toString() + ) ) suspend fun postNewTerm( diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCGlobalAttributeStore.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCGlobalAttributeStore.kt index 0359c89022..2a9718ea42 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCGlobalAttributeStore.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCGlobalAttributeStore.kt @@ -55,8 +55,9 @@ class WCGlobalAttributeStore @Inject constructor( suspend fun fetchAttributeTerms( site: SiteModel, attributeID: Long, + page: Int, pageSize: Int = 100 - ) = restClient.fetchAllAttributeTerms(site, attributeID, pageSize) + ) = restClient.fetchAllAttributeTerms(site, attributeID, page, pageSize) .result?.map { mapper.responseToAttributeTermModel(it, attributeID.toInt(), site) } ?.apply { insertAttributeTermsFromScratch(attributeID.toInt(), site.id, this) From f530c2e55998f409eef286b4ea50741d090045b1 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 7 Sep 2023 11:47:54 -0300 Subject: [PATCH 2/3] Adjust WCGlobalAttributeStore.fetchAttributeTerms to also use default value for page --- .../org/wordpress/android/fluxc/store/WCGlobalAttributeStore.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCGlobalAttributeStore.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCGlobalAttributeStore.kt index 2a9718ea42..2a91e4223d 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCGlobalAttributeStore.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCGlobalAttributeStore.kt @@ -55,7 +55,7 @@ class WCGlobalAttributeStore @Inject constructor( suspend fun fetchAttributeTerms( site: SiteModel, attributeID: Long, - page: Int, + page: Int = 1, pageSize: Int = 100 ) = restClient.fetchAllAttributeTerms(site, attributeID, page, pageSize) .result?.map { mapper.responseToAttributeTermModel(it, attributeID.toInt(), site) } From a31696c3f0e1431b31e4522d9663d0db0b01cabb Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 14 Sep 2023 11:36:05 -0400 Subject: [PATCH 3/3] Replace page parameter default literals with constants --- .../android/fluxc/store/WCGlobalAttributeStore.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCGlobalAttributeStore.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCGlobalAttributeStore.kt index 2a91e4223d..d6390b6526 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCGlobalAttributeStore.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCGlobalAttributeStore.kt @@ -55,8 +55,8 @@ class WCGlobalAttributeStore @Inject constructor( suspend fun fetchAttributeTerms( site: SiteModel, attributeID: Long, - page: Int = 1, - pageSize: Int = 100 + page: Int = DEFAULT_PAGE_INDEX, + pageSize: Int = DEFAULT_PAGE_SIZE ) = restClient.fetchAllAttributeTerms(site, attributeID, page, pageSize) .result?.map { mapper.responseToAttributeTermModel(it, attributeID.toInt(), site) } ?.apply { @@ -194,4 +194,9 @@ class WCGlobalAttributeStore @Inject constructor( .model ?.let { updateSingleAttributeTermsMapping(attributeID.toInt(), termsId, site.id) } } + + companion object { + const val DEFAULT_PAGE_SIZE = 100 + const val DEFAULT_PAGE_INDEX = 1 + } }