Skip to content

Commit 79f78e8

Browse files
authored
Merge pull request #213 from Ecwid/generalize_nested_classes
Add converters to specific implementations of attribute interfaces
2 parents d8453a2 + 4f7c19a commit 79f78e8

5 files changed

Lines changed: 43 additions & 5 deletions

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,15 @@ data class CustomAppRequest(
284284
override val show: AttributeValueLocation? = null
285285
) : FetchedAttributeValue {
286286

287-
fun Collection<FetchedAttributeValue>.toOrderAttributeList() = this.map { it as AttributeValue }
287+
fun FetchedAttributeValue.toOrderAttribute() = AttributeValue(
288+
id = id,
289+
name = name,
290+
type = type,
291+
value = value,
292+
show = show
293+
)
294+
295+
fun Collection<FetchedAttributeValue>.toOrderAttributeList() = this.map { it.toOrderAttribute() }
288296

289297
}
290298

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,14 @@ data class UpdatedProduct(
279279
override val value: String? = null
280280
) : UpdatedAttributeValue {
281281

282-
fun Collection<UpdatedAttributeValue>.toProductAttributeList() = this.map { it as AttributeValue }
282+
fun UpdatedAttributeValue.toProductAttribute() = AttributeValue(
283+
id = id,
284+
alias = alias,
285+
name = name,
286+
value = value,
287+
)
288+
289+
fun Collection<UpdatedAttributeValue>.toProductAttributeList() = this.map { it.toProductAttribute() }
283290

284291
companion object {
285292

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,15 @@ data class FetchedProduct(
242242
override val show: AttributeValueLocation? = null
243243
) : FetchedAttributeValue {
244244

245-
fun Collection<FetchedAttributeValue>.toProductAttributeList() = this.map { it as AttributeValue }
245+
fun FetchedAttributeValue.toProductAttribute() = AttributeValue(
246+
id = id,
247+
name = name,
248+
type = type,
249+
value = value,
250+
show = show
251+
)
252+
253+
fun Collection<FetchedAttributeValue>.toProductAttributeList() = this.map { it.toProductAttribute() }
246254

247255
}
248256

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ data class UpdatedVariation(
4141
override val value: String? = null
4242
) : UpdatedAttributeValue {
4343

44-
fun Collection<UpdatedAttributeValue>.toVariationAttributeList() = this.map { it as AttributeValue }
44+
fun UpdatedAttributeValue.toVariationAttribute() = AttributeValue(
45+
id = id,
46+
alias = alias,
47+
name = name,
48+
value = value,
49+
)
50+
51+
fun Collection<UpdatedAttributeValue>.toVariationAttributeList() = this.map { it.toVariationAttribute() }
4552

4653
}
4754

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ data class FetchedVariation(
5757
override val show: AttributeValueLocation? = null
5858
) : FetchedAttributeValue {
5959

60-
fun Collection<FetchedAttributeValue>.toVariationAttributeList() = this.map { it as AttributeValue }
60+
fun FetchedAttributeValue.toVariationAttribute() = AttributeValue(
61+
id = id,
62+
name = name,
63+
type = type,
64+
value = value,
65+
show = show
66+
)
67+
68+
fun Collection<FetchedAttributeValue>.toVariationAttributeList() = this.map { it.toVariationAttribute() }
6169

6270
}
6371

0 commit comments

Comments
 (0)