Skip to content

Commit 6ce48d1

Browse files
author
mvgreen
committed
Introduce UpdatedAttributeValue interface
1 parent 1377804 commit 6ce48d1

3 files changed

Lines changed: 44 additions & 14 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.ecwid.apiclient.v3.dto.common
2+
3+
import com.ecwid.apiclient.v3.dto.product.enums.AttributeValueAlias
4+
5+
interface UpdatedAttributeValue {
6+
val id: Int?
7+
val alias: AttributeValueAlias?
8+
val name: String?
9+
val value: String?
10+
}

src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/UpdatedProduct.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.ecwid.apiclient.v3.dto.product.request
22

3-
import com.ecwid.apiclient.v3.dto.common.NullableUpdatedValue
4-
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO
3+
import com.ecwid.apiclient.v3.dto.common.*
54
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO.ModifyKind
6-
import com.ecwid.apiclient.v3.dto.common.LocalizedValueMap
7-
import com.ecwid.apiclient.v3.dto.common.ProductCondition
85
import com.ecwid.apiclient.v3.dto.product.enums.*
96
import com.ecwid.apiclient.v3.dto.product.result.FetchedProduct
107

@@ -276,11 +273,21 @@ data class UpdatedProduct(
276273
)
277274

278275
data class AttributeValue internal constructor(
279-
val id: Int? = null,
280-
val alias: AttributeValueAlias? = null,
281-
val name: String? = null,
282-
val value: String? = null
283-
) {
276+
override val id: Int? = null,
277+
override val alias: AttributeValueAlias? = null,
278+
override val name: String? = null,
279+
override val value: String? = null
280+
): UpdatedAttributeValue {
281+
282+
fun UpdatedAttributeValue.ofProduct() =
283+
AttributeValue(
284+
id = id,
285+
alias = alias,
286+
name = name,
287+
value = value
288+
)
289+
290+
fun Collection<UpdatedAttributeValue>.ofProduct() = this.map { it.ofProduct() }
284291

285292
companion object {
286293

src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/request/UpdatedVariation.kt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.ecwid.apiclient.v3.dto.variation.request
22

33
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO
44
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO.ModifyKind
5+
import com.ecwid.apiclient.v3.dto.common.UpdatedAttributeValue
56
import com.ecwid.apiclient.v3.dto.product.enums.AttributeValueAlias
67
import com.ecwid.apiclient.v3.dto.product.enums.OutOfStockVisibilityBehaviour
78
import com.ecwid.apiclient.v3.dto.variation.result.FetchedVariation
@@ -34,11 +35,23 @@ data class UpdatedVariation(
3435
) : ApiUpdatedDTO {
3536

3637
data class AttributeValue(
37-
val id: Int? = null,
38-
val alias: AttributeValueAlias? = null,
39-
val name: String? = null,
40-
val value: String? = null
41-
)
38+
override val id: Int? = null,
39+
override val alias: AttributeValueAlias? = null,
40+
override val name: String? = null,
41+
override val value: String? = null
42+
) : UpdatedAttributeValue {
43+
44+
fun UpdatedAttributeValue.ofVariation() =
45+
AttributeValue(
46+
id = id,
47+
alias = alias,
48+
name = name,
49+
value = value
50+
)
51+
52+
fun Collection<UpdatedAttributeValue>.ofVariation() = this.map { it.ofVariation() }
53+
54+
}
4255

4356
data class WholesalePrice(
4457
val quantity: Int = 0,

0 commit comments

Comments
 (0)