diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt index ec3094825..ff6b012bf 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt @@ -5,9 +5,11 @@ import com.ecwid.apiclient.v3.config.ApiStoreCredentials import com.ecwid.apiclient.v3.config.LoggingSettings import com.ecwid.apiclient.v3.dto.application.request.ApplicationDeleteRequest import com.ecwid.apiclient.v3.dto.application.result.ApplicationDeleteResult +import com.ecwid.apiclient.v3.dto.batch.request.CancelBatchGroupRequest import com.ecwid.apiclient.v3.dto.batch.request.CreateBatchRequest import com.ecwid.apiclient.v3.dto.batch.request.CreateBatchRequestWithIds import com.ecwid.apiclient.v3.dto.batch.request.GetEscapedBatchRequest +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 @@ -264,6 +266,7 @@ interface CustomerGroupsApiClient { interface BatchApiClient { fun createBatch(request: CreateBatchRequestWithIds): CreateBatchResult fun createBatch(request: CreateBatchRequest): CreateBatchResult + fun cancelBatchGroup(request: CancelBatchGroupRequest): CancelBatchGroupResult fun getTypedBatch(request: GetEscapedBatchRequest): GetTypedBatchResult fun getEscapedBatch(request: GetEscapedBatchRequest): GetEscapedBatchResult } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/batch/request/CancelBatchGroupRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/batch/request/CancelBatchGroupRequest.kt new file mode 100644 index 000000000..547060460 --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/batch/request/CancelBatchGroupRequest.kt @@ -0,0 +1,20 @@ +package com.ecwid.apiclient.v3.dto.batch.request + +import com.ecwid.apiclient.v3.dto.ApiRequest +import com.ecwid.apiclient.v3.httptransport.HttpBody +import com.ecwid.apiclient.v3.impl.RequestInfo + +data class CancelBatchGroupRequest( + val groupId: String = "" +) : ApiRequest { + override fun toRequestInfo() = RequestInfo.createPostRequest( + pathSegments = listOf( + "batch", + "cancel-group", + ), + params = mapOf( + "groupId" to groupId, + ), + httpBody = HttpBody.EmptyBody, + ) +} diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/batch/request/CreateBatchRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/batch/request/CreateBatchRequest.kt index 1f619fdf1..77afe429a 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/batch/request/CreateBatchRequest.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/batch/request/CreateBatchRequest.kt @@ -12,6 +12,7 @@ data class CreateBatchRequestWithIds( val requests: Map = emptyMap(), val stopOnFirstFailure: Boolean = true, val allowParallelMode: Boolean = false, + val groupId: String? = null, val deduplicationKey: UUID = UUID.randomUUID(), ) : ApiRequest { @@ -19,11 +20,12 @@ data class CreateBatchRequestWithIds( pathSegments = listOf( "batch" ), - params = mapOf( - "stopOnFirstFailure" to stopOnFirstFailure.toString(), - "allowParallelMode" to allowParallelMode.toString(), - "deduplicationKey" to deduplicationKey.toString(), - ), + params = buildMap { + put("stopOnFirstFailure", stopOnFirstFailure.toString()) + put("allowParallelMode", allowParallelMode.toString()) + put("deduplicationKey", deduplicationKey.toString()) + groupId?.let { put("groupId", it) } + }, httpBody = HttpBody.JsonBody( obj = requests.map { (id, request) -> SingleBatchRequest.create(id, request) @@ -36,6 +38,7 @@ data class CreateBatchRequest( val requests: List = emptyList(), val stopOnFirstFailure: Boolean = true, val allowParallelMode: Boolean = false, + val groupId: String? = null, val deduplicationKey: UUID = UUID.randomUUID(), ) : ApiRequest { @@ -43,11 +46,12 @@ data class CreateBatchRequest( pathSegments = listOf( "batch" ), - params = mapOf( - "stopOnFirstFailure" to stopOnFirstFailure.toString(), - "allowParallelMode" to allowParallelMode.toString(), - "deduplicationKey" to deduplicationKey.toString(), - ), + params = buildMap { + put("stopOnFirstFailure", stopOnFirstFailure.toString()) + put("allowParallelMode", allowParallelMode.toString()) + put("deduplicationKey", deduplicationKey.toString()) + groupId?.let { put("groupId", it) } + }, httpBody = HttpBody.JsonBody( obj = requests.map(SingleBatchRequest.Companion::create) ) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/batch/result/CancelBatchGroupResult.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/batch/result/CancelBatchGroupResult.kt new file mode 100644 index 000000000..ce5c7718e --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/batch/result/CancelBatchGroupResult.kt @@ -0,0 +1,7 @@ +package com.ecwid.apiclient.v3.dto.batch.result + +import com.ecwid.apiclient.v3.dto.common.ApiResultDTO + +data class CancelBatchGroupResult( + val updateCount: Int = 0 +) : ApiResultDTO diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/impl/BatchApiClientImpl.kt b/src/main/kotlin/com/ecwid/apiclient/v3/impl/BatchApiClientImpl.kt index ff15710b0..9fba84f46 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/impl/BatchApiClientImpl.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/impl/BatchApiClientImpl.kt @@ -2,9 +2,11 @@ package com.ecwid.apiclient.v3.impl import com.ecwid.apiclient.v3.ApiClientHelper import com.ecwid.apiclient.v3.BatchApiClient +import com.ecwid.apiclient.v3.dto.batch.request.CancelBatchGroupRequest import com.ecwid.apiclient.v3.dto.batch.request.CreateBatchRequest import com.ecwid.apiclient.v3.dto.batch.request.CreateBatchRequestWithIds import com.ecwid.apiclient.v3.dto.batch.request.GetEscapedBatchRequest +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 @@ -20,6 +22,9 @@ internal class BatchApiClientImpl( override fun createBatch(request: CreateBatchRequest) = apiClientHelper.makeObjectResultRequest(request) + override fun cancelBatchGroup(request: CancelBatchGroupRequest) = + apiClientHelper.makeObjectResultRequest(request) + override fun getEscapedBatch(request: GetEscapedBatchRequest) = apiClientHelper.makeObjectResultRequest(request) 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 d506779e9..6f5aadce4 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt @@ -1,5 +1,7 @@ package com.ecwid.apiclient.v3.rule +import com.ecwid.apiclient.v3.dto.batch.request.CreateBatchRequest +import com.ecwid.apiclient.v3.dto.batch.request.CreateBatchRequestWithIds import com.ecwid.apiclient.v3.dto.batch.result.GetEscapedBatchResult import com.ecwid.apiclient.v3.dto.batch.result.GetTypedBatchResult import com.ecwid.apiclient.v3.dto.cart.result.CartUpdateResult @@ -98,6 +100,9 @@ val otherNullablePropertyRules: List> = listOf( AllowNullable(FetchedReportResponse.FetchedDataset::comparePeriodEndTimeStamp), AllowNullable(FetchedReportResponse.FetchedDataset::additionalData), + AllowNullable(CreateBatchRequest::groupId), + AllowNullable(CreateBatchRequestWithIds::groupId), + AllowNullable(InstantSiteRedirectsSearchRequest::keyword), AllowNullable(InstantSiteRedirectsSearchRequest::limit), AllowNullable(InstantSiteRedirectsSearchRequest::offset),