-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ECWID-153684 - added new method searchBrands in API Client.
- Loading branch information
Showing
8 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/request/BrandsSearchRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ByFilters> { | ||
override fun toRequestInfo() = RequestInfo.createGetRequest( | ||
pathSegments = listOf( | ||
"brands", | ||
), | ||
params = toParams(), | ||
responseFields = responseFields, | ||
) | ||
|
||
private fun toParams(): Map<String, String> { | ||
val request = this | ||
return mutableMapOf<String, String>().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, | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/result/BrandsSearchResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<FetchedBrand> = listOf(), | ||
val count: Int = 0, | ||
val total: Int = 0, | ||
val limit: Int = 0, | ||
val offset: Int = 0 | ||
) : ApiResultDTO |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/com/ecwid/apiclient/v3/dto/brand/result/FetchedBrand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, String>? = null, | ||
val productsFilteredByBrandUrl: String? = null, | ||
): ApiFetchedDTO, ApiResultDTO { | ||
Check warning Code scanning / detekt Reports spaces around colons Warning
Missing spacing before ":"
|
||
override fun getModifyKind() = ApiFetchedDTO.ModifyKind.ReadOnly | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/com/ecwid/apiclient/v3/impl/BrandsApiClientImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
Check warning Code scanning / detekt Reports spaces around colons Warning
Missing spacing before ":"
|
||
|
||
override fun searchBrands(request: BrandsSearchRequest.ByFilters) = | ||
apiClientHelper.makeObjectResultRequest<BrandsSearchResult>(request) | ||
|
||
override fun <Result : PartialResult<BrandsSearchResult>> searchBrands( | ||
request: BrandsSearchRequest.ByFilters, | ||
resultClass: KClass<Result> | ||
): Result { | ||
return apiClientHelper.makeObjectPartialResultRequest( | ||
request = request, | ||
resultClass = resultClass, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/BrandsSearchRequestRules.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NullablePropertyRule<*, *>> = listOf( | ||
AllowNullable(BrandsSearchRequest.ByFilters::lang), | ||
AllowNullable(BrandsSearchRequest.ByFilters::hiddenBrands), | ||
AllowNullable(BrandsSearchRequest.ByFilters::baseUrl), | ||
AllowNullable(BrandsSearchRequest.ByFilters::cleanUrls), | ||
AllowNullable(BrandsSearchRequest.ByFilters::sortBy), | ||
) |
10 changes: 10 additions & 0 deletions
10
src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedBrandRules.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NullablePropertyRule<*, *>> = listOf( | ||
AllowNullable(FetchedBrand::nameTranslated), | ||
AllowNullable(FetchedBrand::productsFilteredByBrandUrl), | ||
) |