From 6ce48d162af38753375b2639989021c9b3d4b327 Mon Sep 17 00:00:00 2001 From: mvgreen Date: Mon, 12 Sep 2022 18:25:57 +0400 Subject: [PATCH 1/7] Introduce UpdatedAttributeValue interface --- .../v3/dto/common/UpdatedAttributeValue.kt | 10 ++++++++ .../v3/dto/product/request/UpdatedProduct.kt | 25 ++++++++++++------- .../dto/variation/request/UpdatedVariation.kt | 23 +++++++++++++---- 3 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 src/main/kotlin/com/ecwid/apiclient/v3/dto/common/UpdatedAttributeValue.kt diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/common/UpdatedAttributeValue.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/common/UpdatedAttributeValue.kt new file mode 100644 index 000000000..5ace07feb --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/common/UpdatedAttributeValue.kt @@ -0,0 +1,10 @@ +package com.ecwid.apiclient.v3.dto.common + +import com.ecwid.apiclient.v3.dto.product.enums.AttributeValueAlias + +interface UpdatedAttributeValue { + val id: Int? + val alias: AttributeValueAlias? + val name: String? + val value: String? +} diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/UpdatedProduct.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/UpdatedProduct.kt index cac75c649..2297bff23 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/UpdatedProduct.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/UpdatedProduct.kt @@ -1,10 +1,7 @@ package com.ecwid.apiclient.v3.dto.product.request -import com.ecwid.apiclient.v3.dto.common.NullableUpdatedValue -import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO +import com.ecwid.apiclient.v3.dto.common.* import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO.ModifyKind -import com.ecwid.apiclient.v3.dto.common.LocalizedValueMap -import com.ecwid.apiclient.v3.dto.common.ProductCondition import com.ecwid.apiclient.v3.dto.product.enums.* import com.ecwid.apiclient.v3.dto.product.result.FetchedProduct @@ -276,11 +273,21 @@ data class UpdatedProduct( ) data class AttributeValue internal constructor( - val id: Int? = null, - val alias: AttributeValueAlias? = null, - val name: String? = null, - val value: String? = null - ) { + override val id: Int? = null, + override val alias: AttributeValueAlias? = null, + override val name: String? = null, + override val value: String? = null + ): UpdatedAttributeValue { + + fun UpdatedAttributeValue.ofProduct() = + AttributeValue( + id = id, + alias = alias, + name = name, + value = value + ) + + fun Collection.ofProduct() = this.map { it.ofProduct() } companion object { diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/request/UpdatedVariation.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/request/UpdatedVariation.kt index 367b40bc0..f77f151ac 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/request/UpdatedVariation.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/request/UpdatedVariation.kt @@ -2,6 +2,7 @@ package com.ecwid.apiclient.v3.dto.variation.request import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO.ModifyKind +import com.ecwid.apiclient.v3.dto.common.UpdatedAttributeValue import com.ecwid.apiclient.v3.dto.product.enums.AttributeValueAlias import com.ecwid.apiclient.v3.dto.product.enums.OutOfStockVisibilityBehaviour import com.ecwid.apiclient.v3.dto.variation.result.FetchedVariation @@ -34,11 +35,23 @@ data class UpdatedVariation( ) : ApiUpdatedDTO { data class AttributeValue( - val id: Int? = null, - val alias: AttributeValueAlias? = null, - val name: String? = null, - val value: String? = null - ) + override val id: Int? = null, + override val alias: AttributeValueAlias? = null, + override val name: String? = null, + override val value: String? = null + ) : UpdatedAttributeValue { + + fun UpdatedAttributeValue.ofVariation() = + AttributeValue( + id = id, + alias = alias, + name = name, + value = value + ) + + fun Collection.ofVariation() = this.map { it.ofVariation() } + + } data class WholesalePrice( val quantity: Int = 0, From 2f41f01e90843cfbc1ea3c8640ce0996fa6f98d9 Mon Sep 17 00:00:00 2001 From: mvgreen Date: Tue, 13 Sep 2022 13:13:15 +0400 Subject: [PATCH 2/7] Introduce FetchedAttributeValue interface --- .../v3/dto/common/FetchedAttributeValue.kt | 12 ++++++++ .../v3/dto/custom/CustomAppRequest.kt | 20 +++++++++---- .../v3/dto/product/result/FetchedProduct.kt | 30 ++++++++++++------- .../dto/variation/result/FetchedVariation.kt | 26 ++++++++++++---- 4 files changed, 67 insertions(+), 21 deletions(-) create mode 100644 src/main/kotlin/com/ecwid/apiclient/v3/dto/common/FetchedAttributeValue.kt diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/common/FetchedAttributeValue.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/common/FetchedAttributeValue.kt new file mode 100644 index 000000000..a3d2c6bfa --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/common/FetchedAttributeValue.kt @@ -0,0 +1,12 @@ +package com.ecwid.apiclient.v3.dto.common + +import com.ecwid.apiclient.v3.dto.product.enums.AttributeValueLocation +import com.ecwid.apiclient.v3.dto.producttype.enums.AttributeType + +interface FetchedAttributeValue { + val id: Int? + val name: String? + val type: AttributeType? + val value: String? + val show: AttributeValueLocation? +} diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt index 455a248b4..6adf7d3e4 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt @@ -1,10 +1,7 @@ package com.ecwid.apiclient.v3.dto.custom import com.ecwid.apiclient.v3.dto.cart.result.FetchedCart -import com.ecwid.apiclient.v3.dto.common.ApiRequestDTO -import com.ecwid.apiclient.v3.dto.common.OrderedStringToListStringMap -import com.ecwid.apiclient.v3.dto.common.OrderedStringToStringMap -import com.ecwid.apiclient.v3.dto.common.PictureInfo +import com.ecwid.apiclient.v3.dto.common.* import com.ecwid.apiclient.v3.dto.order.enums.* import com.ecwid.apiclient.v3.dto.product.enums.AttributeValueLocation import com.ecwid.apiclient.v3.dto.producttype.enums.AttributeType @@ -282,7 +279,20 @@ data class CustomAppRequest( val type: AttributeType? = null, val value: String? = null, val show: AttributeValueLocation? = null - ) + ) { + + fun FetchedAttributeValue.ofOrder() = + AttributeValue( + id = id, + name = name, + type = type, + value = value, + show = show + ) + + fun Collection.ofOrder() = this.map { it.ofOrder() } + + } data class ProductDimensions( val length: Double? = null, diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt index 9238c7262..281acec6e 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt @@ -1,10 +1,7 @@ package com.ecwid.apiclient.v3.dto.product.result -import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO +import com.ecwid.apiclient.v3.dto.common.* import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO.ModifyKind -import com.ecwid.apiclient.v3.dto.common.LocalizedValueMap -import com.ecwid.apiclient.v3.dto.common.PictureInfo -import com.ecwid.apiclient.v3.dto.common.ProductCondition import com.ecwid.apiclient.v3.dto.product.enums.* import com.ecwid.apiclient.v3.dto.product.request.UpdatedProduct import com.ecwid.apiclient.v3.dto.producttype.enums.AttributeType @@ -238,12 +235,25 @@ data class FetchedProduct( ) data class AttributeValue( - val id: Int? = null, - val name: String? = null, - val type: AttributeType? = null, - val value: String? = null, - val show: AttributeValueLocation? = null - ) + override val id: Int? = null, + override val name: String? = null, + override val type: AttributeType? = null, + override val value: String? = null, + override val show: AttributeValueLocation? = null + ): FetchedAttributeValue { + + fun FetchedAttributeValue.ofProduct() = + AttributeValue( + id = id, + name = name, + type = type, + value = value, + show = show + ) + + fun Collection.ofProduct() = this.map { it.ofProduct() } + + } data class RelatedProducts( val productIds: List? = null, diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt index d19b93758..59238fe40 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt @@ -2,6 +2,7 @@ package com.ecwid.apiclient.v3.dto.variation.result import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO.ModifyKind +import com.ecwid.apiclient.v3.dto.common.FetchedAttributeValue import com.ecwid.apiclient.v3.dto.common.LocalizedValueMap import com.ecwid.apiclient.v3.dto.product.enums.AttributeValueLocation import com.ecwid.apiclient.v3.dto.product.enums.OutOfStockVisibilityBehaviour @@ -49,12 +50,25 @@ data class FetchedVariation( ) : ApiFetchedDTO { data class AttributeValue( - val id: Int? = null, - val name: String? = null, - val type: AttributeType? = null, - val value: String? = null, - val show: AttributeValueLocation? = null - ) + override val id: Int? = null, + override val name: String? = null, + override val type: AttributeType? = null, + override val value: String? = null, + override val show: AttributeValueLocation? = null + ): FetchedAttributeValue { + + fun FetchedAttributeValue.ofVariation() = + AttributeValue( + id = id, + name = name, + type = type, + value = value, + show = show + ) + + fun Collection.ofVariation() = this.map { it.ofVariation() } + + } data class WholesalePrice( val quantity: Int = 0, From 3f258346c987224613d7f15f56a1a9b001f2c5b1 Mon Sep 17 00:00:00 2001 From: mvgreen Date: Tue, 13 Sep 2022 13:20:17 +0400 Subject: [PATCH 3/7] Fix codestyle issues --- .../ecwid/apiclient/v3/dto/product/request/UpdatedProduct.kt | 2 +- .../com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/UpdatedProduct.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/UpdatedProduct.kt index 2297bff23..76591909e 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/UpdatedProduct.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/UpdatedProduct.kt @@ -277,7 +277,7 @@ data class UpdatedProduct( override val alias: AttributeValueAlias? = null, override val name: String? = null, override val value: String? = null - ): UpdatedAttributeValue { + ) : UpdatedAttributeValue { fun UpdatedAttributeValue.ofProduct() = AttributeValue( diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt index 281acec6e..1094532ec 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt @@ -240,7 +240,7 @@ data class FetchedProduct( override val type: AttributeType? = null, override val value: String? = null, override val show: AttributeValueLocation? = null - ): FetchedAttributeValue { + ) : FetchedAttributeValue { fun FetchedAttributeValue.ofProduct() = AttributeValue( From 45ed2fc2527a3e3cc32eba0ec78ba3de9b22f104 Mon Sep 17 00:00:00 2001 From: mvgreen Date: Tue, 13 Sep 2022 13:25:46 +0400 Subject: [PATCH 4/7] Fix codestyle issue in FetchedVariation --- .../ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt index 59238fe40..a730aa19d 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt @@ -55,7 +55,7 @@ data class FetchedVariation( override val type: AttributeType? = null, override val value: String? = null, override val show: AttributeValueLocation? = null - ): FetchedAttributeValue { + ) : FetchedAttributeValue { fun FetchedAttributeValue.ofVariation() = AttributeValue( From da3f65206eb7a4925ea7331060adad2eade884d5 Mon Sep 17 00:00:00 2001 From: mvgreen Date: Thu, 15 Sep 2022 14:18:47 +0400 Subject: [PATCH 5/7] Remove redundant utility extensions --- .../v3/dto/custom/CustomAppRequest.kt | 25 ++++++------------- .../v3/dto/product/request/UpdatedProduct.kt | 10 +------- .../v3/dto/product/result/FetchedProduct.kt | 11 +------- .../dto/variation/request/UpdatedVariation.kt | 10 +------- .../dto/variation/result/FetchedVariation.kt | 11 +------- 5 files changed, 12 insertions(+), 55 deletions(-) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt index 6adf7d3e4..c0b20b9d3 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt @@ -274,23 +274,14 @@ data class CustomAppRequest( ) data class AttributeValue( - val id: Int? = null, - val name: String? = null, - val type: AttributeType? = null, - val value: String? = null, - val show: AttributeValueLocation? = null - ) { - - fun FetchedAttributeValue.ofOrder() = - AttributeValue( - id = id, - name = name, - type = type, - value = value, - show = show - ) - - fun Collection.ofOrder() = this.map { it.ofOrder() } + override val id: Int? = null, + override val name: String? = null, + override val type: AttributeType? = null, + override val value: String? = null, + override val show: AttributeValueLocation? = null + ): FetchedAttributeValue { + + fun Collection.otOrderAttributeList() = this.map { it as AttributeValue} } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/UpdatedProduct.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/UpdatedProduct.kt index 76591909e..ec1e5674e 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/UpdatedProduct.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/UpdatedProduct.kt @@ -279,15 +279,7 @@ data class UpdatedProduct( override val value: String? = null ) : UpdatedAttributeValue { - fun UpdatedAttributeValue.ofProduct() = - AttributeValue( - id = id, - alias = alias, - name = name, - value = value - ) - - fun Collection.ofProduct() = this.map { it.ofProduct() } + fun Collection.toProductAttributeList() = this.map { it as AttributeValue } companion object { diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt index 1094532ec..603579593 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt @@ -242,16 +242,7 @@ data class FetchedProduct( override val show: AttributeValueLocation? = null ) : FetchedAttributeValue { - fun FetchedAttributeValue.ofProduct() = - AttributeValue( - id = id, - name = name, - type = type, - value = value, - show = show - ) - - fun Collection.ofProduct() = this.map { it.ofProduct() } + fun Collection.toProductAttributeList() = this.map { it as AttributeValue } } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/request/UpdatedVariation.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/request/UpdatedVariation.kt index f77f151ac..d7d486528 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/request/UpdatedVariation.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/request/UpdatedVariation.kt @@ -41,15 +41,7 @@ data class UpdatedVariation( override val value: String? = null ) : UpdatedAttributeValue { - fun UpdatedAttributeValue.ofVariation() = - AttributeValue( - id = id, - alias = alias, - name = name, - value = value - ) - - fun Collection.ofVariation() = this.map { it.ofVariation() } + fun Collection.toVariationAttributeList() = this.map { it as AttributeValue } } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt index a730aa19d..10563f255 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt @@ -57,16 +57,7 @@ data class FetchedVariation( override val show: AttributeValueLocation? = null ) : FetchedAttributeValue { - fun FetchedAttributeValue.ofVariation() = - AttributeValue( - id = id, - name = name, - type = type, - value = value, - show = show - ) - - fun Collection.ofVariation() = this.map { it.ofVariation() } + fun Collection.toVariationAttributeList() = this.map { it as AttributeValue } } From fcd03b146f33f4568a374a3e2b0ffdd58a409d6d Mon Sep 17 00:00:00 2001 From: mvgreen Date: Thu, 15 Sep 2022 14:25:24 +0400 Subject: [PATCH 6/7] Fix spacing in CustomAppRequest --- .../ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt index c0b20b9d3..7944923c2 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt @@ -223,7 +223,10 @@ data class CustomAppRequest( val applicationLimit: DiscountCouponApplicationLimit? = null, val creationDate: Date? = null, val orderCount: Int? = null, - @Deprecated("This field is added for backward compatibility only. Don't use it.", replaceWith = ReplaceWith("catalogLimit")) + @Deprecated( + "This field is added for backward compatibility only. Don't use it.", + replaceWith = ReplaceWith("catalogLimit") + ) val legacyCatalogLimit: DiscountCouponCatalogLimit? = null, val catalogLimit: DiscountCouponCatalogLimit? = null, val repeatCustomerOnly: Boolean? = null, @@ -279,9 +282,9 @@ data class CustomAppRequest( override val type: AttributeType? = null, override val value: String? = null, override val show: AttributeValueLocation? = null - ): FetchedAttributeValue { + ) : FetchedAttributeValue { - fun Collection.otOrderAttributeList() = this.map { it as AttributeValue} + fun Collection.otOrderAttributeList() = this.map { it as AttributeValue } } From fb378b806bf2135d1829d901037538748e03651f Mon Sep 17 00:00:00 2001 From: mvgreen Date: Thu, 15 Sep 2022 16:19:11 +0400 Subject: [PATCH 7/7] Fix typo --- .../com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt index 7944923c2..26cefedf1 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt @@ -284,7 +284,7 @@ data class CustomAppRequest( override val show: AttributeValueLocation? = null ) : FetchedAttributeValue { - fun Collection.otOrderAttributeList() = this.map { it as AttributeValue } + fun Collection.toOrderAttributeList() = this.map { it as AttributeValue } }