From f393e9d7279fc6fe68c53318584e6ec5c6523094 Mon Sep 17 00:00:00 2001 From: valkiriya Date: Wed, 25 Dec 2024 14:19:05 +0400 Subject: [PATCH 1/2] Add swatches support --- .../kotlin/com/ecwid/apiclient/v3/ApiClient.kt | 12 +++++++++++- .../request/RecentSwatchColorsGetRequest.kt | 16 ++++++++++++++++ .../v3/dto/swatches/result/FetchedSwatchColor.kt | 11 +++++++++++ .../apiclient/v3/impl/SwatchesApiClientImpl.kt | 14 ++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/ecwid/apiclient/v3/dto/swatches/request/RecentSwatchColorsGetRequest.kt create mode 100644 src/main/kotlin/com/ecwid/apiclient/v3/dto/swatches/result/FetchedSwatchColor.kt create mode 100644 src/main/kotlin/com/ecwid/apiclient/v3/impl/SwatchesApiClientImpl.kt diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt index b5bff611b..99bcb7731 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt @@ -43,6 +43,8 @@ import com.ecwid.apiclient.v3.dto.storage.result.* import com.ecwid.apiclient.v3.dto.subscriptions.request.SubscriptionsSearchRequest import com.ecwid.apiclient.v3.dto.subscriptions.result.FetchedSubscription import com.ecwid.apiclient.v3.dto.subscriptions.result.SubscriptionsSearchResult +import com.ecwid.apiclient.v3.dto.swatches.request.RecentSwatchColorsGetRequest +import com.ecwid.apiclient.v3.dto.swatches.result.FetchedSwatchColor import com.ecwid.apiclient.v3.dto.variation.request.* import com.ecwid.apiclient.v3.dto.variation.result.* import com.ecwid.apiclient.v3.httptransport.HttpTransport @@ -73,6 +75,7 @@ open class ApiClient private constructor( slugInfoApiClient: SlugInfoApiClientImpl, productReviewsApiClient: ProductReviewsApiClientImpl, storeExtrafieldsApiClient: StoreExtrafieldsApiClientImpl, + swatchesApiClient: SwatchesApiClientImpl, ) : StoreProfileApiClient by storeProfileApiClient, BrandsApiClient by brandsApiClient, @@ -94,7 +97,8 @@ open class ApiClient private constructor( InstantSiteRedirectsApiClient by instantSiteRedirectsApiClient, SlugInfoApiClient by slugInfoApiClient, ProductReviewsApiClient by productReviewsApiClient, - StoreExtrafieldsApiClient by storeExtrafieldsApiClient { + StoreExtrafieldsApiClient by storeExtrafieldsApiClient, + SwatchesApiClient by swatchesApiClient { constructor(apiClientHelper: ApiClientHelper) : this( apiClientHelper = apiClientHelper, @@ -119,6 +123,7 @@ open class ApiClient private constructor( slugInfoApiClient = SlugInfoApiClientImpl(apiClientHelper), productReviewsApiClient = ProductReviewsApiClientImpl(apiClientHelper), storeExtrafieldsApiClient = StoreExtrafieldsApiClientImpl(apiClientHelper), + swatchesApiClient = SwatchesApiClientImpl(apiClientHelper), ) companion object { @@ -316,3 +321,8 @@ interface ProductReviewsApiClient { fun massUpdateProductReview(request: ProductReviewMassUpdateRequest): ProductReviewMassUpdateResult fun getProductReviewsFiltersData(request: ProductReviewFiltersDataRequest): ProductReviewFiltersDataResult } + +// Swatches +interface SwatchesApiClient { + fun getRecentSwatchColors(request: RecentSwatchColorsGetRequest): Sequence +} diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/swatches/request/RecentSwatchColorsGetRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/swatches/request/RecentSwatchColorsGetRequest.kt new file mode 100644 index 000000000..003cc5e61 --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/swatches/request/RecentSwatchColorsGetRequest.kt @@ -0,0 +1,16 @@ +package com.ecwid.apiclient.v3.dto.swatches.request + +import com.ecwid.apiclient.v3.dto.ApiRequest +import com.ecwid.apiclient.v3.impl.RequestInfo + +class RecentSwatchColorsGetRequest : ApiRequest { + override fun toRequestInfo(): RequestInfo { + return RequestInfo.createGetRequest( + pathSegments = listOf( + "swatches", + "recent-colors", + ), + ) + } + +} diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/swatches/result/FetchedSwatchColor.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/swatches/result/FetchedSwatchColor.kt new file mode 100644 index 000000000..1cda4abd6 --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/swatches/result/FetchedSwatchColor.kt @@ -0,0 +1,11 @@ +package com.ecwid.apiclient.v3.dto.swatches.result + +import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO +import com.ecwid.apiclient.v3.dto.common.ApiResultDTO + +data class FetchedSwatchColor( + val name: String = "", + val hexCode: String = "", +) : ApiFetchedDTO, ApiResultDTO { + override fun getModifyKind() = ApiFetchedDTO.ModifyKind.ReadOnly +} diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/impl/SwatchesApiClientImpl.kt b/src/main/kotlin/com/ecwid/apiclient/v3/impl/SwatchesApiClientImpl.kt new file mode 100644 index 000000000..c4bfb1b13 --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/impl/SwatchesApiClientImpl.kt @@ -0,0 +1,14 @@ +package com.ecwid.apiclient.v3.impl + +import com.ecwid.apiclient.v3.ApiClientHelper +import com.ecwid.apiclient.v3.SwatchesApiClient +import com.ecwid.apiclient.v3.dto.swatches.request.RecentSwatchColorsGetRequest +import com.ecwid.apiclient.v3.dto.swatches.result.FetchedSwatchColor + +class SwatchesApiClientImpl( + private val apiClientHelper: ApiClientHelper, +) : SwatchesApiClient { + + override fun getRecentSwatchColors(request: RecentSwatchColorsGetRequest) = + apiClientHelper.makeObjectResultRequest>(request) +} From bab9eeec2a8656ce7db8d0e93f9ca622f40cb787 Mon Sep 17 00:00:00 2001 From: valkiriya Date: Mon, 6 Jan 2025 16:02:59 +0400 Subject: [PATCH 2/2] Return FetchedSwatcheColorsResult in response instend of Sequence of FetchedSwatchColor --- src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt | 4 ++-- .../v3/dto/swatches/result/FetchedSwatchColorsResult.kt | 7 +++++++ .../com/ecwid/apiclient/v3/impl/SwatchesApiClientImpl.kt | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/com/ecwid/apiclient/v3/dto/swatches/result/FetchedSwatchColorsResult.kt diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt index 99bcb7731..4968d6e91 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt @@ -44,7 +44,7 @@ import com.ecwid.apiclient.v3.dto.subscriptions.request.SubscriptionsSearchReque import com.ecwid.apiclient.v3.dto.subscriptions.result.FetchedSubscription import com.ecwid.apiclient.v3.dto.subscriptions.result.SubscriptionsSearchResult import com.ecwid.apiclient.v3.dto.swatches.request.RecentSwatchColorsGetRequest -import com.ecwid.apiclient.v3.dto.swatches.result.FetchedSwatchColor +import com.ecwid.apiclient.v3.dto.swatches.result.FetchedSwatchColorsResult import com.ecwid.apiclient.v3.dto.variation.request.* import com.ecwid.apiclient.v3.dto.variation.result.* import com.ecwid.apiclient.v3.httptransport.HttpTransport @@ -324,5 +324,5 @@ interface ProductReviewsApiClient { // Swatches interface SwatchesApiClient { - fun getRecentSwatchColors(request: RecentSwatchColorsGetRequest): Sequence + fun getRecentSwatchColors(request: RecentSwatchColorsGetRequest): FetchedSwatchColorsResult } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/swatches/result/FetchedSwatchColorsResult.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/swatches/result/FetchedSwatchColorsResult.kt new file mode 100644 index 000000000..3d2173cb0 --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/swatches/result/FetchedSwatchColorsResult.kt @@ -0,0 +1,7 @@ +package com.ecwid.apiclient.v3.dto.swatches.result + +import com.ecwid.apiclient.v3.dto.common.ApiResultDTO + +data class FetchedSwatchColorsResult( + val colors: List = listOf(), +) : ApiResultDTO diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/impl/SwatchesApiClientImpl.kt b/src/main/kotlin/com/ecwid/apiclient/v3/impl/SwatchesApiClientImpl.kt index c4bfb1b13..504c18e30 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/impl/SwatchesApiClientImpl.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/impl/SwatchesApiClientImpl.kt @@ -3,12 +3,12 @@ package com.ecwid.apiclient.v3.impl import com.ecwid.apiclient.v3.ApiClientHelper import com.ecwid.apiclient.v3.SwatchesApiClient import com.ecwid.apiclient.v3.dto.swatches.request.RecentSwatchColorsGetRequest -import com.ecwid.apiclient.v3.dto.swatches.result.FetchedSwatchColor +import com.ecwid.apiclient.v3.dto.swatches.result.FetchedSwatchColorsResult class SwatchesApiClientImpl( private val apiClientHelper: ApiClientHelper, ) : SwatchesApiClient { override fun getRecentSwatchColors(request: RecentSwatchColorsGetRequest) = - apiClientHelper.makeObjectResultRequest>(request) + apiClientHelper.makeObjectResultRequest(request) }