Skip to content

Commit

Permalink
Merge pull request #378 from Ecwid/ECWID-135161-reviews-api
Browse files Browse the repository at this point in the history
ECWID-135161 Added mass update method for product reviews
  • Loading branch information
kitty-ecwid authored Mar 14, 2024
2 parents 5cc2d7d + 153c037 commit 1ac0ec2
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 25 deletions.
6 changes: 4 additions & 2 deletions src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,11 @@ interface SlugInfoApiClient {

// Product reviews
interface ProductReviewsApiClient {
fun searchProductReviews(request: ProductReviewsSearchRequest): ProductReviewSearchResult
fun searchProductReviewsAsSequence(request: ProductReviewsSearchRequest): Sequence<FetchedProductReview>
fun searchProductReviews(request: ProductReviewSearchRequest): ProductReviewSearchResult
fun searchProductReviewsAsSequence(request: ProductReviewSearchRequest): Sequence<FetchedProductReview>
fun getProductReviewDetails(request: ProductReviewDetailsRequest): FetchedProductReview
fun updateProductReviewStatus(request: ProductReviewUpdateStatusRequest): ProductReviewUpdateStatusResult
fun deleteProductReview(request: ProductReviewDeleteRequest): ProductReviewDeleteResult
fun massUpdateProductReview(request: ProductReviewMassUpdateRequest): ProductReviewMassUpdateResult
fun getProductReviewsFiltersData(request: ProductReviewFiltersDataRequest): ProductReviewFiltersDataResult
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ecwid.apiclient.v3.dto.productreview.enums

enum class ProductReviewSelectMode {
SELECTED,
ALL_FILTERED,
ALL,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ecwid.apiclient.v3.dto.productreview.request

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

data class ProductReviewFiltersDataRequest(
val responseFields: ResponseFields = ResponseFields.All,
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createGetRequest(
pathSegments = listOf(
"reviews",
"filters_data",
),
responseFields = responseFields,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.ecwid.apiclient.v3.dto.productreview.request

import com.ecwid.apiclient.v3.dto.common.ApiRequestDTO
import com.ecwid.apiclient.v3.dto.productreview.enums.ProductReviewSelectMode
import com.ecwid.apiclient.v3.dto.productreview.enums.ProductReviewStatus
import java.time.Instant

data class ProductReviewMassUpdate(
val reviewIds: List<Long>? = null,
val selectMode: ProductReviewSelectMode? = null,
val delete: Boolean = false,
val newStatus: ProductReviewStatus? = null,
val filters: Filters? = null,
) : ApiRequestDTO {

data class Filters(
val reviewId: String? = null,
val productId: String? = null,
val orderId: String? = null,
val status: ProductReviewStatus? = null,
val rating: Int? = null,
val createdFrom: Instant? = null,
val createdTo: Instant? = null,
val searchKeyword: String? = null,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ecwid.apiclient.v3.dto.productreview.request

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

data class ProductReviewMassUpdateRequest(
val updateInfo: ProductReviewMassUpdate = ProductReviewMassUpdate(),
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createPutRequest(
pathSegments = listOf(
"reviews",
"mass_update",
),
params = mapOf(),
httpBody = HttpBody.JsonBody(
obj = updateInfo
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.ecwid.apiclient.v3.responsefields.ResponseFields
import java.time.Instant
import java.util.concurrent.TimeUnit

data class ProductReviewsSearchRequest(
data class ProductReviewSearchRequest(
val reviewId: String? = null,
val productId: String? = null,
val orderId: String? = null,
Expand All @@ -19,11 +19,12 @@ data class ProductReviewsSearchRequest(
val createdTo: Instant? = null,
val updatedFrom: Instant? = null,
val updatedTo: Instant? = null,
val searchKeyword: String? = null,
val sortBy: ProductReviewSortOrder? = null,
val limit: Int = 100,
override val offset: Int = 0,
val responseFields: ResponseFields = ResponseFields.All,
) : ApiRequest, PagingRequest<ProductReviewsSearchRequest> {
) : ApiRequest, PagingRequest<ProductReviewSearchRequest> {
override fun toRequestInfo() = RequestInfo.createGetRequest(
pathSegments = listOf(
"reviews"
Expand All @@ -44,6 +45,7 @@ data class ProductReviewsSearchRequest(
request.createdTo?.let { put("createdTo", TimeUnit.MILLISECONDS.toSeconds(it.toEpochMilli()).toString()) }
request.updatedFrom?.let { put("updatedFrom", TimeUnit.MILLISECONDS.toSeconds(it.toEpochMilli()).toString()) }
request.updatedTo?.let { put("updatedTo", TimeUnit.MILLISECONDS.toSeconds(it.toEpochMilli()).toString()) }
request.searchKeyword?.let { put("searchKeyword", it) }
request.sortBy?.let { put("sortBy", it.name) }
put("offset", request.offset.toString())
put("limit", request.limit.toString())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.ecwid.apiclient.v3.dto.productreview.result

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

data class ProductReviewFiltersDataResult(
val allCount: Int = 0,
val moderatedCount: Int = 0,
val publishedCount: Int = 0,
) : ApiResultDTO
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ecwid.apiclient.v3.dto.productreview.result

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

data class ProductReviewMassUpdateResult(
val updateCount: Int = 0
) : ApiResultDTO
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import com.ecwid.apiclient.v3.dto.productreview.result.*
class ProductReviewsApiClientImpl(
private val apiClientHelper: ApiClientHelper,
) : ProductReviewsApiClient {
override fun searchProductReviews(request: ProductReviewsSearchRequest) =
override fun searchProductReviews(request: ProductReviewSearchRequest) =
apiClientHelper.makeObjectResultRequest<ProductReviewSearchResult>(request)

override fun searchProductReviewsAsSequence(request: ProductReviewsSearchRequest) =
override fun searchProductReviewsAsSequence(request: ProductReviewSearchRequest) =
apiClientHelper.makeObjectResultRequest<Sequence<FetchedProductReview>>(request)

override fun getProductReviewDetails(request: ProductReviewDetailsRequest) =
Expand All @@ -22,4 +22,11 @@ class ProductReviewsApiClientImpl(

override fun deleteProductReview(request: ProductReviewDeleteRequest) =
apiClientHelper.makeObjectResultRequest<ProductReviewDeleteResult>(request)

override fun massUpdateProductReview(request: ProductReviewMassUpdateRequest) =
apiClientHelper.makeObjectResultRequest<ProductReviewMassUpdateResult>(request)

override fun getProductReviewsFiltersData(request: ProductReviewFiltersDataRequest) =
apiClientHelper.makeObjectResultRequest<ProductReviewFiltersDataResult>(request)

}
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ val nullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
fetchedSlugInfoClassesNullablePropertyRules,
slugInfoRequestNullablePropertyRules,
fetchedProductReviewNullablePropertyRules,
productReviewsSearchRequestNullablePropertyRules,
productReviewMassUpdateRequestNullablePropertyRules,
productReviewSearchRequestNullablePropertyRules,
).flatten()

sealed class NullablePropertyRule<T, R>(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ecwid.apiclient.v3.rule.nullablepropertyrules

import com.ecwid.apiclient.v3.dto.productreview.request.ProductReviewMassUpdate
import com.ecwid.apiclient.v3.rule.NullablePropertyRule
import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable

val productReviewMassUpdateRequestNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
AllowNullable(ProductReviewMassUpdate.Filters::createdFrom),
AllowNullable(ProductReviewMassUpdate.Filters::createdTo),
AllowNullable(ProductReviewMassUpdate.Filters::orderId),
AllowNullable(ProductReviewMassUpdate.Filters::productId),
AllowNullable(ProductReviewMassUpdate.Filters::rating),
AllowNullable(ProductReviewMassUpdate.Filters::reviewId),
AllowNullable(ProductReviewMassUpdate.Filters::searchKeyword),
AllowNullable(ProductReviewMassUpdate.Filters::status),
AllowNullable(ProductReviewMassUpdate::filters),
AllowNullable(ProductReviewMassUpdate::newStatus),
AllowNullable(ProductReviewMassUpdate::reviewIds),
AllowNullable(ProductReviewMassUpdate::selectMode),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.ecwid.apiclient.v3.rule.nullablepropertyrules

import com.ecwid.apiclient.v3.dto.productreview.request.ProductReviewSearchRequest
import com.ecwid.apiclient.v3.rule.NullablePropertyRule
import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable

val productReviewSearchRequestNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
AllowNullable(ProductReviewSearchRequest::createdFrom),
AllowNullable(ProductReviewSearchRequest::createdTo),
AllowNullable(ProductReviewSearchRequest::orderId),
AllowNullable(ProductReviewSearchRequest::productId),
AllowNullable(ProductReviewSearchRequest::rating),
AllowNullable(ProductReviewSearchRequest::reviewId),
AllowNullable(ProductReviewSearchRequest::searchKeyword),
AllowNullable(ProductReviewSearchRequest::sortBy),
AllowNullable(ProductReviewSearchRequest::status),
AllowNullable(ProductReviewSearchRequest::updatedFrom),
AllowNullable(ProductReviewSearchRequest::updatedTo),
)

This file was deleted.

0 comments on commit 1ac0ec2

Please sign in to comment.