Skip to content

Commit 2f41f01

Browse files
author
mvgreen
committed
Introduce FetchedAttributeValue interface
1 parent 6ce48d1 commit 2f41f01

4 files changed

Lines changed: 67 additions & 21 deletions

File tree

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

src/main/kotlin/com/ecwid/apiclient/v3/dto/custom/CustomAppRequest.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.ecwid.apiclient.v3.dto.custom
22

33
import com.ecwid.apiclient.v3.dto.cart.result.FetchedCart
4-
import com.ecwid.apiclient.v3.dto.common.ApiRequestDTO
5-
import com.ecwid.apiclient.v3.dto.common.OrderedStringToListStringMap
6-
import com.ecwid.apiclient.v3.dto.common.OrderedStringToStringMap
7-
import com.ecwid.apiclient.v3.dto.common.PictureInfo
4+
import com.ecwid.apiclient.v3.dto.common.*
85
import com.ecwid.apiclient.v3.dto.order.enums.*
96
import com.ecwid.apiclient.v3.dto.product.enums.AttributeValueLocation
107
import com.ecwid.apiclient.v3.dto.producttype.enums.AttributeType
@@ -282,7 +279,20 @@ data class CustomAppRequest(
282279
val type: AttributeType? = null,
283280
val value: String? = null,
284281
val show: AttributeValueLocation? = null
285-
)
282+
) {
283+
284+
fun FetchedAttributeValue.ofOrder() =
285+
AttributeValue(
286+
id = id,
287+
name = name,
288+
type = type,
289+
value = value,
290+
show = show
291+
)
292+
293+
fun Collection<FetchedAttributeValue>.ofOrder() = this.map { it.ofOrder() }
294+
295+
}
286296

287297
data class ProductDimensions(
288298
val length: Double? = null,

src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt

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

3-
import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO
3+
import com.ecwid.apiclient.v3.dto.common.*
44
import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO.ModifyKind
5-
import com.ecwid.apiclient.v3.dto.common.LocalizedValueMap
6-
import com.ecwid.apiclient.v3.dto.common.PictureInfo
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.request.UpdatedProduct
107
import com.ecwid.apiclient.v3.dto.producttype.enums.AttributeType
@@ -238,12 +235,25 @@ data class FetchedProduct(
238235
)
239236

240237
data class AttributeValue(
241-
val id: Int? = null,
242-
val name: String? = null,
243-
val type: AttributeType? = null,
244-
val value: String? = null,
245-
val show: AttributeValueLocation? = null
246-
)
238+
override val id: Int? = null,
239+
override val name: String? = null,
240+
override val type: AttributeType? = null,
241+
override val value: String? = null,
242+
override val show: AttributeValueLocation? = null
243+
): FetchedAttributeValue {
244+
245+
fun FetchedAttributeValue.ofProduct() =
246+
AttributeValue(
247+
id = id,
248+
name = name,
249+
type = type,
250+
value = value,
251+
show = show
252+
)
253+
254+
fun Collection<FetchedAttributeValue>.ofProduct() = this.map { it.ofProduct() }
255+
256+
}
247257

248258
data class RelatedProducts(
249259
val productIds: List<Int>? = null,

src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt

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

33
import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO
44
import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO.ModifyKind
5+
import com.ecwid.apiclient.v3.dto.common.FetchedAttributeValue
56
import com.ecwid.apiclient.v3.dto.common.LocalizedValueMap
67
import com.ecwid.apiclient.v3.dto.product.enums.AttributeValueLocation
78
import com.ecwid.apiclient.v3.dto.product.enums.OutOfStockVisibilityBehaviour
@@ -49,12 +50,25 @@ data class FetchedVariation(
4950
) : ApiFetchedDTO {
5051

5152
data class AttributeValue(
52-
val id: Int? = null,
53-
val name: String? = null,
54-
val type: AttributeType? = null,
55-
val value: String? = null,
56-
val show: AttributeValueLocation? = null
57-
)
53+
override val id: Int? = null,
54+
override val name: String? = null,
55+
override val type: AttributeType? = null,
56+
override val value: String? = null,
57+
override val show: AttributeValueLocation? = null
58+
): FetchedAttributeValue {
59+
60+
fun FetchedAttributeValue.ofVariation() =
61+
AttributeValue(
62+
id = id,
63+
name = name,
64+
type = type,
65+
value = value,
66+
show = show
67+
)
68+
69+
fun Collection<FetchedAttributeValue>.ofVariation() = this.map { it.ofVariation() }
70+
71+
}
5872

5973
data class WholesalePrice(
6074
val quantity: Int = 0,

0 commit comments

Comments
 (0)