Skip to content

Commit b608ae8

Browse files
authored
Merge pull request #215 from Ecwid/generalize_nested_classes
Move converters to the interface declarations
2 parents 79f78e8 + 8793e1c commit b608ae8

7 files changed

Lines changed: 18 additions & 26 deletions

File tree

src/main/kotlin/com/ecwid/apiclient/v3/dto/common/FetchedAttributeValue.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ package com.ecwid.apiclient.v3.dto.common
33
import com.ecwid.apiclient.v3.dto.product.enums.AttributeValueLocation
44
import com.ecwid.apiclient.v3.dto.producttype.enums.AttributeType
55

6-
interface FetchedAttributeValue {
6+
interface FetchedAttributeValue<T : FetchedAttributeValue<T>> {
77
val id: Int?
88
val name: String?
99
val type: AttributeType?
1010
val value: String?
1111
val show: AttributeValueLocation?
12+
13+
fun cast(): T
14+
1215
}

src/main/kotlin/com/ecwid/apiclient/v3/dto/common/UpdatedAttributeValue.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package com.ecwid.apiclient.v3.dto.common
22

33
import com.ecwid.apiclient.v3.dto.product.enums.AttributeValueAlias
44

5-
interface UpdatedAttributeValue {
5+
interface UpdatedAttributeValue<T : UpdatedAttributeValue<T>> {
66
val id: Int?
77
val alias: AttributeValueAlias?
88
val name: String?
99
val value: String?
10+
11+
fun cast(): T
12+
1013
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,18 +282,15 @@ data class CustomAppRequest(
282282
override val type: AttributeType? = null,
283283
override val value: String? = null,
284284
override val show: AttributeValueLocation? = null
285-
) : FetchedAttributeValue {
285+
) : FetchedAttributeValue<AttributeValue> {
286286

287-
fun FetchedAttributeValue.toOrderAttribute() = AttributeValue(
287+
override fun cast() = AttributeValue(
288288
id = id,
289289
name = name,
290290
type = type,
291291
value = value,
292292
show = show
293293
)
294-
295-
fun Collection<FetchedAttributeValue>.toOrderAttributeList() = this.map { it.toOrderAttribute() }
296-
297294
}
298295

299296
data class ProductDimensions(

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,17 +277,15 @@ data class UpdatedProduct(
277277
override val alias: AttributeValueAlias? = null,
278278
override val name: String? = null,
279279
override val value: String? = null
280-
) : UpdatedAttributeValue {
280+
) : UpdatedAttributeValue<AttributeValue> {
281281

282-
fun UpdatedAttributeValue.toProductAttribute() = AttributeValue(
282+
override fun cast() = AttributeValue(
283283
id = id,
284284
alias = alias,
285285
name = name,
286286
value = value,
287287
)
288288

289-
fun Collection<UpdatedAttributeValue>.toProductAttributeList() = this.map { it.toProductAttribute() }
290-
291289
companion object {
292290

293291
fun createBrandAttributeValue(value: String) = AttributeValue(

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,15 @@ data class FetchedProduct(
240240
override val type: AttributeType? = null,
241241
override val value: String? = null,
242242
override val show: AttributeValueLocation? = null
243-
) : FetchedAttributeValue {
243+
) : FetchedAttributeValue<AttributeValue> {
244244

245-
fun FetchedAttributeValue.toProductAttribute() = AttributeValue(
245+
override fun cast() = AttributeValue(
246246
id = id,
247247
name = name,
248248
type = type,
249249
value = value,
250250
show = show
251251
)
252-
253-
fun Collection<FetchedAttributeValue>.toProductAttributeList() = this.map { it.toProductAttribute() }
254-
255252
}
256253

257254
data class RelatedProducts(

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,14 @@ data class UpdatedVariation(
3939
override val alias: AttributeValueAlias? = null,
4040
override val name: String? = null,
4141
override val value: String? = null
42-
) : UpdatedAttributeValue {
42+
) : UpdatedAttributeValue<AttributeValue> {
4343

44-
fun UpdatedAttributeValue.toVariationAttribute() = AttributeValue(
44+
override fun cast() = AttributeValue(
4545
id = id,
4646
alias = alias,
4747
name = name,
4848
value = value,
4949
)
50-
51-
fun Collection<UpdatedAttributeValue>.toVariationAttributeList() = this.map { it.toVariationAttribute() }
52-
5350
}
5451

5552
data class WholesalePrice(

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,15 @@ data class FetchedVariation(
5555
override val type: AttributeType? = null,
5656
override val value: String? = null,
5757
override val show: AttributeValueLocation? = null
58-
) : FetchedAttributeValue {
58+
) : FetchedAttributeValue<AttributeValue> {
5959

60-
fun FetchedAttributeValue.toVariationAttribute() = AttributeValue(
60+
override fun cast() = AttributeValue(
6161
id = id,
6262
name = name,
6363
type = type,
6464
value = value,
6565
show = show
6666
)
67-
68-
fun Collection<FetchedAttributeValue>.toVariationAttributeList() = this.map { it.toVariationAttribute() }
69-
7067
}
7168

7269
data class WholesalePrice(

0 commit comments

Comments
 (0)