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

Batch cancel group #327

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ data class CreateBatchRequestWithIds(
val requests: Map<String, ApiRequest> = emptyMap(),
val stopOnFirstFailure: Boolean = true,
val allowParallelMode: Boolean = false,
val groupId: String? = null,
val deduplicationKey: UUID = UUID.randomUUID(),
) : ApiRequest {

override fun toRequestInfo() = RequestInfo.createPostRequest(
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)
Expand All @@ -36,18 +38,20 @@ data class CreateBatchRequest(
val requests: List<ApiRequest> = emptyList(),
val stopOnFirstFailure: Boolean = true,
val allowParallelMode: Boolean = false,
val groupId: String? = null,
val deduplicationKey: UUID = UUID.randomUUID(),
) : ApiRequest {

override fun toRequestInfo() = RequestInfo.createPostRequest(
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)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,6 +22,9 @@ internal class BatchApiClientImpl(
override fun createBatch(request: CreateBatchRequest) =
apiClientHelper.makeObjectResultRequest<CreateBatchResult>(request)

override fun cancelBatchGroup(request: CancelBatchGroupRequest) =
apiClientHelper.makeObjectResultRequest<CancelBatchGroupResult>(request)

override fun getEscapedBatch(request: GetEscapedBatchRequest) =
apiClientHelper.makeObjectResultRequest<GetEscapedBatchResult>(request)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -98,6 +100,9 @@ val otherNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
AllowNullable(FetchedReportResponse.FetchedDataset::comparePeriodEndTimeStamp),
AllowNullable(FetchedReportResponse.FetchedDataset::additionalData),

AllowNullable(CreateBatchRequest::groupId),
AllowNullable(CreateBatchRequestWithIds::groupId),

AllowNullable(InstantSiteRedirectsSearchRequest::keyword),
AllowNullable(InstantSiteRedirectsSearchRequest::limit),
AllowNullable(InstantSiteRedirectsSearchRequest::offset),
Expand Down