Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit cc6b2f8

Browse files
authored
Merge pull request #3064 from wordpress-mobile/issue/11794-fetch-single-order-sync
Fetch single order sync
2 parents 94d25d3 + 0ce4d95 commit cc6b2f8

File tree

1 file changed

+21
-2
lines changed
  • plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store

1 file changed

+21
-2
lines changed

plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCOrderStore.kt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,19 @@ class WCOrderStore @Inject constructor(
603603
}
604604
}
605605

606+
suspend fun fetchSingleOrderSync(site: SiteModel, remoteOrderId: Long): WooResult<OrderEntity> {
607+
return coroutineEngine.withDefaultContext(API, this, "fetchSingleOrderSync") {
608+
val result = wcOrderRestClient.fetchSingleOrder(site, remoteOrderId)
609+
610+
return@withDefaultContext if (result.isError) {
611+
WooResult(WooError(API_ERROR, SERVER_ERROR, result.error.message))
612+
} else {
613+
insertOrder(site.localId(), result.orderWithMeta)
614+
WooResult(result.order)
615+
}
616+
}
617+
}
618+
606619
@Suppress("SpreadOperator")
607620
suspend fun fetchOrders(
608621
site: SiteModel,
@@ -1094,7 +1107,10 @@ class WCOrderStore @Inject constructor(
10941107
return deleteOptions
10951108
}
10961109

1097-
suspend fun fetchOrdersListFirstPage(listDescriptor: WCOrderListDescriptor): WooResult<List<OrderEntity>> {
1110+
suspend fun fetchOrdersListFirstPage(
1111+
listDescriptor: WCOrderListDescriptor,
1112+
deleteOldData: Boolean = false
1113+
): WooResult<List<OrderEntity>> {
10981114
val response = wcOrderRestClient.fetchOrdersListFirstPage(listDescriptor)
10991115
return if (response.isError) {
11001116
WooResult(WooError(API_ERROR, SERVER_ERROR, response.error.message))
@@ -1113,7 +1129,10 @@ class WCOrderStore @Inject constructor(
11131129
OrderSqlUtils.insertOrUpdateOrderSummaries(orderSummaries)
11141130
}
11151131

1116-
ordersDaoDecorator.deleteOrdersForSite(listDescriptor.site.localId())
1132+
if (deleteOldData) {
1133+
ordersDaoDecorator.deleteOrdersForSite(listDescriptor.site.localId())
1134+
}
1135+
11171136
@Suppress("SpreadOperator")
11181137
insertOrder(listDescriptor.site.localId(), *result.toTypedArray())
11191138
WooResult(orders)

0 commit comments

Comments
 (0)