From acd8a70ac8507b646c611a0b79a8665d2c5aec48 Mon Sep 17 00:00:00 2001 From: mvgreen Date: Sun, 12 Mar 2023 13:07:27 +0400 Subject: [PATCH 1/2] Fix deserialization of enums --- .../apiclient/v3/dto/report/enums/ComparePeriod.kt | 11 +++++++++++ .../apiclient/v3/dto/report/enums/FirstDayOfWeek.kt | 5 +++++ .../ecwid/apiclient/v3/dto/report/enums/ReportType.kt | 5 +++++ .../apiclient/v3/dto/report/enums/TimeScaleValue.kt | 11 +++++++++++ 4 files changed, 32 insertions(+) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ComparePeriod.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ComparePeriod.kt index ea12828ab..cbf9300fc 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ComparePeriod.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ComparePeriod.kt @@ -1,9 +1,20 @@ package com.ecwid.apiclient.v3.dto.report.enums +import com.google.gson.annotations.SerializedName + enum class ComparePeriod(val alias: String) { + @SerializedName("previousPeriod") PREVIOUS_PERIOD("previousPeriod"), + + @SerializedName("similarPeriodInPreviousWeek") SIMILAR_PERIOD_IN_PREVIOUS_WEEK("similarPeriodInPreviousWeek"), + + @SerializedName("similarPeriodInPreviousMonth") SIMILAR_PERIOD_IN_PREVIOUS_MONTH("similarPeriodInPreviousMonth"), + + @SerializedName("similarPeriodInPreviousYear") SIMILAR_PERIOD_IN_PREVIOUS_YEAR("similarPeriodInPreviousYear"), + + @SerializedName("noComparePeriod") NO_COMPARE_PERIOD("noComparePeriod"); } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/FirstDayOfWeek.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/FirstDayOfWeek.kt index 5eedeaf5b..5f7cdeba0 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/FirstDayOfWeek.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/FirstDayOfWeek.kt @@ -1,6 +1,11 @@ package com.ecwid.apiclient.v3.dto.report.enums +import com.google.gson.annotations.SerializedName + enum class FirstDayOfWeek(val alias: String) { + @SerializedName("monday") MONDAY("monday"), + + @SerializedName("sunday") SUNDAY("sunday"); } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ReportType.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ReportType.kt index 242eb1092..9097904bc 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ReportType.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ReportType.kt @@ -1,6 +1,11 @@ package com.ecwid.apiclient.v3.dto.report.enums +import com.google.gson.annotations.SerializedName + enum class ReportType(val alias: String) { + @SerializedName("allTraffic") ALL_TRAFFIC("allTraffic"), + + @SerializedName("newVsReturningVisitors") NEW_VS_RETURNING_VISITORS("newVsReturningVisitors"), } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/TimeScaleValue.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/TimeScaleValue.kt index 45f420180..c3a7a1ce8 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/TimeScaleValue.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/TimeScaleValue.kt @@ -1,9 +1,20 @@ package com.ecwid.apiclient.v3.dto.report.enums +import com.google.gson.annotations.SerializedName + enum class TimeScaleValue(val alias: String) { + @SerializedName("hour") HOUR("hour"), + + @SerializedName("day") DAY("day"), + + @SerializedName("week") WEEK("week"), + + @SerializedName("month") MONTH("month"), + + @SerializedName("year") YEAR("year"); } From 546f57a0ac85ad992adee8c1311d0ab2acf744ad Mon Sep 17 00:00:00 2001 From: mvgreen Date: Mon, 13 Mar 2023 13:58:40 +0400 Subject: [PATCH 2/2] Rename names of the enums to avoid using @SerializedName --- .../v3/dto/report/enums/ComparePeriod.kt | 23 +++++-------------- .../v3/dto/report/enums/FirstDayOfWeek.kt | 11 +++------ .../v3/dto/report/enums/ReportType.kt | 11 +++------ .../v3/dto/report/enums/TimeScaleValue.kt | 23 +++++-------------- .../v3/dto/report/request/ReportRequest.kt | 10 ++++---- .../report/result/FetchedReportResponse.kt | 2 +- 6 files changed, 24 insertions(+), 56 deletions(-) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ComparePeriod.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ComparePeriod.kt index cbf9300fc..42222f769 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ComparePeriod.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ComparePeriod.kt @@ -1,20 +1,9 @@ package com.ecwid.apiclient.v3.dto.report.enums -import com.google.gson.annotations.SerializedName - -enum class ComparePeriod(val alias: String) { - @SerializedName("previousPeriod") - PREVIOUS_PERIOD("previousPeriod"), - - @SerializedName("similarPeriodInPreviousWeek") - SIMILAR_PERIOD_IN_PREVIOUS_WEEK("similarPeriodInPreviousWeek"), - - @SerializedName("similarPeriodInPreviousMonth") - SIMILAR_PERIOD_IN_PREVIOUS_MONTH("similarPeriodInPreviousMonth"), - - @SerializedName("similarPeriodInPreviousYear") - SIMILAR_PERIOD_IN_PREVIOUS_YEAR("similarPeriodInPreviousYear"), - - @SerializedName("noComparePeriod") - NO_COMPARE_PERIOD("noComparePeriod"); +enum class ComparePeriod { + previousPeriod, + similarPeriodInPreviousWeek, + similarPeriodInPreviousMonth, + similarPeriodInPreviousYear, + noComparePeriod; } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/FirstDayOfWeek.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/FirstDayOfWeek.kt index 5f7cdeba0..158a3c144 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/FirstDayOfWeek.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/FirstDayOfWeek.kt @@ -1,11 +1,6 @@ package com.ecwid.apiclient.v3.dto.report.enums -import com.google.gson.annotations.SerializedName - -enum class FirstDayOfWeek(val alias: String) { - @SerializedName("monday") - MONDAY("monday"), - - @SerializedName("sunday") - SUNDAY("sunday"); +enum class FirstDayOfWeek { + monday, + sunday; } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ReportType.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ReportType.kt index 9097904bc..b2e68f607 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ReportType.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/ReportType.kt @@ -1,11 +1,6 @@ package com.ecwid.apiclient.v3.dto.report.enums -import com.google.gson.annotations.SerializedName - -enum class ReportType(val alias: String) { - @SerializedName("allTraffic") - ALL_TRAFFIC("allTraffic"), - - @SerializedName("newVsReturningVisitors") - NEW_VS_RETURNING_VISITORS("newVsReturningVisitors"), +enum class ReportType { + allTraffic, + newVsReturningVisitors, } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/TimeScaleValue.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/TimeScaleValue.kt index c3a7a1ce8..7e00816f2 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/TimeScaleValue.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/enums/TimeScaleValue.kt @@ -1,20 +1,9 @@ package com.ecwid.apiclient.v3.dto.report.enums -import com.google.gson.annotations.SerializedName - -enum class TimeScaleValue(val alias: String) { - @SerializedName("hour") - HOUR("hour"), - - @SerializedName("day") - DAY("day"), - - @SerializedName("week") - WEEK("week"), - - @SerializedName("month") - MONTH("month"), - - @SerializedName("year") - YEAR("year"); +enum class TimeScaleValue { + hour, + day, + week, + month, + year; } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/request/ReportRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/request/ReportRequest.kt index 4bb1f4b8d..a730e275c 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/request/ReportRequest.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/request/ReportRequest.kt @@ -8,7 +8,7 @@ import com.ecwid.apiclient.v3.dto.report.enums.TimeScaleValue import com.ecwid.apiclient.v3.impl.RequestInfo data class ReportRequest( - val reportType: ReportType = ReportType.ALL_TRAFFIC, + val reportType: ReportType = ReportType.allTraffic, val startedFrom: Long? = null, val endedAt: Long? = null, val timeScaleValue: TimeScaleValue? = null, @@ -19,7 +19,7 @@ data class ReportRequest( override fun toRequestInfo() = RequestInfo.createGetRequest( pathSegments = listOf( "reports", - reportType.alias, + reportType.toString(), ), params = toParams() ) @@ -28,9 +28,9 @@ data class ReportRequest( return mutableMapOf().apply { startedFrom?.let { put("startedFrom", it.toString()) } endedAt?.let { put("endedAt", it.toString()) } - timeScaleValue?.let { put("timeScaleValue", it.alias) } - comparePeriod?.let { put("comparePeriod", it.alias) } - firstDayOfWeek?.let { put("firstDayOfWeek", it.alias) } + timeScaleValue?.let { put("timeScaleValue", it.toString()) } + comparePeriod?.let { put("comparePeriod", it.toString()) } + firstDayOfWeek?.let { put("firstDayOfWeek", it.toString()) } }.toMap() } diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/result/FetchedReportResponse.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/result/FetchedReportResponse.kt index 53f3ae9a3..4c4f10306 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/result/FetchedReportResponse.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/report/result/FetchedReportResponse.kt @@ -6,7 +6,7 @@ import com.ecwid.apiclient.v3.dto.report.enums.ReportType import com.ecwid.apiclient.v3.dto.report.enums.TimeScaleValue data class FetchedReportResponse( - val reportType: ReportType = ReportType.ALL_TRAFFIC, + val reportType: ReportType = ReportType.allTraffic, val startedFrom: Long = 0, val endedAt: Long = 0, val timeScaleValue: TimeScaleValue? = null,