aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin/mx
diff options
context:
space:
mode:
authorIsidro Henoch <imhenoch@protonmail.com>2022-01-03 13:55:58 -0600
committerIsidro Henoch <imhenoch@protonmail.com>2022-01-03 13:55:58 -0600
commit1c94fbca0faebea6d005a92a53e7885e3ddd7dc6 (patch)
tree5567d2c823e0d28627f67738d07b810a65a2a0eb /shared/src/commonMain/kotlin/mx
parent4196352a52eba7e9148cbab6e12d7bafb0f07d88 (diff)
parent84fd0a97d775b88ef03c3161bbe126032ace8238 (diff)
downloadetbsa-trackermap-mobile-1c94fbca0faebea6d005a92a53e7885e3ddd7dc6.tar.gz
etbsa-trackermap-mobile-1c94fbca0faebea6d005a92a53e7885e3ddd7dc6.tar.bz2
etbsa-trackermap-mobile-1c94fbca0faebea6d005a92a53e7885e3ddd7dc6.zip
Merge branch 'reports'
# Conflicts: # androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt # androidApp/src/main/res/values/strings.xml
Diffstat (limited to 'shared/src/commonMain/kotlin/mx')
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/CommandsApi.kt9
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ReportsApi.kt164
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Command.kt8
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Event.kt4
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Stop.kt (renamed from shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/ReportStops.kt)15
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/CommandsController.kt29
6 files changed, 140 insertions, 89 deletions
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/CommandsApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/CommandsApi.kt
index 8f60153..e840888 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/CommandsApi.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/CommandsApi.kt
@@ -30,7 +30,14 @@ class CommandsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Ap
*/
@Suppress("UNCHECKED_CAST")
suspend fun commandsGet(all: kotlin.Boolean? = null, userId: kotlin.Int? = null, deviceId: kotlin.Int? = null, groupId: kotlin.Int? = null, refresh: kotlin.Boolean? = null): kotlin.Array<Command> {
- val localVariableQuery: MultiValueMap = mapOf("all" to listOf("$all"), "userId" to listOf("$userId"), "deviceId" to listOf("$deviceId"), "groupId" to listOf("$groupId"), "refresh" to listOf("$refresh"))
+ val query: MutableMap<String, List<String>> = mutableMapOf()
+ all?.let { query["all"] = listOf("$it") }
+ userId?.let { query["userId"] = listOf("$it") }
+ deviceId?.let { query["deviceId"] = listOf("$it") }
+ groupId?.let { query["groupId"] = listOf("$it") }
+ refresh?.let { query["refresh"] = listOf("$it") }
+ val localVariableQuery: MultiValueMap = query
+
val localVariableConfig = RequestConfig(
RequestMethod.GET,
"/commands", query = localVariableQuery
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 0caa945..43feaa6 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
@@ -13,7 +13,7 @@ package mx.trackermap.TrackerMap.client.apis
import mx.trackermap.TrackerMap.client.models.Event
import mx.trackermap.TrackerMap.client.models.Position
-import mx.trackermap.TrackerMap.client.models.ReportStops
+import mx.trackermap.TrackerMap.client.models.Stop
import mx.trackermap.TrackerMap.client.models.ReportSummary
import mx.trackermap.TrackerMap.client.models.ReportTrips
@@ -24,142 +24,210 @@ class ReportsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Api
/**
* Fetch a list of Events within the time period for the Devices or Groups
* At least one _deviceId_ or one _groupId_ must be passed
- * @param from in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
- * @param to in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
+ * @param from in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
+ * @param to in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
* @param deviceId (optional)
* @param groupId (optional)
* @param type % can be used to return events of all types (optional)
* @return kotlin.Array<Event>
*/
@Suppress("UNCHECKED_CAST")
- suspend fun reportsEventsGet(from: java.time.LocalDateTime, to: java.time.LocalDateTime, deviceId: kotlin.Array<kotlin.Int>? = null, groupId: kotlin.Array<kotlin.Int>? = null, type: kotlin.Array<kotlin.String>? = null): kotlin.Array<Event> {
- val localVariableQuery: MultiValueMap = mapOf("deviceId" to toMultiValue(deviceId!!.toList(), "multi"), "groupId" to toMultiValue(groupId!!.toList(), "multi"), "type" to toMultiValue(type!!.toList(), "csv"), "from" to listOf("$from"), "to" to listOf("$to"))
+ suspend fun reportsEventsGet(
+ from: String,
+ to: String,
+ deviceId: Int
+ ): kotlin.Array<Event> {
+ val localVariableQuery: MultiValueMap = mapOf(
+ "deviceId" to toMultiValue(listOf(deviceId), "multi"),
+ "from" to listOf(from),
+ "to" to listOf(to)
+ )
val localVariableConfig = RequestConfig(
- RequestMethod.GET,
- "/reports/events", query = localVariableQuery
+ RequestMethod.GET,
+ "/reports/events", query = localVariableQuery
)
val response = request<kotlin.Array<Event>>(
- localVariableConfig
+ localVariableConfig
)
return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Event>
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
- ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
- ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
+ ResponseType.ClientError -> throw ClientException(
+ (response as ClientError<*>).body as? String ?: "Client error"
+ )
+ ResponseType.ServerError -> throw ServerException(
+ (response as ServerError<*>).message ?: "Server error"
+ )
}
}
+
/**
* Fetch a list of Positions within the time period for the Devices or Groups
* At least one _deviceId_ or one _groupId_ must be passed
- * @param from in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
- * @param to in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
+ * @param from in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
+ * @param to in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
* @param deviceId (optional)
* @param groupId (optional)
* @return kotlin.Array<Position>
*/
@Suppress("UNCHECKED_CAST")
- suspend fun reportsRouteGet(from: java.time.LocalDateTime, to: java.time.LocalDateTime, deviceId: kotlin.Array<kotlin.Int>? = null, groupId: kotlin.Array<kotlin.Int>? = null): kotlin.Array<Position> {
- val localVariableQuery: MultiValueMap = mapOf("deviceId" to toMultiValue(deviceId!!.toList(), "multi"), "groupId" to toMultiValue(groupId!!.toList(), "multi"), "from" to listOf("$from"), "to" to listOf("$to"))
+ suspend fun reportsRouteGet(
+ from: String,
+ to: String,
+ deviceId: Int
+ ): kotlin.Array<Position> {
+ val localVariableQuery: MultiValueMap = mapOf(
+ "deviceId" to toMultiValue(listOf(deviceId), "multi"),
+ "from" to listOf(from),
+ "to" to listOf(to)
+ )
val localVariableConfig = RequestConfig(
- RequestMethod.GET,
- "/reports/route", query = localVariableQuery
+ RequestMethod.GET,
+ "/reports/route", query = localVariableQuery
)
val response = request<kotlin.Array<Position>>(
- localVariableConfig
+ localVariableConfig
)
return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Position>
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
- ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
- ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
+ ResponseType.ClientError -> throw ClientException(
+ (response as ClientError<*>).body as? String ?: "Client error"
+ )
+ ResponseType.ServerError -> throw ServerException(
+ (response as ServerError<*>).message ?: "Server error"
+ )
}
}
+
/**
* Fetch a list of ReportStops within the time period for the Devices or Groups
* At least one _deviceId_ or one _groupId_ must be passed
- * @param from in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
- * @param to in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
+ * @param from in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
+ * @param to in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
* @param deviceId (optional)
* @param groupId (optional)
* @return kotlin.Array<ReportStops>
*/
@Suppress("UNCHECKED_CAST")
- suspend fun reportsStopsGet(from: java.time.LocalDateTime, to: java.time.LocalDateTime, deviceId: kotlin.Array<kotlin.Int>? = null, groupId: kotlin.Array<kotlin.Int>? = null): kotlin.Array<ReportStops> {
- val localVariableQuery: MultiValueMap = mapOf("deviceId" to toMultiValue(deviceId!!.toList(), "multi"), "groupId" to toMultiValue(groupId!!.toList(), "multi"), "from" to listOf("$from"), "to" to listOf("$to"))
+ suspend fun reportsStopsGet(
+ from: String,
+ to: String,
+ deviceId: Int
+ ): kotlin.Array<Stop> {
+ val localVariableQuery: MultiValueMap = mapOf(
+ "deviceId" to toMultiValue(listOf(deviceId), "multi"),
+ "from" to listOf(from),
+ "to" to listOf(to)
+ )
val localVariableConfig = RequestConfig(
- RequestMethod.GET,
- "/reports/stops", query = localVariableQuery
+ RequestMethod.GET,
+ "/reports/stops", query = localVariableQuery
)
- val response = request<kotlin.Array<ReportStops>>(
- localVariableConfig
+ val response = request<kotlin.Array<Stop>>(
+ localVariableConfig
)
return when (response.responseType) {
- ResponseType.Success -> (response as Success<*>).data as kotlin.Array<ReportStops>
+ ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Stop>
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
- ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
- ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
+ ResponseType.ClientError -> throw ClientException(
+ (response as ClientError<*>).body as? String ?: "Client error"
+ )
+ ResponseType.ServerError -> throw ServerException(
+ (response as ServerError<*>).message ?: "Server error"
+ )
}
}
+
/**
* Fetch a list of ReportSummary within the time period for the Devices or Groups
* At least one _deviceId_ or one _groupId_ must be passed
- * @param from in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
- * @param to in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
+ * @param from in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
+ * @param to in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
* @param deviceId (optional)
* @param groupId (optional)
* @return kotlin.Array<ReportSummary>
*/
@Suppress("UNCHECKED_CAST")
- suspend fun reportsSummaryGet(from: java.time.LocalDateTime, to: java.time.LocalDateTime, deviceId: kotlin.Array<kotlin.Int>? = null, groupId: kotlin.Array<kotlin.Int>? = null): kotlin.Array<ReportSummary> {
- val localVariableQuery: MultiValueMap = mapOf("deviceId" to toMultiValue(deviceId!!.toList(), "multi"), "groupId" to toMultiValue(groupId!!.toList(), "multi"), "from" to listOf("$from"), "to" to listOf("$to"))
+ suspend fun reportsSummaryGet(
+ from: java.time.LocalDateTime,
+ to: java.time.LocalDateTime,
+ deviceId: kotlin.Array<kotlin.Int>? = null,
+ groupId: kotlin.Array<kotlin.Int>? = null
+ ): kotlin.Array<ReportSummary> {
+ val localVariableQuery: MultiValueMap = mapOf(
+ "deviceId" to toMultiValue(deviceId!!.toList(), "multi"),
+ "groupId" to toMultiValue(groupId!!.toList(), "multi"),
+ "from" to listOf("$from"),
+ "to" to listOf("$to")
+ )
val localVariableConfig = RequestConfig(
- RequestMethod.GET,
- "/reports/summary", query = localVariableQuery
+ RequestMethod.GET,
+ "/reports/summary", query = localVariableQuery
)
val response = request<kotlin.Array<ReportSummary>>(
- localVariableConfig
+ localVariableConfig
)
return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<ReportSummary>
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
- ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
- ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
+ ResponseType.ClientError -> throw ClientException(
+ (response as ClientError<*>).body as? String ?: "Client error"
+ )
+ ResponseType.ServerError -> throw ServerException(
+ (response as ServerError<*>).message ?: "Server error"
+ )
}
}
+
/**
* Fetch a list of ReportTrips within the time period for the Devices or Groups
* At least one _deviceId_ or one _groupId_ must be passed
- * @param from in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
- * @param to in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
+ * @param from in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
+ * @param to in IS0 8601 format. eg. &#x60;1963-11-22T18:30:00Z&#x60;
* @param deviceId (optional)
* @param groupId (optional)
* @return kotlin.Array<ReportTrips>
*/
@Suppress("UNCHECKED_CAST")
- suspend fun reportsTripsGet(from: java.time.LocalDateTime, to: java.time.LocalDateTime, deviceId: kotlin.Array<kotlin.Int>? = null, groupId: kotlin.Array<kotlin.Int>? = null): kotlin.Array<ReportTrips> {
- val localVariableQuery: MultiValueMap = mapOf("deviceId" to toMultiValue(deviceId!!.toList(), "multi"), "groupId" to toMultiValue(groupId!!.toList(), "multi"), "from" to listOf("$from"), "to" to listOf("$to"))
+ suspend fun reportsTripsGet(
+ from: java.time.LocalDateTime,
+ to: java.time.LocalDateTime,
+ deviceId: kotlin.Array<kotlin.Int>? = null,
+ groupId: kotlin.Array<kotlin.Int>? = null
+ ): kotlin.Array<ReportTrips> {
+ val localVariableQuery: MultiValueMap = mapOf(
+ "deviceId" to toMultiValue(deviceId!!.toList(), "multi"),
+ "groupId" to toMultiValue(groupId!!.toList(), "multi"),
+ "from" to listOf("$from"),
+ "to" to listOf("$to")
+ )
val localVariableConfig = RequestConfig(
- RequestMethod.GET,
- "/reports/trips", query = localVariableQuery
+ RequestMethod.GET,
+ "/reports/trips", query = localVariableQuery
)
val response = request<kotlin.Array<ReportTrips>>(
- localVariableConfig
+ localVariableConfig
)
return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<ReportTrips>
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
- ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
- ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
+ ResponseType.ClientError -> throw ClientException(
+ (response as ClientError<*>).body as? String ?: "Client error"
+ )
+ ResponseType.ServerError -> throw ServerException(
+ (response as ServerError<*>).message ?: "Server error"
+ )
}
}
}
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Command.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Command.kt
index c1c6a5d..37b22d4 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Command.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Command.kt
@@ -11,6 +11,7 @@
*/
package mx.trackermap.TrackerMap.client.models
+import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonPrimitive
@@ -22,12 +23,11 @@ import kotlinx.serialization.json.JsonPrimitive
* @param type
* @param attributes
*/
+@Serializable
data class Command (
-
val id: Int? = null,
- val deviceId: Int? = null,
+ var deviceId: Int? = null,
val description: String? = null,
val type: String? = null,
val attributes: Map<String, JsonPrimitive> = mapOf()
-) {
-} \ No newline at end of file
+) \ No newline at end of file
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Event.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Event.kt
index e504600..741ae57 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Event.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Event.kt
@@ -11,6 +11,7 @@
*/
package mx.trackermap.TrackerMap.client.models
+import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonPrimitive
@@ -25,12 +26,13 @@ import kotlinx.serialization.json.JsonPrimitive
* @param maintenanceId
* @param attributes
*/
+@Serializable
data class Event (
val id: Int? = null,
val type: String? = null,
/* in IS0 8601 format. eg. `1963-11-22T18:30:00Z` */
- val eventTime: java.time.LocalDateTime? = null,
+ val eventTime: String? = null,
val deviceId: Int? = null,
val positionId: Int? = null,
val geofenceId: Int? = null,
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/ReportStops.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Stop.kt
index bdd4cbe..c06b864 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/ReportStops.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Stop.kt
@@ -11,6 +11,8 @@
*/
package mx.trackermap.TrackerMap.client.models
+import kotlinx.serialization.Serializable
+
/**
*
@@ -25,20 +27,21 @@ package mx.trackermap.TrackerMap.client.models
* @param spentFuel in liters
* @param engineHours
*/
-data class ReportStops (
+@Serializable
+data class Stop (
val deviceId: kotlin.Int? = null,
val deviceName: kotlin.String? = null,
val duration: kotlin.Int? = null,
/* in IS0 8601 format. eg. `1963-11-22T18:30:00Z` */
- val startTime: java.time.LocalDateTime? = null,
+ val startTime: String? = null,
val address: kotlin.String? = null,
- val lat: java.math.BigDecimal? = null,
- val lon: java.math.BigDecimal? = null,
+ val lat: Double? = null,
+ val lon: Double? = null,
/* in IS0 8601 format. eg. `1963-11-22T18:30:00Z` */
- val endTime: java.time.LocalDateTime? = null,
+ val endTime: String? = null,
/* in liters */
- val spentFuel: java.math.BigDecimal? = null,
+ val spentFuel: Double? = null,
val engineHours: kotlin.Int? = null
) {
} \ No newline at end of file
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/CommandsController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/CommandsController.kt
deleted file mode 100644
index b710763..0000000
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/CommandsController.kt
+++ /dev/null
@@ -1,29 +0,0 @@
-package mx.trackermap.TrackerMap.controllers
-
-import mx.trackermap.TrackerMap.client.apis.CommandsApi
-import mx.trackermap.TrackerMap.client.models.Command
-import mx.trackermap.TrackerMap.client.models.Device
-
-class CommandsController(
- val commandsApi: CommandsApi,
- val sessionController: SessionController)
-{
- var commands = emptyArray<Command>()
- val deviceCommands = mutableMapOf<Int, Array<Command>>()
-
- suspend fun getAllCommands () {
- sessionController.user?.id?.let {
- commands = commandsApi.commandsGet(userId = it)
- }
- }
-
- suspend fun getDeviceCommands (device: Device) {
- device.id?.let {
- deviceCommands[it] = commandsApi.commandsSendGet (deviceId = device.id)
- }
- }
-
- suspend fun sendCommand (command: Command) {
- commandsApi.commandsSendPost(command)
- }
-} \ No newline at end of file