From 6439bbe03aff94617139d1d32f41fbdd4aba6ab2 Mon Sep 17 00:00:00 2001 From: "illarion.borts" Date: Mon, 13 May 2024 12:28:22 +0200 Subject: [PATCH] ECWID-139066 - support PartialResult models for variation --- .../kotlin/com/ecwid/apiclient/v3/ApiClient.kt | 16 ++++++++++++++++ .../com/ecwid/apiclient/v3/ApiClientHelper.kt | 9 +++++++++ .../v3/dto/variation/result/FetchedVariation.kt | 7 ++----- .../v3/impl/ProductVariationsApiClientImpl.kt | 10 ++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt index efaf413e6..12b47a230 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt @@ -17,6 +17,7 @@ import com.ecwid.apiclient.v3.dto.batch.result.GetEscapedBatchResult import com.ecwid.apiclient.v3.dto.batch.result.GetTypedBatchResult import com.ecwid.apiclient.v3.dto.cart.request.* import com.ecwid.apiclient.v3.dto.cart.result.* +import com.ecwid.apiclient.v3.dto.common.PartialResult import com.ecwid.apiclient.v3.dto.coupon.request.* import com.ecwid.apiclient.v3.dto.coupon.result.* import com.ecwid.apiclient.v3.dto.customer.request.* @@ -47,6 +48,7 @@ import com.ecwid.apiclient.v3.dto.variation.result.* import com.ecwid.apiclient.v3.httptransport.HttpTransport import com.ecwid.apiclient.v3.impl.* import com.ecwid.apiclient.v3.jsontransformer.JsonTransformerProvider +import kotlin.reflect.KClass open class ApiClient private constructor( protected val apiClientHelper: ApiClientHelper, @@ -212,7 +214,11 @@ interface ProductVariationsApiClient { fun uploadVariationImage(request: ProductVariationImageUploadRequest): ProductVariationImageUploadResult fun uploadProductVariationImageAsync(request: ProductVariationImageAsyncUploadRequest): ProductVariationImageAsyncUploadResult fun getAllProductVariations(request: ProductVariationsRequest): ProductVariationsResult + fun getAllProductVariations(request: ProductVariationsRequest, resultClass: KClass): List + where Result : PartialResult fun getProductVariation(request: ProductVariationDetailsRequest): FetchedVariation + fun getProductVariation(request: ProductVariationDetailsRequest, resultClass: KClass): Result + where Result : PartialResult fun updateProductVariation(request: UpdateProductVariationRequest): UpdateProductVariationResult fun deleteProductVariation(request: DeleteProductVariationRequest): DeleteProductVariationsResult fun deleteAllProductVariations(request: DeleteAllProductVariationsRequest): DeleteProductVariationsResult @@ -220,6 +226,16 @@ interface ProductVariationsApiClient { fun deleteVariationImage(request: ProductVariationImageDeleteRequest): ProductVariationImageDeleteResult } +@Suppress("EXTENSION_SHADOWED_BY_MEMBER") +inline fun > ProductVariationsApiClient.getProductVariation(request: ProductVariationDetailsRequest): Result { + return getProductVariation(request, Result::class) +} + +@Suppress("EXTENSION_SHADOWED_BY_MEMBER") +inline fun > ProductVariationsApiClient.getAllProductVariations(request: ProductVariationsRequest): List { + return getAllProductVariations(request, Result::class) +} + // Carts // https://developers.ecwid.com/api-documentation/carts interface CartsApiClient { diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClientHelper.kt b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClientHelper.kt index f13e28fb4..051e6411b 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClientHelper.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClientHelper.kt @@ -128,6 +128,15 @@ class ApiClientHelper private constructor( ) } + @Suppress("UNCHECKED_CAST") + fun > makeObjectPartialResultRequestList(request: ApiRequest, resultClass: KClass): List { + return makeRequestInt( + request = request, + responseParser = ObjectResponseParser(jsonTransformer, resultClass.java.arrayType() as Class>), + responseFieldsOverride = responseFieldsOf(resultClass) + ).toList() + } + @Suppress("unused") fun , VExt : PartialResult<*>> makeObjectPartialResultWithExtRequest( request: ApiRequest, 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 e20419b2a..a1c6f21ce 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 @@ -1,10 +1,7 @@ package com.ecwid.apiclient.v3.dto.variation.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.FetchedAlt -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 import com.ecwid.apiclient.v3.dto.product.enums.RecurringSubscriptionInterval @@ -58,7 +55,7 @@ data class FetchedVariation( val customsHsTariffCode: String? = null, val subscriptionSettings: SubscriptionSettings? = null, val alt: FetchedAlt? = null, -) : ApiFetchedDTO { +) : ApiFetchedDTO, ApiResultDTO { data class AttributeValue( override val id: Int? = null, diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/impl/ProductVariationsApiClientImpl.kt b/src/main/kotlin/com/ecwid/apiclient/v3/impl/ProductVariationsApiClientImpl.kt index a16182ccb..7e1a4e631 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/impl/ProductVariationsApiClientImpl.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/impl/ProductVariationsApiClientImpl.kt @@ -2,8 +2,10 @@ package com.ecwid.apiclient.v3.impl import com.ecwid.apiclient.v3.ApiClientHelper import com.ecwid.apiclient.v3.ProductVariationsApiClient +import com.ecwid.apiclient.v3.dto.common.PartialResult import com.ecwid.apiclient.v3.dto.variation.request.* import com.ecwid.apiclient.v3.dto.variation.result.* +import kotlin.reflect.KClass internal class ProductVariationsApiClientImpl( private val apiClientHelper: ApiClientHelper @@ -23,9 +25,17 @@ internal class ProductVariationsApiClientImpl( override fun getAllProductVariations(request: ProductVariationsRequest) = apiClientHelper.makeObjectResultRequest(request) + override fun > getAllProductVariations(request: ProductVariationsRequest, resultClass: KClass): List { + return apiClientHelper.makeObjectPartialResultRequestList(request, resultClass) + } + override fun getProductVariation(request: ProductVariationDetailsRequest) = apiClientHelper.makeObjectResultRequest(request) + override fun > getProductVariation(request: ProductVariationDetailsRequest, resultClass: KClass): Result { + return apiClientHelper.makeObjectPartialResultRequest(request, resultClass) + } + override fun updateProductVariation(request: UpdateProductVariationRequest) = apiClientHelper.makeObjectResultRequest(request)