Skip to content

Commit 2f94bfe

Browse files
authored
Merge pull request #439 from Ecwid/fix_report_advice
Have the same set of parameters for the report advises as for reports
2 parents dd293d5 + adcece3 commit 2f94bfe

File tree

4 files changed

+75
-38
lines changed

4 files changed

+75
-38
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.ecwid.apiclient.v3.dto.report.request
2+
3+
import com.ecwid.apiclient.v3.dto.ApiRequest
4+
import com.ecwid.apiclient.v3.dto.report.enums.*
5+
import com.ecwid.apiclient.v3.responsefields.ResponseFields
6+
7+
abstract class AbstractReportRequest : ApiRequest {
8+
abstract val reportType: ReportType
9+
abstract val startedFrom: Long?
10+
abstract val endedAt: Long?
11+
abstract val timeScaleValue: TimeScaleValue?
12+
abstract val comparePeriod: ComparePeriod?
13+
abstract val firstDayOfWeek: FirstDayOfWeek?
14+
abstract val orderByMetric: String?
15+
abstract val orderDirection: String?
16+
abstract val limit: Int?
17+
abstract val offset: Int?
18+
abstract val responseFields: ResponseFields
19+
abstract val storefrontPlatform: StorefrontPlatform?
20+
21+
protected fun toParams(): Map<String, String> {
22+
return mutableMapOf<String, String>().apply {
23+
startedFrom?.let { put("startedFrom", it.toString()) }
24+
endedAt?.let { put("endedAt", it.toString()) }
25+
timeScaleValue?.let { put("timeScaleValue", it.toString()) }
26+
comparePeriod?.let { put("comparePeriod", it.toString()) }
27+
firstDayOfWeek?.let { put("firstDayOfWeek", it.toString()) }
28+
orderByMetric?.let { put("orderByMetric", it) }
29+
orderDirection?.let { put("orderDirection", it) }
30+
limit?.let { put("limit", it.toString()) }
31+
offset?.let { put("offset", it.toString()) }
32+
storefrontPlatform?.let { put("storefrontPlatform", it.toString()) }
33+
}.toMap()
34+
}
35+
}

src/main/kotlin/com/ecwid/apiclient/v3/dto/report/request/ReportAdviceRequest.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
package com.ecwid.apiclient.v3.dto.report.request
22

3-
import com.ecwid.apiclient.v3.dto.ApiRequest
4-
import com.ecwid.apiclient.v3.dto.report.enums.ReportType
3+
import com.ecwid.apiclient.v3.dto.report.enums.*
54
import com.ecwid.apiclient.v3.impl.RequestInfo
65
import com.ecwid.apiclient.v3.responsefields.ResponseFields
76

