Skip to content

Commit c25ea96

Browse files
committed
ECWID-153684 - added new method searchBrands in API Client.
1 parent c01e7e2 commit c25ea96

8 files changed

Lines changed: 136 additions & 2 deletions

File tree

src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import com.ecwid.apiclient.v3.dto.batch.result.CancelBatchGroupResult
1515
import com.ecwid.apiclient.v3.dto.batch.result.CreateBatchResult
1616
import com.ecwid.apiclient.v3.dto.batch.result.GetEscapedBatchResult
1717
import com.ecwid.apiclient.v3.dto.batch.result.GetTypedBatchResult
18+
import com.ecwid.apiclient.v3.dto.brand.request.BrandsSearchRequest
19+
import com.ecwid.apiclient.v3.dto.brand.result.BrandsSearchResult
1820
import com.ecwid.apiclient.v3.dto.cart.request.*
1921
import com.ecwid.apiclient.v3.dto.cart.result.*
2022
import com.ecwid.apiclient.v3.dto.common.PartialResult
@@ -26,8 +28,6 @@ import com.ecwid.apiclient.v3.dto.customergroup.request.*
2628
import com.ecwid.apiclient.v3.dto.customergroup.result.*
2729
import com.ecwid.apiclient.v3.dto.instantsite.redirects.request.*
2830
import com.ecwid.apiclient.v3.dto.instantsite.redirects.result.*
29-
import com.ecwid.apiclient.v3.dto.order.request.*
30-
import com.ecwid.apiclient.v3.dto.order.result.*
3131
import com.ecwid.apiclient.v3.dto.productreview.request.*
3232
import com.ecwid.apiclient.v3.dto.productreview.result.*
3333
import com.ecwid.apiclient.v3.dto.producttype.request.*
@@ -55,6 +55,7 @@ import kotlin.reflect.KClass
5555
open class ApiClient private constructor(
5656
protected val apiClientHelper: ApiClientHelper,
5757
storeProfileApiClient: StoreProfileApiClient,
58+
brandsApiClient: BrandsApiClient,
5859
productsApiClient: ProductsApiClient,
5960
categoriesApiClient: CategoriesApiClient,
6061
ordersApiClient: OrdersApiClient,
@@ -76,6 +77,7 @@ open class ApiClient private constructor(
7677
storeExtrafieldsApiClient: StoreExtrafieldsApiClientImpl,
7778
) :
7879
StoreProfileApiClient by storeProfileApiClient,
80+
BrandsApiClient by brandsApiClient,
7981
ProductsApiClient by productsApiClient,
8082
CategoriesApiClient by categoriesApiClient,
8183
OrdersApiClient by ordersApiClient,
@@ -99,6 +101,7 @@ open class ApiClient private constructor(
99101
constructor(apiClientHelper: ApiClientHelper) : this(
100102
apiClientHelper = apiClientHelper,
101103
storeProfileApiClient = StoreProfileApiClientImpl(apiClientHelper),
104+
brandsApiClient = BrandsApiClientImpl(apiClientHelper),
102105
productsApiClient = ProductsApiClientImpl(apiClientHelper),
103106
categoriesApiClient = CategoriesApiClientImpl(apiClientHelper),
104107
ordersApiClient = OrdersApiClientImpl(apiClientHelper),
@@ -315,3 +318,11 @@ interface ProductReviewsApiClient {
315318
fun massUpdateProductReview(request: ProductReviewMassUpdateRequest): ProductReviewMassUpdateResult
316319
fun getProductReviewsFiltersData(request: ProductReviewFiltersDataRequest): ProductReviewFiltersDataResult
317320
}
321+
322+
// Brands
323+
// https://api-docs.ecwid.com/reference/search-product-brands
324+
interface BrandsApiClient {
325+
fun searchBrands(request: BrandsSearchRequest.ByFilters): BrandsSearchResult
326+
fun <Result> searchBrands(request: BrandsSearchRequest.ByFilters, resultClass: KClass<Result>): Result
327+
where Result: PartialResult<BrandsSearchResult>
328+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.ecwid.apiclient.v3.dto.brand.request
2+
3+
import com.ecwid.apiclient.v3.dto.ApiRequest
4+
import com.ecwid.apiclient.v3.dto.common.PagingRequest
5+
import com.ecwid.apiclient.v3.impl.RequestInfo
6+
import com.ecwid.apiclient.v3.responsefields.ResponseFields
7+
8+
sealed class BrandsSearchRequest : ApiRequest {
9+
10+
data class ByFilters(
11+
val limit: Int = 100,
12+
override val offset: Int = 0,
13+
val lang: String? = null,
14+
val hiddenBrands: Boolean? = null,
15+
val baseUrl: String? = null,
16+
val cleanUrls: Boolean? = null,
17+
val sortBy: SortOrder? = null,
18+
val responseFields: ResponseFields = ResponseFields.All,
19+
) : BrandsSearchRequest(), PagingRequest<ByFilters> {
20+
override fun toRequestInfo() = RequestInfo.createGetRequest(
21+
pathSegments = listOf(
22+
"brands",
23+
),
24+
params = toParams(),
25+
responseFields = responseFields,
26+
)
27+
28+
private fun toParams(): Map<String, String> {
29+
val request = this
30+
return mutableMapOf<String, String>().apply {
31+
put("limit", request.limit.toString())
32+
put("offset", request.offset.toString())
33+
request.lang?.let { put("lang", it) }
34+
request.hiddenBrands?.let { put("hiddenBrands", it.toString()) }
35+
request.baseUrl?.let { put("baseUrl", it) }
36+
request.cleanUrls?.let { put("cleanUrls", it.toString()) }
37+
request.sortBy?.let { put("sortBy", it.name) }
38+
}.toMap()
39+
}
40+
41+
override fun copyWithOffset(offset: Int) = copy(offset = offset)
42+
}
43+
44+
@Suppress("unused")
45+
enum class SortOrder {
46+
PRODUCT_COUNT_DESC,
47+
NAME_ASC,
48+
}
49+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.ecwid.apiclient.v3.dto.brand.result
2+
3+
import com.ecwid.apiclient.v3.dto.common.ApiResultDTO
4+
5+
data class BrandsSearchResult(
6+
val items: List<FetchedBrand> = listOf(),
7+
val count: Int = 0,
8+
val total: Int = 0,
9+
val limit: Int = 0,
10+
val offset: Int = 0
11+
) : ApiResultDTO
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.ecwid.apiclient.v3.dto.brand.result
2+
3+
import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO
4+
import com.ecwid.apiclient.v3.dto.common.ApiResultDTO
5+
6+
data class FetchedBrand(
7+
val name: String = "",
8+
val nameTranslated: Map<String, String>? = null,
9+
val productsFilteredByBrandUrl: String? = null,
10+
): ApiFetchedDTO, ApiResultDTO {
11+
override fun getModifyKind() = ApiFetchedDTO.ModifyKind.ReadOnly
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.ecwid.apiclient.v3.impl
2+
3+
import com.ecwid.apiclient.v3.ApiClientHelper
4+
import com.ecwid.apiclient.v3.BrandsApiClient
5+
import com.ecwid.apiclient.v3.dto.brand.request.BrandsSearchRequest
6+
import com.ecwid.apiclient.v3.dto.brand.result.BrandsSearchResult
7+
import com.ecwid.apiclient.v3.dto.common.PartialResult
8+
import kotlin.reflect.KClass
9+
10+
internal class BrandsApiClientImpl(
11+
private val apiClientHelper: ApiClientHelper,
12+
): BrandsApiClient {
13+
14+
override fun searchBrands(request: BrandsSearchRequest.ByFilters) =
15+
apiClientHelper.makeObjectResultRequest<BrandsSearchResult>(request)
16+
17+
override fun <Result : PartialResult<BrandsSearchResult>> searchBrands(
18+
request: BrandsSearchRequest.ByFilters,
19+
resultClass: KClass<Result>
20+
): Result {
21+
return apiClientHelper.makeObjectPartialResultRequest(
22+
request = request,
23+
resultClass = resultClass,
24+
)
25+
}
26+
}

src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ val nullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
200200
productReviewMassUpdateRequestNullablePropertyRules,
201201
productReviewSearchRequestNullablePropertyRules,
202202
fetchedCustomersConfigNullablePropertyRules,
203+
brandsSearchRequestNullablePropertyRules,
204+
fetchedBrandNullablePropertyRules,
203205
).flatten()
204206

205207
sealed class NullablePropertyRule<T, R>(
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.ecwid.apiclient.v3.rule.nullablepropertyrules
2+
3+
import com.ecwid.apiclient.v3.dto.brand.request.BrandsSearchRequest
4+
import com.ecwid.apiclient.v3.rule.NullablePropertyRule
5+
import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable
6+
7+
val brandsSearchRequestNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
8+
AllowNullable(BrandsSearchRequest.ByFilters::lang),
9+
AllowNullable(BrandsSearchRequest.ByFilters::hiddenBrands),
10+
AllowNullable(BrandsSearchRequest.ByFilters::baseUrl),
11+
AllowNullable(BrandsSearchRequest.ByFilters::cleanUrls),
12+
AllowNullable(BrandsSearchRequest.ByFilters::sortBy),
13+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.ecwid.apiclient.v3.rule.nullablepropertyrules
2+
3+
import com.ecwid.apiclient.v3.dto.brand.result.FetchedBrand
4+
import com.ecwid.apiclient.v3.rule.NullablePropertyRule
5+
import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable
6+
7+
val fetchedBrandNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
8+
AllowNullable(FetchedBrand::nameTranslated),
9+
AllowNullable(FetchedBrand::productsFilteredByBrandUrl),
10+
)

0 commit comments

Comments
 (0)