From 0a1a58ff2a880f40c05c6b7a2da5a1fd7e6d8967 Mon Sep 17 00:00:00 2001 From: Rossana <30724184+rossanafmenezes@users.noreply.github.com> Date: Fri, 20 Oct 2023 17:43:04 -0400 Subject: [PATCH] Add customerId to OrderEntity --- .../wordpress/android/fluxc/persistence/MigrationTests.kt | 8 ++++++++ .../org/wordpress/android/fluxc/model/OrderEntity.kt | 2 ++ .../android/fluxc/network/rest/wpcom/wc/order/OrderDto.kt | 1 + .../fluxc/network/rest/wpcom/wc/order/OrderDtoMapper.kt | 1 + .../android/fluxc/persistence/WCAndroidDatabase.kt | 3 ++- 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce/src/androidTest/java/org/wordpress/android/fluxc/persistence/MigrationTests.kt b/plugins/woocommerce/src/androidTest/java/org/wordpress/android/fluxc/persistence/MigrationTests.kt index 27163d8b49..6206092aa9 100644 --- a/plugins/woocommerce/src/androidTest/java/org/wordpress/android/fluxc/persistence/MigrationTests.kt +++ b/plugins/woocommerce/src/androidTest/java/org/wordpress/android/fluxc/persistence/MigrationTests.kt @@ -244,6 +244,14 @@ class MigrationTests { } } + @Test + fun testMigration28to29() { + helper.apply { + createDatabase(TEST_DB, 28).close() + runMigrationsAndValidate(TEST_DB, 29, false) + } + } + companion object { private const val TEST_DB = "migration-test" } diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/model/OrderEntity.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/model/OrderEntity.kt index 6ef7ed19f0..a28a1a2735 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/model/OrderEntity.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/model/OrderEntity.kt @@ -42,6 +42,8 @@ data class OrderEntity( val discountTotal: String = "", val discountCodes: String = "", val refundTotal: BigDecimal = BigDecimal.ZERO, // The total refund value for this order (usually a negative number) + @ColumnInfo(name = "customerId", defaultValue = "0") + val customerId: Long = 0, val billingFirstName: String = "", val billingLastName: String = "", val billingCompany: String = "", diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/order/OrderDto.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/order/OrderDto.kt index df19b30414..63091056f3 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/order/OrderDto.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/order/OrderDto.kt @@ -39,6 +39,7 @@ class OrderDto : Response { val total: String? = null } + val customer_id: Long? = null val billing: Billing? = null val coupon_lines: List? = null val currency: String? = null diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/order/OrderDtoMapper.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/order/OrderDtoMapper.kt index 16a9d67f71..cfe2ab1de2 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/order/OrderDtoMapper.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/order/OrderDtoMapper.kt @@ -49,6 +49,7 @@ class OrderDtoMapper @Inject internal constructor( // store their sum as a 'Double'. refunds.sumOf { it.total?.toBigDecimalOrNull() ?: BigDecimal.ZERO } } ?: BigDecimal.ZERO, + customerId = this.customer_id ?: 0, billingFirstName = this.billing?.first_name ?: "", billingLastName = this.billing?.last_name ?: "", billingCompany = this.billing?.company ?: "", diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/persistence/WCAndroidDatabase.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/persistence/WCAndroidDatabase.kt index 322ee671fa..71f50cb4a4 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/persistence/WCAndroidDatabase.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/persistence/WCAndroidDatabase.kt @@ -57,7 +57,7 @@ import org.wordpress.android.fluxc.persistence.migrations.MIGRATION_8_9 import org.wordpress.android.fluxc.persistence.migrations.MIGRATION_9_10 @Database( - version = 28, + version = 29, entities = [ AddonEntity::class, AddonOptionEntity::class, @@ -84,6 +84,7 @@ import org.wordpress.android.fluxc.persistence.migrations.MIGRATION_9_10 AutoMigration(from = 23, to = 24, spec = AutoMigration23to24::class), AutoMigration(from = 25, to = 26), AutoMigration(from = 26, to = 27), + AutoMigration(from = 28, to = 29), ] ) @TypeConverters(