87
data class ReportAdviceRequest(
9-
val reportType: ReportType = ReportType.allTraffic,
10-
) : ApiRequest {
8+
override val reportType: ReportType = ReportType.allTraffic,
9+
override val startedFrom: Long? = null,
10+
override val endedAt: Long? = null,
11+
override val timeScaleValue: TimeScaleValue? = null,
12+
override val comparePeriod: ComparePeriod? = null,
13+
override val firstDayOfWeek: FirstDayOfWeek? = null,
14+
override val orderByMetric: String? = null,
15+
override val orderDirection: String? = null,
16+
override val limit: Int? = null,
17+
override val offset: Int? = null,
18+
override val responseFields: ResponseFields = ResponseFields.All,
19+
override val storefrontPlatform: StorefrontPlatform? = null,
20+
) : AbstractReportRequest() {
1121

1222
override fun toRequestInfo() = RequestInfo.createGetRequest(
1323
pathSegments = listOf(
1424
"reports",
1525
reportType.toString(),
1626
"tip"
1727
),
18-
params = emptyMap(),
28+
params = toParams(),
1929
responseFields = ResponseFields.All
2030
)
2131

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
package com.ecwid.apiclient.v3.dto.report.request
22

3-
import com.ecwid.apiclient.v3.dto.ApiRequest
43
import com.ecwid.apiclient.v3.dto.report.enums.*
54
import com.ecwid.apiclient.v3.impl.RequestInfo
65
import com.ecwid.apiclient.v3.responsefields.ResponseFields
76

87
data class ReportRequest(
9-
val reportType: ReportType = ReportType.allTraffic,
10-
val startedFrom: Long? = null,
11-
val endedAt: Long? = null,
12-
val timeScaleValue: TimeScaleValue? = null,
13-
val comparePeriod: ComparePeriod? = null,
14-
val firstDayOfWeek: FirstDayOfWeek? = null,
15-
val orderByMetric: String? = null,
16-
val orderDirection: String? = null,
17-
val limit: Int? = null,
18-
val offset: Int? = null,
19-
val responseFields: ResponseFields = ResponseFields.All,
20-
val storefrontPlatform: StorefrontPlatform? = null,
21-
) : ApiRequest {
22-
8+
override val reportType: ReportType = ReportType.allTraffic,
9+
override val startedFrom: Long? = null,
10+
override val endedAt: Long? = null,
11+
override val timeScaleValue: TimeScaleValue? = null,
12+
override val comparePeriod: ComparePeriod? = null,
13+
override val firstDayOfWeek: FirstDayOfWeek? = null,
14+
override val orderByMetric: String? = null,
15+
override val orderDirection: String? = null,
16+
override val limit: Int? = null,
17+
override val offset: Int? = null,
18+
override val responseFields: ResponseFields = ResponseFields.All,
19+
override val storefrontPlatform: StorefrontPlatform? = null,
20+
) : AbstractReportRequest() {
2321
override fun toRequestInfo() = RequestInfo.createGetRequest(
2422
pathSegments = listOf(
2523
"reports",
@@ -28,22 +26,4 @@ data class ReportRequest(
2826
params = toParams(),
2927
responseFields = responseFields,
3028
)
31-
32-
private fun toParams(): Map<String, String> {
33-
return mutableMapOf<String, String>().apply {
34-
startedFrom?.let { put("startedFrom", it.toString()) }
35-
endedAt?.let { put("endedAt", it.toString()) }
36-
timeScaleValue?.let { put("timeScaleValue", it.toString()) }
37-
comparePeriod?.let { put("comparePeriod", it.toString()) }
38-
firstDayOfWeek?.let { put("firstDayOfWeek", it.toString()) }
39-
orderByMetric?.let { put("orderByMetric", it) }
40-
orderDirection?.let { put("orderDirection", it) }
41-
limit?.let { put("limit", it.toString()) }
42-
offset?.let { put("offset", it.toString()) }
43-
storefrontPlatform?.let { put("storefrontPlatform", it.toString()) }
44-
}.toMap()
45-
}
46-
47-
48-
4929
}

src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import com.ecwid.apiclient.v3.dto.product.result.ProductInventoryUpdateResult
1818
import com.ecwid.apiclient.v3.dto.productreview.request.UpdatedProductReviewStatus
1919
import com.ecwid.apiclient.v3.dto.profile.request.StoreProfileRequest
2020
import com.ecwid.apiclient.v3.dto.profile.result.FetchedLatestStats
21+
import com.ecwid.apiclient.v3.dto.report.request.ReportAdviceRequest
2122
import com.ecwid.apiclient.v3.dto.report.request.ReportRequest
2223
import com.ecwid.apiclient.v3.dto.report.result.FetchedReportAdviceResponse
2324
import com.ecwid.apiclient.v3.dto.report.result.FetchedReportResponse
@@ -84,6 +85,17 @@ val otherNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
8485
AllowNullable(ReportRequest::offset),
8586
AllowNullable(ReportRequest::storefrontPlatform),
8687

88+
AllowNullable(ReportAdviceRequest::startedFrom),
89+
AllowNullable(ReportAdviceRequest::endedAt),
90+
AllowNullable(ReportAdviceRequest::timeScaleValue),
91+
AllowNullable(ReportAdviceRequest::comparePeriod),
92+
AllowNullable(ReportAdviceRequest::firstDayOfWeek),
93+
AllowNullable(ReportAdviceRequest::orderByMetric),
94+
AllowNullable(ReportAdviceRequest::orderDirection),
95+
AllowNullable(ReportAdviceRequest::limit),
96+
AllowNullable(ReportAdviceRequest::offset),
97+
AllowNullable(ReportAdviceRequest::storefrontPlatform),
98+
8799
AllowNullable(FetchedReportResponse::timeScaleValue),
88100
AllowNullable(FetchedReportResponse::comparePeriod),
89101
AllowNullable(FetchedReportResponse::firstDayOfWeek),

0 commit comments

Comments
 (0)