From f133dc96d4072c3bf4f9794b000b1e0ab946f96b Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sun, 16 Jan 2022 18:28:14 -0600 Subject: Fixed event report types on API --- .../mx/trackermap/TrackerMap/client/apis/ReportsApi.kt | 12 ++++++------ .../trackermap/TrackerMap/client/models/EventInformation.kt | 6 +++--- .../mx/trackermap/TrackerMap/controllers/ReportController.kt | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'shared') diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ReportsApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ReportsApi.kt index 3765207..d77064e 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ReportsApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ReportsApi.kt @@ -36,14 +36,14 @@ class ReportsApi(basePath: String = "https://demo.traccar.org/api") : ApiClient( from: String, to: String, deviceId: Int, - type: String = "%", + types: List = listOf("%"), xlsx: Boolean = false ): Any { val localVariableQuery: MultiValueMap = mapOf( "deviceId" to toMultiValue(listOf(deviceId), "multi"), "from" to listOf(from), "to" to listOf(to), - "type" to listOf(type) + "type" to types ) val localVariableHeaders = mutableMapOf() if (xlsx) { @@ -81,20 +81,20 @@ class ReportsApi(basePath: String = "https://demo.traccar.org/api") : ApiClient( suspend fun reportsEventsGet( from: String, to: String, - type: String = "%", + types: List = listOf("%"), deviceId: Int, ): Array { - return reportsEventsGetBase(from, to, deviceId, type, false) as Array + return reportsEventsGetBase(from, to, deviceId, types, false) as Array } @Suppress("UNCHECKED_CAST") suspend fun reportsEventsGetXlsx( from: String, to: String, - type: String = "%", + types: List = listOf("%"), deviceId: Int, ): ByteArray { - return reportsEventsGetBase(from, to, deviceId, type, true) as ByteArray + return reportsEventsGetBase(from, to, deviceId, types, true) as ByteArray } /** diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/EventInformation.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/EventInformation.kt index befd8f1..5e4b2d5 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/EventInformation.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/EventInformation.kt @@ -51,11 +51,11 @@ data class EventInformation( Type.UNKNOWN -> "unknown" } - fun reportTypesToString(t: Array) = + fun reportTypesToStrings(t: List) = if (t.isEmpty() || t.contains(Type.ALL)) { - reportTypeToString(Type.ALL) + listOf(reportTypeToString(Type.ALL)) } else { - t.joinToString(",", transform = this::reportTypeToString) + t.map(this::reportTypeToString) } fun stringToReportType(s: String) = diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt index 8a7f527..78f0173 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/ReportController.kt @@ -37,7 +37,7 @@ class ReportController( reportType: ReportType?, reportPeriod: ReportDates.ReportPeriod?, xlsx: Boolean = false, - eventTypes: Array = arrayOf() + eventTypes: List = listOf() ) { if (reportType == null || reportPeriod == null) { return @@ -85,7 +85,7 @@ class ReportController( deviceId: Int, from: String, to: String, - types: Array, + types: List, xlsx: Boolean ) { Log.d("UnitReportsVM", "Fetching events") @@ -93,7 +93,7 @@ class ReportController( if (!xlsx) { val positionsResult = reportsApi.reportsRouteGet(from, to, deviceId) val eventsResult = reportsApi.reportsEventsGet( - from, to, EventInformation.reportTypesToString(types), deviceId + from, to, EventInformation.reportTypesToStrings(types), deviceId ) val geofencesResult = geofencesApi.geofencesGet(all = true) @@ -110,7 +110,7 @@ class ReportController( reportFlow.value = Report.EventsReport(result.toTypedArray()) } else { val result = reportsApi.reportsEventsGetXlsx( - from, to, EventInformation.reportTypesToString(types), deviceId + from, to, EventInformation.reportTypesToStrings(types), deviceId ) Log.d("UnitReportsVM", "Events report: $result") -- cgit v1.2.3