Skip to content

Commit

Permalink
ECWID-141762 merge remote-tracking branch 'origin/master' into ECWID-…
Browse files Browse the repository at this point in the history
…141762
  • Loading branch information
n-viktorovich committed Aug 8, 2024
2 parents 0f23e56 + 804bef0 commit d7a48ac
Show file tree
Hide file tree
Showing 48 changed files with 443 additions and 56 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
25 changes: 7 additions & 18 deletions src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import com.ecwid.apiclient.v3.dto.productreview.request.*
import com.ecwid.apiclient.v3.dto.productreview.result.*
import com.ecwid.apiclient.v3.dto.producttype.request.*
import com.ecwid.apiclient.v3.dto.producttype.result.*
import com.ecwid.apiclient.v3.dto.report.request.ReportAdviceRequest
import com.ecwid.apiclient.v3.dto.report.request.ReportRequest
import com.ecwid.apiclient.v3.dto.report.result.FetchedReportAdviceResponse
import com.ecwid.apiclient.v3.dto.report.result.FetchedReportResponse
import com.ecwid.apiclient.v3.dto.saleschannels.request.*
import com.ecwid.apiclient.v3.dto.saleschannels.response.*
Expand Down Expand Up @@ -71,6 +73,7 @@ open class ApiClient private constructor(
instantSiteRedirectsApiClient: InstantSiteRedirectsApiClientImpl,
slugInfoApiClient: SlugInfoApiClientImpl,
productReviewsApiClient: ProductReviewsApiClientImpl,
storeExtrafieldsApiClient: StoreExtrafieldsApiClientImpl,
) :
StoreProfileApiClient by storeProfileApiClient,
ProductsApiClient by productsApiClient,
Expand All @@ -90,7 +93,8 @@ open class ApiClient private constructor(
SubscriptionsApiClient by subscriptionsApiClient,
InstantSiteRedirectsApiClient by instantSiteRedirectsApiClient,
SlugInfoApiClient by slugInfoApiClient,
ProductReviewsApiClient by productReviewsApiClient {
ProductReviewsApiClient by productReviewsApiClient,
StoreExtrafieldsApiClient by storeExtrafieldsApiClient {

constructor(apiClientHelper: ApiClientHelper) : this(
apiClientHelper = apiClientHelper,
Expand All @@ -113,6 +117,7 @@ open class ApiClient private constructor(
instantSiteRedirectsApiClient = InstantSiteRedirectsApiClientImpl(apiClientHelper),
slugInfoApiClient = SlugInfoApiClientImpl(apiClientHelper),
productReviewsApiClient = ProductReviewsApiClientImpl(apiClientHelper),
storeExtrafieldsApiClient = StoreExtrafieldsApiClientImpl(apiClientHelper),
)

companion object {
Expand All @@ -136,23 +141,6 @@ open class ApiClient private constructor(
}
}

// Orders
// https://developers.ecwid.com/api-documentation/orders
interface OrdersApiClient {
fun searchOrders(request: OrdersSearchRequest): OrdersSearchResult
fun searchOrdersAsSequence(request: OrdersSearchRequest): Sequence<FetchedOrder>
fun getOrderDetails(request: OrderDetailsRequest): FetchedOrder
fun getOrderInvoice(request: OrderInvoiceRequest): String
fun createOrder(request: OrderCreateRequest): OrderCreateResult
fun updateOrder(request: OrderUpdateRequest): OrderUpdateResult
fun deleteOrder(request: OrderDeleteRequest): OrderDeleteResult
fun uploadOrderItemOptionFile(request: OrderItemOptionFileUploadRequest): OrderItemOptionFileUploadResult
fun deleteOrderItemOptionFile(request: OrderItemOptionFileDeleteRequest): OrderItemOptionFileDeleteResult
fun deleteOrderItemOptionFiles(request: OrderItemOptionFilesDeleteRequest): OrderItemOptionFileDeleteResult
fun searchDeletedOrders(request: DeletedOrdersSearchRequest): DeletedOrdersSearchResult
fun searchDeletedOrdersAsSequence(request: DeletedOrdersSearchRequest): Sequence<DeletedOrder>
}

// Product types
// https://developers.ecwid.com/api-documentation/product-types
interface ProductTypesApiClient {
Expand Down Expand Up @@ -294,6 +282,7 @@ interface ApplicationStorageApiClient {
// Report API
interface ReportsApiClient {
fun fetchReport(request: ReportRequest): FetchedReportResponse
fun getReportAdvice(request: ReportAdviceRequest): FetchedReportAdviceResponse
}

// Recurring subscriptions
Expand Down
30 changes: 30 additions & 0 deletions src/main/kotlin/com/ecwid/apiclient/v3/OrdersApiClient.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.ecwid.apiclient.v3

import com.ecwid.apiclient.v3.dto.common.PartialResult
import com.ecwid.apiclient.v3.dto.order.request.*
import com.ecwid.apiclient.v3.dto.order.result.*
import kotlin.reflect.KClass

// Orders
// https://developers.ecwid.com/api-documentation/orders
interface OrdersApiClient {
fun searchOrders(request: OrdersSearchRequest): OrdersSearchResult
fun <Result> searchOrders(request: OrdersSearchRequest, resultClass: KClass<Result>): Result
where Result : PartialResult<OrdersSearchResult>
fun searchOrdersAsSequence(request: OrdersSearchRequest): Sequence<FetchedOrder>
fun getOrderDetails(request: OrderDetailsRequest): FetchedOrder
fun getOrderInvoice(request: OrderInvoiceRequest): String
fun createOrder(request: OrderCreateRequest): OrderCreateResult
fun updateOrder(request: OrderUpdateRequest): OrderUpdateResult
fun deleteOrder(request: OrderDeleteRequest): OrderDeleteResult
fun uploadOrderItemOptionFile(request: OrderItemOptionFileUploadRequest): OrderItemOptionFileUploadResult
fun deleteOrderItemOptionFile(request: OrderItemOptionFileDeleteRequest): OrderItemOptionFileDeleteResult
fun deleteOrderItemOptionFiles(request: OrderItemOptionFilesDeleteRequest): OrderItemOptionFileDeleteResult
fun searchDeletedOrders(request: DeletedOrdersSearchRequest): DeletedOrdersSearchResult
fun searchDeletedOrdersAsSequence(request: DeletedOrdersSearchRequest): Sequence<DeletedOrder>
}

@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified Result : PartialResult<OrdersSearchResult>> OrdersApiClient.searchOrders(request: OrdersSearchRequest): Result {
return searchOrders(request, Result::class)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ecwid.apiclient.v3

import com.ecwid.apiclient.v3.dto.extrafield.request.*
import com.ecwid.apiclient.v3.dto.extrafield.result.*


interface StoreExtrafieldsApiClient {
fun searchCustomersConfigs(request: CustomersConfigsSearchRequest): CustomersConfigsSearchResult
fun getCustomersConfig(request: CustomersConfigDetailsRequest): FetchedCustomersConfig
fun createCustomersConfig(request: CustomersConfigCreateRequest): CustomersConfigCreateResult
fun updateCustomersConfig(request: CustomersConfigUpdateRequest): CustomersConfigUpdateResult
fun deleteCustomersConfig(request: CustomersConfigDeleteRequest): CustomersConfigDeleteResult
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ interface StoreProfileApiClient {
fun updateExtrafieldConfig(request: ExtrafieldConfigUpdateRequest): ExtrafieldConfigUpdateResult
fun deleteExtrafieldConfig(request: ExtrafieldConfigDeleteRequest): ExtrafieldConfigDeleteResult
fun searchOrderStatusesSettings(request: OrderStatusSettingsSearchRequest): OrderStatusSettingsSearchResult
fun <Result> searchOrderStatusesSettings(request: OrderStatusSettingsSearchRequest, resultClass: KClass<Result>): Result
where Result : PartialResult<OrderStatusSettingsSearchResult>
fun getOrderStatusSettingsDetails(request: OrderStatusSettingsDetailsRequest): FetchedOrderStatusSettings
fun updateOrderStatusSettings(request: OrderStatusSettingsUpdateRequest): OrderStatusSettingsUpdateResult
}
Expand All @@ -43,3 +45,8 @@ interface StoreProfileApiClient {
inline fun <reified Result : PartialResult<FetchedStoreProfile>> StoreProfileApiClient.getStoreProfile(request: StoreProfileRequest): Result {
return getStoreProfile(request, Result::class)
}

@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
inline fun <reified Result : PartialResult<OrderStatusSettingsSearchResult>> StoreProfileApiClient.searchOrderStatusesSettings(request: OrderStatusSettingsSearchRequest): Result {
return searchOrderStatusesSettings(request, Result::class)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fun FetchedCustomer.toUpdated(): UpdatedCustomer {
lang = lang,
privateAdminNotes = privateAdminNotes,
commercialRelationshipScheme = commercialRelationshipScheme,
extrafields = extrafields?.map(FetchedCustomer.CustomerExtrafield::toUpdated)
)
}

Expand Down Expand Up @@ -61,3 +62,12 @@ fun FetchedCustomer.CustomerContact.toUpdated(): UpdatedCustomer.CustomerContact
orderBy = orderBy,
)
}

fun FetchedCustomer.CustomerExtrafield.toUpdated(): UpdatedCustomer.CustomerExtrafield {
return UpdatedCustomer.CustomerExtrafield(
key = key,
title = title,
value = value,
type = type,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.ecwid.apiclient.v3.converter

import com.ecwid.apiclient.v3.dto.extrafield.request.UpdatedCustomersConfig
import com.ecwid.apiclient.v3.dto.extrafield.result.FetchedCustomersConfig


fun FetchedCustomersConfig.toUpdated(): UpdatedCustomersConfig {
return UpdatedCustomersConfig(
key = key,
title = title,
type = type,
shownOnOrderDetails = shownOnOrderDetails,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fun FetchedProduct.toUpdated(): UpdatedProduct {
description = description,
descriptionTranslated = descriptionTranslated,
sku = sku,
customSlug = customSlug,

enabled = enabled,
quantity = quantity,
Expand Down Expand Up @@ -55,6 +56,7 @@ fun FetchedProduct.toUpdated(): UpdatedProduct {

media = media?.toUpdated(),

discountsAllowed = discountsAllowed,
subtitle = subtitle,
ribbon = ribbon?.toUpdated(),
ribbonTranslated = ribbonTranslated,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ data class CustomersSearchRequest(
val name: String? = null,
val email: String? = null,
val customerGroupId: Int? = null,
val usePrecalculatedOrderCount: Boolean? = null,
val minOrderCount: Int? = null,
val maxOrderCount: Int? = null,
val minSalesValue: Int? = null,
Expand Down Expand Up @@ -70,6 +71,7 @@ data class CustomersSearchRequest(
request.name?.let { put("name", it) }
request.email?.let { put("email", it) }
request.customerGroupId?.let { put("customerGroup", it.toString()) }
request.usePrecalculatedOrderCount?.let { put("usePrecalculatedOrderCount", it.toString()) }
request.minOrderCount?.let { put("minOrderCount", it.toString()) }
request.maxOrderCount?.let { put("maxOrderCount", it.toString()) }
request.minSalesValue?.let { put("minSalesValue", it.toString()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO.ModifyKind
import com.ecwid.apiclient.v3.dto.customer.enums.CommercialRelationshipScheme
import com.ecwid.apiclient.v3.dto.customer.result.FetchedCustomer
import com.ecwid.apiclient.v3.dto.extrafield.enums.ExtrafieldType
import com.ecwid.apiclient.v3.jsontransformer.JsonFieldName

data class UpdatedCustomer(
Expand All @@ -19,6 +20,7 @@ data class UpdatedCustomer(
val acceptMarketing: Boolean? = null,
val lang: String? = null,
val privateAdminNotes: String? = null,
val extrafields: List<CustomerExtrafield>? = null,

@JsonFieldName("b2b_b2c")
val commercialRelationshipScheme: CommercialRelationshipScheme? = null,
Expand Down Expand Up @@ -60,5 +62,12 @@ data class UpdatedCustomer(
val orderBy: Int? = null,
)

data class CustomerExtrafield(
val key: String? = null,
val title: String? = null,
val value: String? = null,
val type: ExtrafieldType? = null,
)

override fun getModifyKind() = ModifyKind.ReadWrite(FetchedCustomer::class)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO
import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO.ModifyKind
import com.ecwid.apiclient.v3.dto.customer.enums.CommercialRelationshipScheme
import com.ecwid.apiclient.v3.dto.customer.request.UpdatedCustomer
import com.ecwid.apiclient.v3.dto.extrafield.enums.ExtrafieldEntityType
import com.ecwid.apiclient.v3.dto.extrafield.enums.ExtrafieldType
import com.ecwid.apiclient.v3.jsontransformer.JsonFieldName
import java.util.*
import kotlin.collections.ArrayList

data class FetchedCustomer(
val id: Int = 0,
Expand All @@ -26,6 +27,7 @@ data class FetchedCustomer(
val stats: CustomerStats? = null,
val privateAdminNotes: String? = null,
val favorites: List<CustomerFavorite> = ArrayList(),
val extrafields: List<CustomerExtrafield>? = null,

@JsonFieldName("b2b_b2c")
val commercialRelationshipScheme: CommercialRelationshipScheme = CommercialRelationshipScheme.b2c,
Expand Down Expand Up @@ -89,5 +91,14 @@ data class FetchedCustomer(
val addedTimestamp: Date? = null,
)

data class CustomerExtrafield(
val key: String? = null,
val title: String? = null,
val value: String? = null,
val orderBy: Int = 0,
val type: ExtrafieldType? = null,
val entityTypes: List<ExtrafieldEntityType> = emptyList(),
)

override fun getModifyKind() = ModifyKind.ReadWrite(UpdatedCustomer::class)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.ecwid.apiclient.v3.dto.extrafield.enums

enum class ExtrafieldEntityType {
CHECKOUT,
CUSTOMERS,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ecwid.apiclient.v3.dto.profile.enums
package com.ecwid.apiclient.v3.dto.extrafield.enums

enum class ExtrafieldType {
TEXT,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.ecwid.apiclient.v3.dto.extrafield.request

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

data class CustomersConfigCreateRequest(
val newConfig: UpdatedCustomersConfig = UpdatedCustomersConfig()
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createPostRequest(
pathSegments = listOf(
"store_extrafields",
"customers"
),
httpBody = HttpBody.JsonBody(
obj = newConfig
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ecwid.apiclient.v3.dto.extrafield.request

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

data class CustomersConfigDeleteRequest(
val extrafieldKey: String = ""
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createDeleteRequest(
pathSegments = listOf(
"store_extrafields",
"customers",
extrafieldKey
),
params = mapOf()
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ecwid.apiclient.v3.dto.extrafield.request

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

data class CustomersConfigDetailsRequest(
val extrafieldKey: String = "",
val responseFields: ResponseFields = ResponseFields.All,
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createGetRequest(
pathSegments = listOf(
"store_extrafields",
"customers",
extrafieldKey
),
params = mapOf(),
responseFields = responseFields,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ecwid.apiclient.v3.dto.extrafield.request

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

data class CustomersConfigUpdateRequest(
val extrafieldKey: String = "",
val updatedConfig: UpdatedCustomersConfig = UpdatedCustomersConfig()
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createPutRequest(
pathSegments = listOf(
"store_extrafields",
"customers",
extrafieldKey
),
httpBody = HttpBody.JsonBody(
obj = updatedConfig
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.ecwid.apiclient.v3.dto.extrafield.request

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


data class CustomersConfigsSearchRequest(
val responseFields: ResponseFields = ResponseFields.All,
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createGetRequest(
pathSegments = listOf(
"store_extrafields",
"customers"
),
params = mapOf(),
responseFields = responseFields,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.ecwid.apiclient.v3.dto.extrafield.request

import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO.ModifyKind
import com.ecwid.apiclient.v3.dto.extrafield.enums.ExtrafieldType
import com.ecwid.apiclient.v3.dto.extrafield.result.FetchedCustomersConfig

data class UpdatedCustomersConfig(
val key: String? = null,
val title: String? = null,
val type: ExtrafieldType? = null,
val shownOnOrderDetails: Boolean? = null,
) : ApiUpdatedDTO {

override fun getModifyKind() = ModifyKind.ReadWrite(FetchedCustomersConfig::class)
}
Loading

0 comments on commit d7a48ac

Please sign in to comment.