Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECWID-124685 the datatype for groups has been changed to allow a list… #310

Merged
merged 11 commits into from
Sep 4, 2023
Merged
2 changes: 2 additions & 0 deletions src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ interface CustomersApiClient {
fun searchDeletedCustomersAsSequence(request: DeletedCustomersSearchRequest): Sequence<DeletedCustomer>
fun searchCustomersProducts(request: CustomersProductsSearchRequest): CustomersProductsSearchResult
fun searchCustomersLocations(request: CustomersLocationsSearchRequest): CustomersLocationsSearchResult
fun searchCustomersFilters(request: CustomerFiltersDataSearchRequest): CustomersFiltersDataSearchResult
fun massUpdate(request: CustomersMassUpdateRequest): CustomerUpdateResult
}

// Customer groups
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ecwid.apiclient.v3.dto.customer.enums

enum class SelectMode {
SELECTED,
ALL_FILTERED,
ALL;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ecwid.apiclient.v3.dto.customer.request

import com.ecwid.apiclient.v3.dto.ApiRequest
import com.ecwid.apiclient.v3.impl.RequestInfo

class CustomerFiltersDataSearchRequest : ApiRequest {
override fun toRequestInfo() = RequestInfo.createGetRequest(
pathSegments = listOf(
"customers",
"filters",
),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.ecwid.apiclient.v3.dto.customer.request

import com.ecwid.apiclient.v3.dto.ApiRequest
import com.ecwid.apiclient.v3.httptransport.HttpBody
import com.ecwid.apiclient.v3.impl.RequestInfo

data class CustomersMassUpdateRequest(
val keyword: String? = null,
val minOrderCount: Int? = null,
val maxOrderCount: Int? = null,
val minSalesValue: Int? = null,
val maxSalesValue: Int? = null,
val taxExempt: Boolean? = null,
val acceptMarketing: Boolean? = null,
val purchasedProductIds: String? = null,
val customerGroupIds: String? = null,
val countryCodes: String? = null,
val lang: String? = null,
val customer: MassUpdateCustomer = MassUpdateCustomer()
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createPostRequest(
pathSegments = listOf(
"customers_update"
),
params = toParams(),
httpBody = HttpBody.JsonBody(
obj = customer
)
)

private fun toParams(): Map<String, String> {
val request = this
return mutableMapOf<String, String>().apply {
request.keyword?.let { put("keyword", it) }
request.minOrderCount?.let { put("minOrderCount", it.toString()) }
request.maxOrderCount?.let { put("maxOrderCount", it.toString()) }
request.minSalesValue?.let { put("minSalesValue", it.toString()) }
request.maxSalesValue?.let { put("maxSalesValue", it.toString()) }
request.taxExempt?.let { put("taxExempt", it.toString()) }
request.acceptMarketing?.let { put("acceptMarketing", it.toString()) }
request.purchasedProductIds?.let { put("purchasedProductIds", it) }
request.customerGroupIds?.let { put("customerGroupIds", it) }
request.countryCodes?.let { put("countryCodes", it) }
request.lang?.let { put("lang", it) }
}.toMap()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ data class CustomersSearchRequest(
val maxSalesValue: Int? = null,
val taxExempt: Boolean? = null,
val acceptMarketing: Boolean? = null,
val purchasedProductId: String? = null,
val countryCode: String? = null,
val purchasedProductIds: String? = null,
val customerGroupIds: String? = null,
val countryCodes: String? = null,
val createdFrom: Date? = null,
val createdTo: Date? = null,
val updatedFrom: Date? = null,
Expand Down Expand Up @@ -73,8 +74,9 @@ data class CustomersSearchRequest(
request.updatedTo?.let { put("updatedTo", TimeUnit.MILLISECONDS.toSeconds(it.time).toString()) }
request.taxExempt?.let { put("taxExempt", it.toString()) }
request.acceptMarketing?.let { put("acceptMarketing", it.toString()) }
request.purchasedProductId?.let { put("purchasedProductId", it) }
request.countryCode?.let { put("countryCode", it) }
request.purchasedProductIds?.let { put("purchasedProductIds", it) }
request.customerGroupIds?.let { put("customerGroupIds", it) }
request.countryCodes?.let { put("countryCodes", it) }
request.lang?.let { put("lang", it) }
request.sortBy?.let { put("sortBy", it.name) }
put("offset", request.offset.toString())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.ecwid.apiclient.v3.dto.customer.request

import com.ecwid.apiclient.v3.dto.common.ApiRequestDTO
import com.ecwid.apiclient.v3.dto.customer.enums.SelectMode

data class MassUpdateCustomer(
val ids: List<Int>? = null,
val mode: SelectMode = SelectMode.ALL,
val delete: Boolean? = null,
val customer: UpdatedCustomer? = null
) : ApiRequestDTO {

data class UpdatedCustomer(
val customerGroupId: Int? = null,
val taxExempt: Boolean? = null,
val acceptMarketing: Boolean? = null,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.ecwid.apiclient.v3.dto.customer.result

import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO

data class CustomerFilterGroup(
val id: Int = 0,
val name: String = "General"
) : ApiFetchedDTO {
override fun getModifyKind() = ApiFetchedDTO.ModifyKind.ReadOnly
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.ecwid.apiclient.v3.dto.customer.result

import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO

data class CustomerFilterShippingAddress(
val street: String? = null,
val city: String? = null,
val countryCode: String? = null,
val countryName: String? = null,
) : ApiFetchedDTO {
override fun getModifyKind() = ApiFetchedDTO.ModifyKind.ReadOnly
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ecwid.apiclient.v3.dto.customer.result

import com.ecwid.apiclient.v3.dto.common.ApiResultDTO

data class CustomersFiltersDataSearchResult(
val total: Int = 0,
val storeGroups: List<CustomerFilterGroup> = listOf(),
val customerGroups: List<CustomerFilterGroup> = listOf(),
val shippingAddresses: List<CustomerFilterShippingAddress> = listOf(),
val languages: List<String> = listOf(),
) : ApiResultDTO
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ internal data class CustomersApiClientImpl(

override fun searchCustomersLocations(request: CustomersLocationsSearchRequest) =
apiClientHelper.makeObjectResultRequest<CustomersLocationsSearchResult>(request)

override fun searchCustomersFilters(request: CustomerFiltersDataSearchRequest) =
apiClientHelper.makeObjectResultRequest<CustomersFiltersDataSearchResult>(request)

override fun massUpdate(request: CustomersMassUpdateRequest) =
apiClientHelper.makeObjectResultRequest<CustomerUpdateResult>(request)

}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ val nullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
couponSearchRequestNullablePropertyRules,
customAppRequestNullablePropertyRules,
customersSearchRequestNullablePropertyRules,
customersMassUpdatedRequestNullablePropertyRules,
deletedCustomersSearchRequestNullablePropertyRules,
deletedOrdersSearchRequestNullablePropertyRules,
deletedProductsSearchRequestNullablePropertyRules,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.ecwid.apiclient.v3.rule.nullablepropertyrules

import com.ecwid.apiclient.v3.dto.customer.request.CustomersMassUpdateRequest
import com.ecwid.apiclient.v3.dto.customer.request.MassUpdateCustomer
import com.ecwid.apiclient.v3.rule.NullablePropertyRule
import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable


val customersMassUpdatedRequestNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(

AllowNullable(CustomersMassUpdateRequest::keyword),
AllowNullable(CustomersMassUpdateRequest::maxOrderCount),
AllowNullable(CustomersMassUpdateRequest::minOrderCount),
AllowNullable(CustomersMassUpdateRequest::maxSalesValue),
AllowNullable(CustomersMassUpdateRequest::minSalesValue),
AllowNullable(CustomersMassUpdateRequest::purchasedProductIds),
AllowNullable(CustomersMassUpdateRequest::customerGroupIds),
AllowNullable(CustomersMassUpdateRequest::countryCodes),
AllowNullable(CustomersMassUpdateRequest::taxExempt),
AllowNullable(CustomersMassUpdateRequest::acceptMarketing),
AllowNullable(CustomersMassUpdateRequest::lang),

AllowNullable(MassUpdateCustomer::ids),
AllowNullable(MassUpdateCustomer::delete),
AllowNullable(MassUpdateCustomer::customer),

AllowNullable(MassUpdateCustomer.UpdatedCustomer::customerGroupId),
AllowNullable(MassUpdateCustomer.UpdatedCustomer::taxExempt),
AllowNullable(MassUpdateCustomer.UpdatedCustomer::acceptMarketing),
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ val customersSearchRequestNullablePropertyRules: List<NullablePropertyRule<*, *>
AllowNullable(CustomersSearchRequest::sortBy),
AllowNullable(CustomersSearchRequest::updatedFrom),
AllowNullable(CustomersSearchRequest::updatedTo),
AllowNullable(CustomersSearchRequest::purchasedProductId),
AllowNullable(CustomersSearchRequest::countryCode),
AllowNullable(CustomersSearchRequest::purchasedProductIds),
AllowNullable(CustomersSearchRequest::customerGroupIds),
AllowNullable(CustomersSearchRequest::countryCodes),
AllowNullable(CustomersSearchRequest::taxExempt),
AllowNullable(CustomersSearchRequest::acceptMarketing),
AllowNullable(CustomersSearchRequest::lang),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ecwid.apiclient.v3.rule.nullablepropertyrules

import com.ecwid.apiclient.v3.dto.customer.result.CustomerFilterShippingAddress
import com.ecwid.apiclient.v3.dto.customer.result.FetchedCustomer
import com.ecwid.apiclient.v3.rule.NullablePropertyRule
import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable
Expand Down Expand Up @@ -51,4 +52,9 @@ val fetchedCustomerNullablePropertyRules: List<NullablePropertyRule<*, *>> = lis
AllowNullable(FetchedCustomer.CustomerContact::handle),
AllowNullable(FetchedCustomer.CustomerContact::note),
AllowNullable(FetchedCustomer.CustomerContact::timestamp),

AllowNullable(CustomerFilterShippingAddress::street),
AllowNullable(CustomerFilterShippingAddress::city),
AllowNullable(CustomerFilterShippingAddress::countryCode),
AllowNullable(CustomerFilterShippingAddress::countryName),
)