Skip to content

Commit

Permalink
Merge pull request #2850 from wordpress-mobile/issue/add-pagination-s…
Browse files Browse the repository at this point in the history
…upport-to-attribute-list-fetching

HACK Week: Add pagination support to attribute list fetching
  • Loading branch information
ThomazFB authored Sep 14, 2023
2 parents f8f31bf + a31696c commit 9f10cf5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Array<AttributeTermApiResponse>>(
site = site,
params = mapOf("per_page" to pageSize.toString())
params = mapOf(
"page" to page.toString(),
"per_page" to pageSize.toString()
)
)

suspend fun postNewTerm(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ class WCGlobalAttributeStore @Inject constructor(
suspend fun fetchAttributeTerms(
site: SiteModel,
attributeID: Long,
pageSize: Int = 100
) = restClient.fetchAllAttributeTerms(site, attributeID, pageSize)
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 {
insertAttributeTermsFromScratch(attributeID.toInt(), site.id, this)
Expand Down Expand Up @@ -193,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
}
}

0 comments on commit 9f10cf5

Please sign in to comment.