From c25ea96e242b5698285bf2656756de82cd16f3a3 Mon Sep 17 00:00:00 2001 From: Alexeyyy Date: Thu, 5 Dec 2024 10:50:42 +0400 Subject: [PATCH 1/9] ECWID-153684 - added new method searchBrands in API Client. --- .../com/ecwid/apiclient/v3/ApiClient.kt | 15 +++++- .../dto/brand/request/BrandsSearchRequest.kt | 49 +++++++++++++++++++ .../v3/dto/brand/result/BrandsSearchResult.kt | 11 +++++ .../v3/dto/brand/result/FetchedBrand.kt | 12 +++++ .../apiclient/v3/impl/BrandsApiClientImpl.kt | 26 ++++++++++ .../v3/rule/NullablePropertyRules.kt | 2 + .../BrandsSearchRequestRules.kt | 13 +++++ .../FetchedBrandRules.kt | 10 ++++ 8 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/request/BrandsSearchRequest.kt create mode 100644 src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/result/BrandsSearchResult.kt create mode 100644 src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/result/FetchedBrand.kt create mode 100644 src/main/kotlin/com/ecwid/apiclient/v3/impl/BrandsApiClientImpl.kt create mode 100644 src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/BrandsSearchRequestRules.kt create mode 100644 src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedBrandRules.kt diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt index ab396411..8f3c2a17 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt @@ -15,6 +15,8 @@ import com.ecwid.apiclient.v3.dto.batch.result.CancelBatchGroupResult import com.ecwid.apiclient.v3.dto.batch.result.CreateBatchResult import com.ecwid.apiclient.v3.dto.batch.result.GetEscapedBatchResult import com.ecwid.apiclient.v3.dto.batch.result.GetTypedBatchResult +import com.ecwid.apiclient.v3.dto.brand.request.BrandsSearchRequest +import com.ecwid.apiclient.v3.dto.brand.result.BrandsSearchResult import com.ecwid.apiclient.v3.dto.cart.request.* import com.ecwid.apiclient.v3.dto.cart.result.* import com.ecwid.apiclient.v3.dto.common.PartialResult @@ -26,8 +28,6 @@ import com.ecwid.apiclient.v3.dto.customergroup.request.* import com.ecwid.apiclient.v3.dto.customergroup.result.* import com.ecwid.apiclient.v3.dto.instantsite.redirects.request.* import com.ecwid.apiclient.v3.dto.instantsite.redirects.result.* -import com.ecwid.apiclient.v3.dto.order.request.* -import com.ecwid.apiclient.v3.dto.order.result.* import com.ecwid.apiclient.v3.dto.productreview.request.* import com.ecwid.apiclient.v3.dto.productreview.result.* import com.ecwid.apiclient.v3.dto.producttype.request.* @@ -55,6 +55,7 @@ import kotlin.reflect.KClass open class ApiClient private constructor( protected val apiClientHelper: ApiClientHelper, storeProfileApiClient: StoreProfileApiClient, + brandsApiClient: BrandsApiClient, productsApiClient: ProductsApiClient, categoriesApiClient: CategoriesApiClient, ordersApiClient: OrdersApiClient, @@ -76,6 +77,7 @@ open class ApiClient private constructor( storeExtrafieldsApiClient: StoreExtrafieldsApiClientImpl, ) : StoreProfileApiClient by storeProfileApiClient, + BrandsApiClient by brandsApiClient, ProductsApiClient by productsApiClient, CategoriesApiClient by categoriesApiClient, OrdersApiClient by ordersApiClient, @@ -99,6 +101,7 @@ open class ApiClient private constructor( constructor(apiClientHelper: ApiClientHelper) : this( apiClientHelper = apiClientHelper, storeProfileApiClient = StoreProfileApiClientImpl(apiClientHelper), + brandsApiClient = BrandsApiClientImpl(apiClientHelper), productsApiClient = ProductsApiClientImpl(apiClientHelper), categoriesApiClient = CategoriesApiClientImpl(apiClientHelper), ordersApiClient = OrdersApiClientImpl(apiClientHelper), @@ -315,3 +318,11 @@ interface ProductReviewsApiClient { fun massUpdateProductReview(request: ProductReviewMassUpdateRequest): ProductReviewMassUpdateResult fun getProductReviewsFiltersData(request: ProductReviewFiltersDataRequest): ProductReviewFiltersDataResult } + +// Brands +// https://api-docs.ecwid.com/reference/search-product-brands +interface BrandsApiClient { + fun searchBrands(request: BrandsSearchRequest.ByFilters): BrandsSearchResult + fun searchBrands(request: BrandsSearchRequest.ByFilters, resultClass: KClass): Result + where Result: PartialResult +} diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/request/BrandsSearchRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/request/BrandsSearchRequest.kt new file mode 100644 index 00000000..eb687647 --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/request/BrandsSearchRequest.kt @@ -0,0 +1,49 @@ +package com.ecwid.apiclient.v3.dto.brand.request + +import com.ecwid.apiclient.v3.dto.ApiRequest +import com.ecwid.apiclient.v3.dto.common.PagingRequest +import com.ecwid.apiclient.v3.impl.RequestInfo +import com.ecwid.apiclient.v3.responsefields.ResponseFields + +sealed class BrandsSearchRequest : ApiRequest { + + data class ByFilters( + val limit: Int = 100, + override val offset: Int = 0, + val lang: String? = null, + val hiddenBrands: Boolean? = null, + val baseUrl: String? = null, + val cleanUrls: Boolean? = null, + val sortBy: SortOrder? = null, + val responseFields: ResponseFields = ResponseFields.All, + ) : BrandsSearchRequest(), PagingRequest { + override fun toRequestInfo() = RequestInfo.createGetRequest( + pathSegments = listOf( + "brands", + ), + params = toParams(), + responseFields = responseFields, + ) + + private fun toParams(): Map { + val request = this + return mutableMapOf().apply { + put("limit", request.limit.toString()) + put("offset", request.offset.toString()) + request.lang?.let { put("lang", it) } + request.hiddenBrands?.let { put("hiddenBrands", it.toString()) } + request.baseUrl?.let { put("baseUrl", it) } + request.cleanUrls?.let { put("cleanUrls", it.toString()) } + request.sortBy?.let { put("sortBy", it.name) } + }.toMap() + } + + override fun copyWithOffset(offset: Int) = copy(offset = offset) + } + + @Suppress("unused") + enum class SortOrder { + PRODUCT_COUNT_DESC, + NAME_ASC, + } +} diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/result/BrandsSearchResult.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/result/BrandsSearchResult.kt new file mode 100644 index 00000000..ca65cc8d --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/result/BrandsSearchResult.kt @@ -0,0 +1,11 @@ +package com.ecwid.apiclient.v3.dto.brand.result + +import com.ecwid.apiclient.v3.dto.common.ApiResultDTO + +data class BrandsSearchResult( + val items: List = listOf(), + val count: Int = 0, + val total: Int = 0, + val limit: Int = 0, + val offset: Int = 0 +) : ApiResultDTO diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/result/FetchedBrand.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/result/FetchedBrand.kt new file mode 100644 index 00000000..7dffff72 --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/result/FetchedBrand.kt @@ -0,0 +1,12 @@ +package com.ecwid.apiclient.v3.dto.brand.result + +import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO +import com.ecwid.apiclient.v3.dto.common.ApiResultDTO + +data class FetchedBrand( + val name: String = "", + val nameTranslated: Map? = null, + val productsFilteredByBrandUrl: String? = null, +): ApiFetchedDTO, ApiResultDTO { + override fun getModifyKind() = ApiFetchedDTO.ModifyKind.ReadOnly +} diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/impl/BrandsApiClientImpl.kt b/src/main/kotlin/com/ecwid/apiclient/v3/impl/BrandsApiClientImpl.kt new file mode 100644 index 00000000..f4bbf407 --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/impl/BrandsApiClientImpl.kt @@ -0,0 +1,26 @@ +package com.ecwid.apiclient.v3.impl + +import com.ecwid.apiclient.v3.ApiClientHelper +import com.ecwid.apiclient.v3.BrandsApiClient +import com.ecwid.apiclient.v3.dto.brand.request.BrandsSearchRequest +import com.ecwid.apiclient.v3.dto.brand.result.BrandsSearchResult +import com.ecwid.apiclient.v3.dto.common.PartialResult +import kotlin.reflect.KClass + +internal class BrandsApiClientImpl( + private val apiClientHelper: ApiClientHelper, +): BrandsApiClient { + + override fun searchBrands(request: BrandsSearchRequest.ByFilters) = + apiClientHelper.makeObjectResultRequest(request) + + override fun > searchBrands( + request: BrandsSearchRequest.ByFilters, + resultClass: KClass + ): Result { + return apiClientHelper.makeObjectPartialResultRequest( + request = request, + resultClass = resultClass, + ) + } +} diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt b/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt index e0ed2c84..f139e9d6 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt @@ -200,6 +200,8 @@ val nullablePropertyRules: List> = listOf( productReviewMassUpdateRequestNullablePropertyRules, productReviewSearchRequestNullablePropertyRules, fetchedCustomersConfigNullablePropertyRules, + brandsSearchRequestNullablePropertyRules, + fetchedBrandNullablePropertyRules, ).flatten() sealed class NullablePropertyRule( diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/BrandsSearchRequestRules.kt b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/BrandsSearchRequestRules.kt new file mode 100644 index 00000000..7bac458a --- /dev/null +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/BrandsSearchRequestRules.kt @@ -0,0 +1,13 @@ +package com.ecwid.apiclient.v3.rule.nullablepropertyrules + +import com.ecwid.apiclient.v3.dto.brand.request.BrandsSearchRequest +import com.ecwid.apiclient.v3.rule.NullablePropertyRule +import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable + +val brandsSearchRequestNullablePropertyRules: List> = listOf( + AllowNullable(BrandsSearchRequest.ByFilters::lang), + AllowNullable(BrandsSearchRequest.ByFilters::hiddenBrands), + AllowNullable(BrandsSearchRequest.ByFilters::baseUrl), + AllowNullable(BrandsSearchRequest.ByFilters::cleanUrls), + AllowNullable(BrandsSearchRequest.ByFilters::sortBy), +) diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedBrandRules.kt b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedBrandRules.kt new file mode 100644 index 00000000..6b15f06f --- /dev/null +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedBrandRules.kt @@ -0,0 +1,10 @@ +package com.ecwid.apiclient.v3.rule.nullablepropertyrules + +import com.ecwid.apiclient.v3.dto.brand.result.FetchedBrand +import com.ecwid.apiclient.v3.rule.NullablePropertyRule +import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable + +val fetchedBrandNullablePropertyRules: List> = listOf( + AllowNullable(FetchedBrand::nameTranslated), + AllowNullable(FetchedBrand::productsFilteredByBrandUrl), +) From a54a3cd527f0f8de635bd9292bf2645952f1311b Mon Sep 17 00:00:00 2001 From: Alexeyyy Date: Thu, 5 Dec 2024 12:55:24 +0400 Subject: [PATCH 2/9] ECWID-153684 - fixed DETEKT. --- src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt | 2 +- .../com/ecwid/apiclient/v3/dto/brand/result/FetchedBrand.kt | 2 +- .../kotlin/com/ecwid/apiclient/v3/impl/BrandsApiClientImpl.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt index 8f3c2a17..1e5d3870 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt @@ -324,5 +324,5 @@ interface ProductReviewsApiClient { interface BrandsApiClient { fun searchBrands(request: BrandsSearchRequest.ByFilters): BrandsSearchResult fun searchBrands(request: BrandsSearchRequest.ByFilters, resultClass: KClass): Result - where Result: PartialResult + where Result : PartialResult } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/result/FetchedBrand.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/result/FetchedBrand.kt index 7dffff72..09ebf1da 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/result/FetchedBrand.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/result/FetchedBrand.kt @@ -7,6 +7,6 @@ data class FetchedBrand( val name: String = "", val nameTranslated: Map? = null, val productsFilteredByBrandUrl: String? = null, -): ApiFetchedDTO, ApiResultDTO { +) : ApiFetchedDTO, ApiResultDTO { override fun getModifyKind() = ApiFetchedDTO.ModifyKind.ReadOnly } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/impl/BrandsApiClientImpl.kt b/src/main/kotlin/com/ecwid/apiclient/v3/impl/BrandsApiClientImpl.kt index f4bbf407..c5d42f6e 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/impl/BrandsApiClientImpl.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/impl/BrandsApiClientImpl.kt @@ -9,7 +9,7 @@ import kotlin.reflect.KClass internal class BrandsApiClientImpl( private val apiClientHelper: ApiClientHelper, -): BrandsApiClient { +) : BrandsApiClient { override fun searchBrands(request: BrandsSearchRequest.ByFilters) = apiClientHelper.makeObjectResultRequest(request) From 041295c3a81d224c96ae4e7d61699136ad2add77 Mon Sep 17 00:00:00 2001 From: Alexeyyy Date: Fri, 6 Dec 2024 15:04:45 +0400 Subject: [PATCH 3/9] ECWID-153684 - fixed test issue. --- src/test/kotlin/com/ecwid/apiclient/v3/util/OrderUtils.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/util/OrderUtils.kt b/src/test/kotlin/com/ecwid/apiclient/v3/util/OrderUtils.kt index 7942d0c6..a359db5d 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/util/OrderUtils.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/util/OrderUtils.kt @@ -105,9 +105,9 @@ fun generateTestOrder(): UpdatedOrder { shippingMethodName = "Method " + randomAlphanumeric(8), shippingRate = randomPrice(), estimatedTransitTime = "Estimates " + randomAlphanumeric(8), - isPickup = false, + isPickup = true, pickupInstruction = "Instruction " + randomAlphanumeric(64), - fulfillmentType = FulfillmentType.SHIPPING + fulfillmentType = FulfillmentType.PICKUP ), taxesOnShipping = listOf(), handlingFee = UpdatedOrder.HandlingFee( From e1cef13f5e33e494d1b3197f5495f093c2cab1ed Mon Sep 17 00:00:00 2001 From: Alexeyyy Date: Fri, 6 Dec 2024 16:22:48 +0400 Subject: [PATCH 4/9] ECWID-153684 - added tests. --- .../ecwid/apiclient/v3/CategoriesApiClient.kt | 4 + .../v3/impl/CategoriesApiClientImpl.kt | 5 + .../ecwid/apiclient/v3/entity/BrandsTest.kt | 97 +++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 src/test/kotlin/com/ecwid/apiclient/v3/entity/BrandsTest.kt diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/CategoriesApiClient.kt b/src/main/kotlin/com/ecwid/apiclient/v3/CategoriesApiClient.kt index 2a5167cf..14241329 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/CategoriesApiClient.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/CategoriesApiClient.kt @@ -1,5 +1,7 @@ package com.ecwid.apiclient.v3 +import com.ecwid.apiclient.v3.dto.brand.request.BrandsSearchRequest +import com.ecwid.apiclient.v3.dto.brand.result.BrandsSearchResult import com.ecwid.apiclient.v3.dto.category.request.* import com.ecwid.apiclient.v3.dto.category.result.* import com.ecwid.apiclient.v3.dto.common.PagingResult @@ -37,6 +39,8 @@ interface CategoriesApiClient { fun deleteCategoryImage(request: CategoryImageDeleteRequest): CategoryImageDeleteResult fun assignProductsToCategory(request: AssignProductsToCategoryRequest): CategoryUpdateResult fun unassignProductsFromCategory(request: UnassignProductsFromCategoryRequest): CategoryDeleteResult + + fun getBrands(request: BrandsSearchRequest): BrandsSearchResult } @Suppress("EXTENSION_SHADOWED_BY_MEMBER") diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/impl/CategoriesApiClientImpl.kt b/src/main/kotlin/com/ecwid/apiclient/v3/impl/CategoriesApiClientImpl.kt index 9bdf8090..1ae99104 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/impl/CategoriesApiClientImpl.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/impl/CategoriesApiClientImpl.kt @@ -2,6 +2,8 @@ package com.ecwid.apiclient.v3.impl import com.ecwid.apiclient.v3.ApiClientHelper import com.ecwid.apiclient.v3.CategoriesApiClient +import com.ecwid.apiclient.v3.dto.brand.request.BrandsSearchRequest +import com.ecwid.apiclient.v3.dto.brand.result.BrandsSearchResult import com.ecwid.apiclient.v3.dto.category.request.* import com.ecwid.apiclient.v3.dto.category.result.* import com.ecwid.apiclient.v3.dto.common.PagingResult @@ -112,4 +114,7 @@ internal class CategoriesApiClientImpl( ): Sequence where Result : PartialResult, Result : PagingResult { return fetchPagesAsItemSequence(request) { searchCategoriesByPath(it, resultClass) } } + + override fun getBrands(request: BrandsSearchRequest) = + apiClientHelper.makeObjectResultRequest(request) } diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/entity/BrandsTest.kt b/src/test/kotlin/com/ecwid/apiclient/v3/entity/BrandsTest.kt new file mode 100644 index 00000000..35342fd7 --- /dev/null +++ b/src/test/kotlin/com/ecwid/apiclient/v3/entity/BrandsTest.kt @@ -0,0 +1,97 @@ +package com.ecwid.apiclient.v3.entity + +import com.ecwid.apiclient.v3.dto.brand.request.BrandsSearchRequest +import com.ecwid.apiclient.v3.dto.product.request.ProductCreateRequest +import com.ecwid.apiclient.v3.dto.product.request.ProductsSearchRequest.ByFilters +import com.ecwid.apiclient.v3.dto.product.request.UpdatedProduct +import com.ecwid.apiclient.v3.dto.product.request.UpdatedProduct.* +import com.ecwid.apiclient.v3.util.randomAlphanumeric +import com.ecwid.apiclient.v3.util.randomPrice +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import kotlin.test.Test +import kotlin.test.assertEquals + +class BrandsTest : BaseEntityTest() { + + @BeforeEach + override fun beforeEach() { + super.beforeEach() + + initStoreProfile() + removeAllProducts() + } + + @Test + fun getBrands() { + val brandedProductsCreateResult = createProductsWithBrands() + + // Waiting till product became available for searching + brandedProductsCreateResult.skus.forEach { sku -> + waitForIndexedProducts( + productsSearchRequest = ByFilters(sku = sku), + desiredProductCount = 1 + ) + } + + val result = apiClient.getBrands(BrandsSearchRequest.ByFilters()) + assertEquals( + brandedProductsCreateResult.brandNames, + result.items.map { it.name } + ) + } + + private fun createProductsWithBrands(productsCount: Int = 5): BrandedProductsCreateResult { + val brands = mutableListOf() + val skus = mutableListOf() + + for (i in 1..productsCount) { + val randomBrand = randomAlphanumeric(8) + val randomSku = randomAlphanumeric(10) + val price = randomPrice() + + val productCreateRequest = ProductCreateRequest( + newProduct = UpdatedProduct( + name = "Product ${randomAlphanumeric(8)}", + sku = randomSku, + price = price, + compareToPrice = 2 * price, + enabled = true, + quantity = 10, + attributes = listOf( + AttributeValue.createBrandAttributeValue(randomBrand), + AttributeValue.createUpcAttributeValue("UPC ${randomAlphanumeric(8)}") + ), + options = listOf( + ProductOption.createSelectOption( + name = "Color", + choices = listOf( + ProductOptionChoice("Black"), + ProductOptionChoice("White"), + ProductOptionChoice("Yellow"), + ProductOptionChoice("Red") + ), + defaultChoice = 0, + required = true + ) + ) + ) + ) + val productCreateResult = apiClient.createProduct(productCreateRequest) + assertTrue(productCreateResult.id > 0) + + skus.add(randomSku) + brands.add(randomBrand) + } + + return BrandedProductsCreateResult( + brandNames = brands, + skus = skus, + ) + } + + data class BrandedProductsCreateResult( + val brandNames: List, + val skus: List, + ) +} From eb99b1672158fc7c19ac9136dce8a34649d29f9e Mon Sep 17 00:00:00 2001 From: Alexeyyy Date: Fri, 6 Dec 2024 16:41:57 +0400 Subject: [PATCH 5/9] ECWID-153684 - fixed DETEKT. --- src/test/kotlin/com/ecwid/apiclient/v3/entity/BrandsTest.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/entity/BrandsTest.kt b/src/test/kotlin/com/ecwid/apiclient/v3/entity/BrandsTest.kt index 35342fd7..94174fa6 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/entity/BrandsTest.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/entity/BrandsTest.kt @@ -52,7 +52,7 @@ class BrandsTest : BaseEntityTest() { val productCreateRequest = ProductCreateRequest( newProduct = UpdatedProduct( - name = "Product ${randomAlphanumeric(8)}", + name = "Product $i ${randomAlphanumeric(8)}", sku = randomSku, price = price, compareToPrice = 2 * price, @@ -60,7 +60,6 @@ class BrandsTest : BaseEntityTest() { quantity = 10, attributes = listOf( AttributeValue.createBrandAttributeValue(randomBrand), - AttributeValue.createUpcAttributeValue("UPC ${randomAlphanumeric(8)}") ), options = listOf( ProductOption.createSelectOption( From 87ac3dc99d920c8c1ee43cf0b4c02b74ef248054 Mon Sep 17 00:00:00 2001 From: Alexeyyy Date: Mon, 16 Dec 2024 13:12:06 +0400 Subject: [PATCH 6/9] ECWID-153684 - restructured code. --- .../com/ecwid/apiclient/v3/ApiClient.kt | 10 --------- .../com/ecwid/apiclient/v3/BrandsApiClient.kt | 21 +++++++++++++++++++ .../ecwid/apiclient/v3/CategoriesApiClient.kt | 4 ---- .../apiclient/v3/impl/BrandsApiClientImpl.kt | 4 ++-- .../v3/impl/CategoriesApiClientImpl.kt | 5 ----- .../ecwid/apiclient/v3/entity/BrandsTest.kt | 2 +- src/test/resources/test.properties.sample | 6 +++--- 7 files changed, 27 insertions(+), 25 deletions(-) create mode 100644 src/main/kotlin/com/ecwid/apiclient/v3/BrandsApiClient.kt diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt index 1e5d3870..b5bff611 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt @@ -15,8 +15,6 @@ import com.ecwid.apiclient.v3.dto.batch.result.CancelBatchGroupResult import com.ecwid.apiclient.v3.dto.batch.result.CreateBatchResult import com.ecwid.apiclient.v3.dto.batch.result.GetEscapedBatchResult import com.ecwid.apiclient.v3.dto.batch.result.GetTypedBatchResult -import com.ecwid.apiclient.v3.dto.brand.request.BrandsSearchRequest -import com.ecwid.apiclient.v3.dto.brand.result.BrandsSearchResult import com.ecwid.apiclient.v3.dto.cart.request.* import com.ecwid.apiclient.v3.dto.cart.result.* import com.ecwid.apiclient.v3.dto.common.PartialResult @@ -318,11 +316,3 @@ interface ProductReviewsApiClient { fun massUpdateProductReview(request: ProductReviewMassUpdateRequest): ProductReviewMassUpdateResult fun getProductReviewsFiltersData(request: ProductReviewFiltersDataRequest): ProductReviewFiltersDataResult } - -// Brands -// https://api-docs.ecwid.com/reference/search-product-brands -interface BrandsApiClient { - fun searchBrands(request: BrandsSearchRequest.ByFilters): BrandsSearchResult - fun searchBrands(request: BrandsSearchRequest.ByFilters, resultClass: KClass): Result - where Result : PartialResult -} diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/BrandsApiClient.kt b/src/main/kotlin/com/ecwid/apiclient/v3/BrandsApiClient.kt new file mode 100644 index 00000000..5a88d7a8 --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/BrandsApiClient.kt @@ -0,0 +1,21 @@ +package com.ecwid.apiclient.v3 + +import com.ecwid.apiclient.v3.dto.brand.request.BrandsSearchRequest +import com.ecwid.apiclient.v3.dto.brand.result.BrandsSearchResult +import com.ecwid.apiclient.v3.dto.common.PartialResult +import kotlin.reflect.KClass + +// Brands +// https://api-docs.ecwid.com/reference/product-brands +interface BrandsApiClient { + fun searchBrands(request: BrandsSearchRequest): BrandsSearchResult + fun searchBrands(request: BrandsSearchRequest, resultClass: KClass): Result + where Result : PartialResult +} + +@Suppress("EXTENSION_SHADOWED_BY_MEMBER") +inline fun > BrandsApiClient.searchBrands( + request: BrandsSearchRequest +): Result { + return searchBrands(request, resultClass = Result::class) +} diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/CategoriesApiClient.kt b/src/main/kotlin/com/ecwid/apiclient/v3/CategoriesApiClient.kt index 14241329..2a5167cf 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/CategoriesApiClient.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/CategoriesApiClient.kt @@ -1,7 +1,5 @@ package com.ecwid.apiclient.v3 -import com.ecwid.apiclient.v3.dto.brand.request.BrandsSearchRequest -import com.ecwid.apiclient.v3.dto.brand.result.BrandsSearchResult import com.ecwid.apiclient.v3.dto.category.request.* import com.ecwid.apiclient.v3.dto.category.result.* import com.ecwid.apiclient.v3.dto.common.PagingResult @@ -39,8 +37,6 @@ interface CategoriesApiClient { fun deleteCategoryImage(request: CategoryImageDeleteRequest): CategoryImageDeleteResult fun assignProductsToCategory(request: AssignProductsToCategoryRequest): CategoryUpdateResult fun unassignProductsFromCategory(request: UnassignProductsFromCategoryRequest): CategoryDeleteResult - - fun getBrands(request: BrandsSearchRequest): BrandsSearchResult } @Suppress("EXTENSION_SHADOWED_BY_MEMBER") diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/impl/BrandsApiClientImpl.kt b/src/main/kotlin/com/ecwid/apiclient/v3/impl/BrandsApiClientImpl.kt index c5d42f6e..8d56c15c 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/impl/BrandsApiClientImpl.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/impl/BrandsApiClientImpl.kt @@ -11,11 +11,11 @@ internal class BrandsApiClientImpl( private val apiClientHelper: ApiClientHelper, ) : BrandsApiClient { - override fun searchBrands(request: BrandsSearchRequest.ByFilters) = + override fun searchBrands(request: BrandsSearchRequest) = apiClientHelper.makeObjectResultRequest(request) override fun > searchBrands( - request: BrandsSearchRequest.ByFilters, + request: BrandsSearchRequest, resultClass: KClass ): Result { return apiClientHelper.makeObjectPartialResultRequest( diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/impl/CategoriesApiClientImpl.kt b/src/main/kotlin/com/ecwid/apiclient/v3/impl/CategoriesApiClientImpl.kt index 1ae99104..9bdf8090 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/impl/CategoriesApiClientImpl.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/impl/CategoriesApiClientImpl.kt @@ -2,8 +2,6 @@ package com.ecwid.apiclient.v3.impl import com.ecwid.apiclient.v3.ApiClientHelper import com.ecwid.apiclient.v3.CategoriesApiClient -import com.ecwid.apiclient.v3.dto.brand.request.BrandsSearchRequest -import com.ecwid.apiclient.v3.dto.brand.result.BrandsSearchResult import com.ecwid.apiclient.v3.dto.category.request.* import com.ecwid.apiclient.v3.dto.category.result.* import com.ecwid.apiclient.v3.dto.common.PagingResult @@ -114,7 +112,4 @@ internal class CategoriesApiClientImpl( ): Sequence where Result : PartialResult, Result : PagingResult { return fetchPagesAsItemSequence(request) { searchCategoriesByPath(it, resultClass) } } - - override fun getBrands(request: BrandsSearchRequest) = - apiClientHelper.makeObjectResultRequest(request) } diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/entity/BrandsTest.kt b/src/test/kotlin/com/ecwid/apiclient/v3/entity/BrandsTest.kt index 94174fa6..5b740896 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/entity/BrandsTest.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/entity/BrandsTest.kt @@ -34,7 +34,7 @@ class BrandsTest : BaseEntityTest() { ) } - val result = apiClient.getBrands(BrandsSearchRequest.ByFilters()) + val result = apiClient.searchBrands(BrandsSearchRequest.ByFilters()) assertEquals( brandedProductsCreateResult.brandNames, result.items.map { it.name } diff --git a/src/test/resources/test.properties.sample b/src/test/resources/test.properties.sample index 29a05952..a3c3a437 100644 --- a/src/test/resources/test.properties.sample +++ b/src/test/resources/test.properties.sample @@ -1,5 +1,5 @@ # don't use id of store that contains valuable and useful data! tests can modify or even delete store data -storeId= -apiToken= -apiHost=app.ecwid.com +storeId=1754 +apiToken=secret_ZVk1LmWMfv8cnFy6bgQrvnyZSpBGjwsz +apiHost=app.local.ecwid.com apiPort=443 From 0c326224815933f54d9a9240eae8d9bf84b15ce6 Mon Sep 17 00:00:00 2001 From: Alexeyyy Date: Mon, 16 Dec 2024 13:16:24 +0400 Subject: [PATCH 7/9] ECWID-153684 - fixed detekt. --- src/main/kotlin/com/ecwid/apiclient/v3/BrandsApiClient.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/BrandsApiClient.kt b/src/main/kotlin/com/ecwid/apiclient/v3/BrandsApiClient.kt index 5a88d7a8..0e932ab7 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/BrandsApiClient.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/BrandsApiClient.kt @@ -14,7 +14,7 @@ interface BrandsApiClient { } @Suppress("EXTENSION_SHADOWED_BY_MEMBER") -inline fun > BrandsApiClient.searchBrands( +inline fun > BrandsApiClient.searchBrands( request: BrandsSearchRequest ): Result { return searchBrands(request, resultClass = Result::class) From d337a945cfcf06443f9fff58890e81d7eea89013 Mon Sep 17 00:00:00 2001 From: Alexeyyy Date: Mon, 16 Dec 2024 14:00:28 +0400 Subject: [PATCH 8/9] ECWID-153684 - reverted sample properties. --- src/test/resources/test.properties.sample | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/resources/test.properties.sample b/src/test/resources/test.properties.sample index a3c3a437..2e3af6ea 100644 --- a/src/test/resources/test.properties.sample +++ b/src/test/resources/test.properties.sample @@ -1,5 +1,5 @@ # don't use id of store that contains valuable and useful data! tests can modify or even delete store data -storeId=1754 -apiToken=secret_ZVk1LmWMfv8cnFy6bgQrvnyZSpBGjwsz -apiHost=app.local.ecwid.com +storeId= +apiToken= +apiHost= apiPort=443 From ef1bef792146cf63bcd65e5ee5dc8f05e1813d1a Mon Sep 17 00:00:00 2001 From: Alexeyyy Date: Mon, 16 Dec 2024 14:48:57 +0400 Subject: [PATCH 9/9] ECWID-153684 - reverted one more thing. --- src/test/resources/test.properties.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/test.properties.sample b/src/test/resources/test.properties.sample index 2e3af6ea..29a05952 100644 --- a/src/test/resources/test.properties.sample +++ b/src/test/resources/test.properties.sample @@ -1,5 +1,5 @@ # don't use id of store that contains valuable and useful data! tests can modify or even delete store data storeId= apiToken= -apiHost= +apiHost=app.ecwid.com apiPort=443