Skip to content

Commit

Permalink
Merge pull request #439 from Ecwid/fix_report_advice
Browse files Browse the repository at this point in the history
Have the same set of parameters for the report advises as for reports
  • Loading branch information
mvgreen authored Oct 18, 2024
2 parents dd293d5 + adcece3 commit 2f94bfe
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.ecwid.apiclient.v3.dto.report.request

import com.ecwid.apiclient.v3.dto.ApiRequest
import com.ecwid.apiclient.v3.dto.report.enums.*
import com.ecwid.apiclient.v3.responsefields.ResponseFields

abstract class AbstractReportRequest : ApiRequest {
abstract val reportType: ReportType
abstract val startedFrom: Long?
abstract val endedAt: Long?
abstract val timeScaleValue: TimeScaleValue?
abstract val comparePeriod: ComparePeriod?
abstract val firstDayOfWeek: FirstDayOfWeek?
abstract val orderByMetric: String?
abstract val orderDirection: String?
abstract val limit: Int?
abstract val offset: Int?
abstract val responseFields: ResponseFields
abstract val storefrontPlatform: StorefrontPlatform?

protected fun toParams(): Map<String, String> {
return mutableMapOf<String, String>().apply {
startedFrom?.let { put("startedFrom", it.toString()) }
endedAt?.let { put("endedAt", it.toString()) }
timeScaleValue?.let { put("timeScaleValue", it.toString()) }
comparePeriod?.let { put("comparePeriod", it.toString()) }
firstDayOfWeek?.let { put("firstDayOfWeek", it.toString()) }
orderByMetric?.let { put("orderByMetric", it) }
orderDirection?.let { put("orderDirection", it) }
limit?.let { put("limit", it.toString()) }
offset?.let { put("offset", it.toString()) }
storefrontPlatform?.let { put("storefrontPlatform", it.toString()) }
}.toMap()
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
package com.ecwid.apiclient.v3.dto.report.request

import com.ecwid.apiclient.v3.dto.ApiRequest
import com.ecwid.apiclient.v3.dto.report.enums.ReportType
import com.ecwid.apiclient.v3.dto.report.enums.*
import com.ecwid.apiclient.v3.impl.RequestInfo
import com.ecwid.apiclient.v3.responsefields.ResponseFields

data class ReportAdviceRequest(
val reportType: ReportType = ReportType.allTraffic,
) : ApiRequest {
override val reportType: ReportType = ReportType.allTraffic,
override val startedFrom: Long? = null,
override val endedAt: Long? = null,
override val timeScaleValue: TimeScaleValue? = null,
override val comparePeriod: ComparePeriod? = null,
override val firstDayOfWeek: FirstDayOfWeek? = null,
override val orderByMetric: String? = null,
override val orderDirection: String? = null,
override val limit: Int? = null,
override val offset: Int? = null,
override val responseFields: ResponseFields = ResponseFields.All,
override val storefrontPlatform: StorefrontPlatform? = null,
) : AbstractReportRequest() {

override fun toRequestInfo() = RequestInfo.createGetRequest(
pathSegments = listOf(
"reports",
reportType.toString(),
"tip"
),
params = emptyMap(),
params = toParams(),
responseFields = ResponseFields.All
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package com.ecwid.apiclient.v3.dto.report.request

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

data class ReportRequest(
val reportType: ReportType = ReportType.allTraffic,
val startedFrom: Long? = null,
val endedAt: Long? = null,
val timeScaleValue: TimeScaleValue? = null,
val comparePeriod: ComparePeriod? = null,
val firstDayOfWeek: FirstDayOfWeek? = null,
val orderByMetric: String? = null,
val orderDirection: String? = null,
val limit: Int? = null,
val offset: Int? = null,
val responseFields: ResponseFields = ResponseFields.All,
val storefrontPlatform: StorefrontPlatform? = null,
) : ApiRequest {

override val reportType: ReportType = ReportType.allTraffic,
override val startedFrom: Long? = null,
override val endedAt: Long? = null,
override val timeScaleValue: TimeScaleValue? = null,
override val comparePeriod: ComparePeriod? = null,
override val firstDayOfWeek: FirstDayOfWeek? = null,
override val orderByMetric: String? = null,
override val orderDirection: String? = null,
override val limit: Int? = null,
override val offset: Int? = null,
override val responseFields: ResponseFields = ResponseFields.All,
override val storefrontPlatform: StorefrontPlatform? = null,
) : AbstractReportRequest() {
override fun toRequestInfo() = RequestInfo.createGetRequest(
pathSegments = listOf(
"reports",
Expand All @@ -28,22 +26,4 @@ data class ReportRequest(
params = toParams(),
responseFields = responseFields,
)

private fun toParams(): Map<String, String> {
return mutableMapOf<String, String>().apply {
startedFrom?.let { put("startedFrom", it.toString()) }
endedAt?.let { put("endedAt", it.toString()) }
timeScaleValue?.let { put("timeScaleValue", it.toString()) }
comparePeriod?.let { put("comparePeriod", it.toString()) }
firstDayOfWeek?.let { put("firstDayOfWeek", it.toString()) }
orderByMetric?.let { put("orderByMetric", it) }
orderDirection?.let { put("orderDirection", it) }
limit?.let { put("limit", it.toString()) }
offset?.let { put("offset", it.toString()) }
storefrontPlatform?.let { put("storefrontPlatform", it.toString()) }
}.toMap()
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.ecwid.apiclient.v3.dto.product.result.ProductInventoryUpdateResult
import com.ecwid.apiclient.v3.dto.productreview.request.UpdatedProductReviewStatus
import com.ecwid.apiclient.v3.dto.profile.request.StoreProfileRequest
import com.ecwid.apiclient.v3.dto.profile.result.FetchedLatestStats
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
Expand Down Expand Up @@ -84,6 +85,17 @@ val otherNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
AllowNullable(ReportRequest::offset),
AllowNullable(ReportRequest::storefrontPlatform),

AllowNullable(ReportAdviceRequest::startedFrom),
AllowNullable(ReportAdviceRequest::endedAt),
AllowNullable(ReportAdviceRequest::timeScaleValue),
AllowNullable(ReportAdviceRequest::comparePeriod),
AllowNullable(ReportAdviceRequest::firstDayOfWeek),
AllowNullable(ReportAdviceRequest::orderByMetric),
AllowNullable(ReportAdviceRequest::orderDirection),
AllowNullable(ReportAdviceRequest::limit),
AllowNullable(ReportAdviceRequest::offset),
AllowNullable(ReportAdviceRequest::storefrontPlatform),

AllowNullable(FetchedReportResponse::timeScaleValue),
AllowNullable(FetchedReportResponse::comparePeriod),
AllowNullable(FetchedReportResponse::firstDayOfWeek),
Expand Down

0 comments on commit 2f94bfe

Please sign in to comment.