From 343895b173e8d72315597b801053f02d6dff590b Mon Sep 17 00:00:00 2001 From: winrok Date: Tue, 5 Sep 2023 21:22:16 +0400 Subject: [PATCH] ECWID-126129 New Customers: SDK improvements: refactoring fields for Customers Request --- .../customer/request/CustomersIdsRequest.kt | 14 ++--------- .../request/CustomersMassUpdateRequest.kt | 14 ++--------- .../request/CustomersRequestFields.kt | 17 +++++++++++++ .../CustomersIdsRequestRules.kt | 25 ++++++++++--------- .../CustomersMassUpdateRequestRules.kt | 25 +++++++++---------- 5 files changed, 46 insertions(+), 49 deletions(-) create mode 100644 src/main/kotlin/com/ecwid/apiclient/v3/dto/customer/request/CustomersRequestFields.kt diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/customer/request/CustomersIdsRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/customer/request/CustomersIdsRequest.kt index 9d958b7e..072775ea 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/customer/request/CustomersIdsRequest.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/customer/request/CustomersIdsRequest.kt @@ -5,17 +5,7 @@ import com.ecwid.apiclient.v3.impl.RequestInfo import com.ecwid.apiclient.v3.responsefields.ResponseFields data class CustomersIdsRequest( - val keyword: String? = null, - val minOrderCount: Int? = null, - val maxOrderCount: Int? = null, - val minSalesValue: Int? = null, - val maxSalesValue: Int? = null, - val taxExempt: Boolean? = null, - val acceptMarketing: Boolean? = null, - val purchasedProductIds: String? = null, - val customerGroupIds: String? = null, - val countryCodes: String? = null, - val lang: String? = null, + val requestFields: CustomersRequestFields = CustomersRequestFields(), val responseFields: ResponseFields = ResponseFields.All, ) : ApiRequest { override fun toRequestInfo() = RequestInfo.createGetRequest( @@ -27,7 +17,7 @@ data class CustomersIdsRequest( ) private fun toParams(): Map { - val request = this + val request = this.requestFields return mutableMapOf().apply { request.keyword?.let { put("keyword", it) } request.minOrderCount?.let { put("minOrderCount", it.toString()) } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/customer/request/CustomersMassUpdateRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/customer/request/CustomersMassUpdateRequest.kt index 497a1b71..45621eb6 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/customer/request/CustomersMassUpdateRequest.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/customer/request/CustomersMassUpdateRequest.kt @@ -5,17 +5,7 @@ import com.ecwid.apiclient.v3.httptransport.HttpBody import com.ecwid.apiclient.v3.impl.RequestInfo data class CustomersMassUpdateRequest( - val keyword: String? = null, - val minOrderCount: Int? = null, - val maxOrderCount: Int? = null, - val minSalesValue: Int? = null, - val maxSalesValue: Int? = null, - val taxExempt: Boolean? = null, - val acceptMarketing: Boolean? = null, - val purchasedProductIds: String? = null, - val customerGroupIds: String? = null, - val countryCodes: String? = null, - val lang: String? = null, + val requestFields: CustomersRequestFields = CustomersRequestFields(), val customer: MassUpdateCustomer = MassUpdateCustomer() ) : ApiRequest { override fun toRequestInfo() = RequestInfo.createPostRequest( @@ -29,7 +19,7 @@ data class CustomersMassUpdateRequest( ) private fun toParams(): Map { - val request = this + val request = this.requestFields return mutableMapOf().apply { request.keyword?.let { put("keyword", it) } request.minOrderCount?.let { put("minOrderCount", it.toString()) } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/customer/request/CustomersRequestFields.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/customer/request/CustomersRequestFields.kt new file mode 100644 index 00000000..7cdfa2bd --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/customer/request/CustomersRequestFields.kt @@ -0,0 +1,17 @@ +package com.ecwid.apiclient.v3.dto.customer.request + +import com.ecwid.apiclient.v3.dto.common.ApiRequestDTO + +data class CustomersRequestFields( + val keyword: String? = null, + val minOrderCount: Int? = null, + val maxOrderCount: Int? = null, + val minSalesValue: Int? = null, + val maxSalesValue: Int? = null, + val taxExempt: Boolean? = null, + val acceptMarketing: Boolean? = null, + val purchasedProductIds: String? = null, + val customerGroupIds: String? = null, + val countryCodes: String? = null, + val lang: String? = null, +) : ApiRequestDTO diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/CustomersIdsRequestRules.kt b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/CustomersIdsRequestRules.kt index 6cd4932f..ac916aa9 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/CustomersIdsRequestRules.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/CustomersIdsRequestRules.kt @@ -1,18 +1,19 @@ package com.ecwid.apiclient.v3.rule.nullablepropertyrules -import com.ecwid.apiclient.v3.dto.customer.request.CustomersIdsRequest +import com.ecwid.apiclient.v3.dto.customer.request.CustomersRequestFields import com.ecwid.apiclient.v3.rule.NullablePropertyRule +import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable val customersIdsRequestNullablePropertyRules: List> = listOf( - NullablePropertyRule.AllowNullable(CustomersIdsRequest::keyword), - NullablePropertyRule.AllowNullable(CustomersIdsRequest::maxOrderCount), - NullablePropertyRule.AllowNullable(CustomersIdsRequest::minOrderCount), - NullablePropertyRule.AllowNullable(CustomersIdsRequest::maxSalesValue), - NullablePropertyRule.AllowNullable(CustomersIdsRequest::minSalesValue), - NullablePropertyRule.AllowNullable(CustomersIdsRequest::purchasedProductIds), - NullablePropertyRule.AllowNullable(CustomersIdsRequest::customerGroupIds), - NullablePropertyRule.AllowNullable(CustomersIdsRequest::countryCodes), - NullablePropertyRule.AllowNullable(CustomersIdsRequest::taxExempt), - NullablePropertyRule.AllowNullable(CustomersIdsRequest::acceptMarketing), - NullablePropertyRule.AllowNullable(CustomersIdsRequest::lang), + AllowNullable(CustomersRequestFields::keyword), + AllowNullable(CustomersRequestFields::maxOrderCount), + AllowNullable(CustomersRequestFields::minOrderCount), + AllowNullable(CustomersRequestFields::maxSalesValue), + AllowNullable(CustomersRequestFields::minSalesValue), + AllowNullable(CustomersRequestFields::purchasedProductIds), + AllowNullable(CustomersRequestFields::customerGroupIds), + AllowNullable(CustomersRequestFields::countryCodes), + AllowNullable(CustomersRequestFields::taxExempt), + AllowNullable(CustomersRequestFields::acceptMarketing), + AllowNullable(CustomersRequestFields::lang), ) diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/CustomersMassUpdateRequestRules.kt b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/CustomersMassUpdateRequestRules.kt index cc708d27..5213cca7 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/CustomersMassUpdateRequestRules.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/CustomersMassUpdateRequestRules.kt @@ -1,24 +1,23 @@ package com.ecwid.apiclient.v3.rule.nullablepropertyrules -import com.ecwid.apiclient.v3.dto.customer.request.CustomersMassUpdateRequest +import com.ecwid.apiclient.v3.dto.customer.request.CustomersRequestFields import com.ecwid.apiclient.v3.dto.customer.request.MassUpdateCustomer import com.ecwid.apiclient.v3.rule.NullablePropertyRule import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable val customersMassUpdatedRequestNullablePropertyRules: List> = listOf( - - AllowNullable(CustomersMassUpdateRequest::keyword), - AllowNullable(CustomersMassUpdateRequest::maxOrderCount), - AllowNullable(CustomersMassUpdateRequest::minOrderCount), - AllowNullable(CustomersMassUpdateRequest::maxSalesValue), - AllowNullable(CustomersMassUpdateRequest::minSalesValue), - AllowNullable(CustomersMassUpdateRequest::purchasedProductIds), - AllowNullable(CustomersMassUpdateRequest::customerGroupIds), - AllowNullable(CustomersMassUpdateRequest::countryCodes), - AllowNullable(CustomersMassUpdateRequest::taxExempt), - AllowNullable(CustomersMassUpdateRequest::acceptMarketing), - AllowNullable(CustomersMassUpdateRequest::lang), + AllowNullable(CustomersRequestFields::keyword), + AllowNullable(CustomersRequestFields::maxOrderCount), + AllowNullable(CustomersRequestFields::minOrderCount), + AllowNullable(CustomersRequestFields::maxSalesValue), + AllowNullable(CustomersRequestFields::minSalesValue), + AllowNullable(CustomersRequestFields::purchasedProductIds), + AllowNullable(CustomersRequestFields::customerGroupIds), + AllowNullable(CustomersRequestFields::countryCodes), + AllowNullable(CustomersRequestFields::taxExempt), + AllowNullable(CustomersRequestFields::acceptMarketing), + AllowNullable(CustomersRequestFields::lang), AllowNullable(MassUpdateCustomer::ids), AllowNullable(MassUpdateCustomer::delete),