From 7c8a65b8d1ae8a049bf67260acb6fafbd95adac9 Mon Sep 17 00:00:00 2001 From: Isidro Henoch Date: Tue, 21 Dec 2021 14:21:16 -0600 Subject: Implements the commands list - Shows command details - Sends a selected command to a device --- .../TrackerMap/client/apis/CommandsApi.kt | 9 ++++++- .../trackermap/TrackerMap/client/models/Command.kt | 8 +++--- .../TrackerMap/controllers/CommandsController.kt | 29 ---------------------- 3 files changed, 12 insertions(+), 34 deletions(-) delete mode 100644 shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/CommandsController.kt (limited to 'shared/src') 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 { - 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> = 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/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 = mapOf() -) { -} \ No newline at end of file +) \ 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() - val deviceCommands = mutableMapOf>() - - 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 -- cgit v1.2.3 From f37c6de28b014af0cdbf278986a668030f54cc55 Mon Sep 17 00:00:00 2001 From: Isidro Henoch Date: Mon, 27 Dec 2021 14:27:17 -0600 Subject: Implements the report functionality, UI is missing --- androidApp/build.gradle.kts | 1 + .../mx/trackermap/TrackerMap/android/TrackerApp.kt | 4 + .../android/details/reports/UnitReportsFragment.kt | 32 +++- .../details/reports/UnitReportsViewModel.kt | 142 ++++++++++++++++++ .../TrackerMap/android/devices/DevicesAdapter.kt | 2 +- .../src/main/res/layout/unit_details_reports.xml | 57 +++++-- androidApp/src/main/res/values/strings.xml | 5 + .../TrackerMap/client/apis/ReportsApi.kt | 164 +++++++++++++++------ .../trackermap/TrackerMap/client/models/Event.kt | 4 +- .../TrackerMap/client/models/Position.kt | 6 +- .../TrackerMap/client/models/ReportStops.kt | 44 ------ .../mx/trackermap/TrackerMap/client/models/Stop.kt | 47 ++++++ 12 files changed, 398 insertions(+), 110 deletions(-) create mode 100644 androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt delete mode 100644 shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/ReportStops.kt create mode 100644 shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Stop.kt (limited to 'shared/src') diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 01508ac..5736c84 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -37,5 +37,6 @@ dependencies { implementation("androidx.fragment:fragment-ktx:1.4.0") implementation("io.ktor:ktor-client-serialization:1.6.6") implementation("com.github.zerobranch:SwipeLayout:1.3.1") + implementation("com.github.addisonElliott:SegmentedButton:3.1.9") implementation(group = "", name = "WhirlyGlobeMaply", ext = "aar") } \ No newline at end of file diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt index f46a5c9..16cad74 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt @@ -3,11 +3,13 @@ package mx.trackermap.TrackerMap.android import android.app.Application import mx.trackermap.TrackerMap.android.details.commands.UnitCommandsViewModel import mx.trackermap.TrackerMap.android.details.information.UnitInformationViewModel +import mx.trackermap.TrackerMap.android.details.reports.UnitReportsViewModel import mx.trackermap.TrackerMap.android.session.LoginViewModel import mx.trackermap.TrackerMap.android.units.UnitsViewModel import mx.trackermap.TrackerMap.client.apis.CommandsApi import mx.trackermap.TrackerMap.client.apis.DevicesApi import mx.trackermap.TrackerMap.client.apis.PositionsApi +import mx.trackermap.TrackerMap.client.apis.ReportsApi import mx.trackermap.TrackerMap.client.apis.SessionApi import mx.trackermap.TrackerMap.controllers.UnitsController import org.koin.android.ext.koin.androidContext @@ -28,6 +30,7 @@ class TrackerApp : Application() { single { DevicesApi(get()) } single { PositionsApi(get()) } single { CommandsApi(get()) } + single { ReportsApi(get()) } single { UnitsController(get(), get()) } @@ -35,6 +38,7 @@ class TrackerApp : Application() { viewModel { UnitInformationViewModel(get()) } viewModel { UnitCommandsViewModel(get()) } single { UnitsViewModel(get()) } + viewModel { UnitReportsViewModel(get(), get()) } } startKoin { diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt index a2faec8..dfc0493 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt @@ -1,17 +1,22 @@ package mx.trackermap.TrackerMap.android.details.reports import android.os.Bundle +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import mx.trackermap.TrackerMap.android.databinding.UnitDetailsReportsBinding import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter +import org.koin.androidx.viewmodel.ext.android.viewModel + +class UnitReportsFragment : Fragment() { -class UnitReportsFragment: Fragment() { private var _binding: UnitDetailsReportsBinding? = null private val binding get() = _binding!! + private val unitReportsViewModel: UnitReportsViewModel by viewModel() + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -23,12 +28,33 @@ class UnitReportsFragment: Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val id = arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG) - binding.unitReportsText.text = "COMMANDS for ID - $id" + + unitReportsViewModel.deviceId.value = + arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG) ?: 0 + setupEvents() + setupObservers() } override fun onDestroyView() { super.onDestroyView() _binding = null } + + private fun setupEvents() { + binding.reportType.setOnPositionChangedListener { position -> + unitReportsViewModel.reportType.value = when (position) { + 0 -> UnitReportsViewModel.ReportType.POSITIONS + 1 -> UnitReportsViewModel.ReportType.EVENTS + else -> UnitReportsViewModel.ReportType.STOPS + } + } + unitReportsViewModel.reportPeriod.value = UnitReportsViewModel.ReportPeriod.DAY + unitReportsViewModel.reportType.value = UnitReportsViewModel.ReportType.POSITIONS + } + + private fun setupObservers() { + unitReportsViewModel.report.observe(this) { report -> + Log.d("UnitReportsFragment", "Report available: $report") + } + } } \ No newline at end of file diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt new file mode 100644 index 0000000..808bdda --- /dev/null +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt @@ -0,0 +1,142 @@ +package mx.trackermap.TrackerMap.android.details.reports + +import android.util.Log +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.SavedStateHandle +import androidx.lifecycle.ViewModel +import androidx.lifecycle.asFlow +import androidx.lifecycle.viewModelScope +import java.text.SimpleDateFormat +import java.util.Calendar +import java.util.Date +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.launch +import mx.trackermap.TrackerMap.client.apis.ReportsApi +import mx.trackermap.TrackerMap.client.models.Event +import mx.trackermap.TrackerMap.client.models.Position +import mx.trackermap.TrackerMap.client.models.Stop +import org.koin.core.component.KoinComponent + +class UnitReportsViewModel( + private val reportsApi: ReportsApi, + savedStateHandle: SavedStateHandle +) : ViewModel(), KoinComponent { + + sealed class Report { + class PositionsReport(positions: Array) : Report() + class EventsReport(events: Array) : Report() + class StopsReport(stops: Array) : Report() + } + + enum class ReportType { + POSITIONS, EVENTS, STOPS + } + + enum class ReportPeriod { + DAY, WEEK, MONTH + } + + var deviceId = savedStateHandle.getLiveData("deviceId", 0) + val reportType: MutableLiveData = savedStateHandle.getLiveData("reportType", null) + val reportPeriod: MutableLiveData = + savedStateHandle.getLiveData("reportPeriod", null) + val report: MutableLiveData = MutableLiveData() + + val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") + + init { + viewModelScope.launch { + setupTypeObserver() + } + viewModelScope.launch { + setupPeriodObserver() + } + } + + private suspend fun setupTypeObserver() { + reportType.asFlow().collect { + fetchReport() + } + } + + private suspend fun setupPeriodObserver() { + reportPeriod.asFlow().collect { + fetchReport() + } + } + + private fun fetchReport() { + if (reportType.value == null || reportPeriod.value == null) { + return + } + + val (currentDate, previousDate) = getDates() + Log.d("UnitReportsVM", "Current report type: ${reportType.value.toString()}") + Log.d("UnitReportsVM", "Current report period: ${reportPeriod.value.toString()}") + Log.d("UnitReportsVM", "Current date:${dateFormat.format(currentDate)}") + Log.d("UnitReportsVM", "Previous date:${dateFormat.format(previousDate)}") + + viewModelScope.launch { + when (reportType.value!!) { + ReportType.POSITIONS -> fetchPositions(previousDate, currentDate) + ReportType.EVENTS -> fetchEvents(previousDate, currentDate) + ReportType.STOPS -> fetchStops(previousDate, currentDate) + } + } + } + + private fun getDates(): Pair { + val calendar = Calendar.getInstance() + val currentDate = calendar.time + + calendar.add( + Calendar.DATE, when (reportPeriod.value!!) { + ReportPeriod.DAY -> -1 + ReportPeriod.WEEK -> -7 + ReportPeriod.MONTH -> -30 + } + ) + val previousDate = calendar.time + + return Pair(currentDate, previousDate) + } + + private suspend fun fetchPositions(from: Date, to: Date) { + Log.d("UnitReportsVM", "Fetching positions") + + val result = reportsApi.reportsRouteGet( + dateFormat.format(from), + dateFormat.format(to), + deviceId.value!! + ) + + Log.d("UnitReportsVM", "Positions report: $result") + report.postValue(Report.PositionsReport(result)) + } + + private suspend fun fetchEvents(from: Date, to: Date) { + Log.d("UnitReportsVM", "Fetching events") + + val result = reportsApi.reportsEventsGet( + dateFormat.format(from), + dateFormat.format(to), + deviceId.value!! + ) + + Log.d("UnitReportsVM", "Events report: $result") + report.postValue(Report.EventsReport(result)) + } + + private suspend fun fetchStops(from: Date, to: Date) { + Log.d("UnitReportsVM", "Fetching stops") + + val result = reportsApi.reportsStopsGet( + dateFormat.format(from), + dateFormat.format(to), + deviceId.value!! + ) + + Log.d("UnitReportsVM", "Stops report: $result") + report.postValue(Report.StopsReport(result)) + } +} \ No newline at end of file diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt index 4852757..6a01e33 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt @@ -73,7 +73,7 @@ class DevicesAdapter( driverName.text = unit.device.contact unitSpeed.text = context.getString(R.string.unit_speed_format, unit.position?.speed?.toInt() ?: 0) lastAddress.text = unit.position?.address - lastDate.text = "yyyy/mm/dd, hh:mm" + lastDate.text = unit.position?.deviceTime actionCallback?.let { callback -> detailsButton.setOnClickListener { callback(unit, Action.DETAILS) } reportsButton.setOnClickListener { callback(unit, Action.REPORTS) } diff --git a/androidApp/src/main/res/layout/unit_details_reports.xml b/androidApp/src/main/res/layout/unit_details_reports.xml index f1b52e3..f064a3f 100644 --- a/androidApp/src/main/res/layout/unit_details_reports.xml +++ b/androidApp/src/main/res/layout/unit_details_reports.xml @@ -1,19 +1,56 @@ + android:layout_width="match_parent" + android:layout_height="match_parent"> - + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:position="0" + app:radius="30dp" + app:ripple="true" + app:selectedBackground="@color/colorPrimary"> + + + + + + + + \ No newline at end of file diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index 7478ddb..ca9ff5e 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -23,7 +23,12 @@ Reports Commands Type to search + Key Value Send Command + + Positions + Events + Stops \ No newline at end of file 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. `1963-11-22T18:30:00Z` - * @param to in IS0 8601 format. eg. `1963-11-22T18:30:00Z` + * @param from in IS0 8601 format. eg. `1963-11-22T18:30:00Z` + * @param to in IS0 8601 format. eg. `1963-11-22T18:30:00Z` * @param deviceId (optional) * @param groupId (optional) * @param type % can be used to return events of all types (optional) * @return kotlin.Array */ @Suppress("UNCHECKED_CAST") - suspend fun reportsEventsGet(from: java.time.LocalDateTime, to: java.time.LocalDateTime, deviceId: kotlin.Array? = null, groupId: kotlin.Array? = null, type: kotlin.Array? = null): kotlin.Array { - 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 { + 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>( - localVariableConfig + localVariableConfig ) return when (response.responseType) { ResponseType.Success -> (response as Success<*>).data as kotlin.Array 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. `1963-11-22T18:30:00Z` - * @param to in IS0 8601 format. eg. `1963-11-22T18:30:00Z` + * @param from in IS0 8601 format. eg. `1963-11-22T18:30:00Z` + * @param to in IS0 8601 format. eg. `1963-11-22T18:30:00Z` * @param deviceId (optional) * @param groupId (optional) * @return kotlin.Array */ @Suppress("UNCHECKED_CAST") - suspend fun reportsRouteGet(from: java.time.LocalDateTime, to: java.time.LocalDateTime, deviceId: kotlin.Array? = null, groupId: kotlin.Array? = null): kotlin.Array { - 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 { + 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>( - localVariableConfig + localVariableConfig ) return when (response.responseType) { ResponseType.Success -> (response as Success<*>).data as kotlin.Array 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. `1963-11-22T18:30:00Z` - * @param to in IS0 8601 format. eg. `1963-11-22T18:30:00Z` + * @param from in IS0 8601 format. eg. `1963-11-22T18:30:00Z` + * @param to in IS0 8601 format. eg. `1963-11-22T18:30:00Z` * @param deviceId (optional) * @param groupId (optional) * @return kotlin.Array */ @Suppress("UNCHECKED_CAST") - suspend fun reportsStopsGet(from: java.time.LocalDateTime, to: java.time.LocalDateTime, deviceId: kotlin.Array? = null, groupId: kotlin.Array? = null): kotlin.Array { - 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 { + 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>( - localVariableConfig + val response = request>( + localVariableConfig ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array + ResponseType.Success -> (response as Success<*>).data as kotlin.Array 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. `1963-11-22T18:30:00Z` - * @param to in IS0 8601 format. eg. `1963-11-22T18:30:00Z` + * @param from in IS0 8601 format. eg. `1963-11-22T18:30:00Z` + * @param to in IS0 8601 format. eg. `1963-11-22T18:30:00Z` * @param deviceId (optional) * @param groupId (optional) * @return kotlin.Array */ @Suppress("UNCHECKED_CAST") - suspend fun reportsSummaryGet(from: java.time.LocalDateTime, to: java.time.LocalDateTime, deviceId: kotlin.Array? = null, groupId: kotlin.Array? = null): kotlin.Array { - 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? = null, + groupId: kotlin.Array? = null + ): kotlin.Array { + 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>( - localVariableConfig + localVariableConfig ) return when (response.responseType) { ResponseType.Success -> (response as Success<*>).data as kotlin.Array 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. `1963-11-22T18:30:00Z` - * @param to in IS0 8601 format. eg. `1963-11-22T18:30:00Z` + * @param from in IS0 8601 format. eg. `1963-11-22T18:30:00Z` + * @param to in IS0 8601 format. eg. `1963-11-22T18:30:00Z` * @param deviceId (optional) * @param groupId (optional) * @return kotlin.Array */ @Suppress("UNCHECKED_CAST") - suspend fun reportsTripsGet(from: java.time.LocalDateTime, to: java.time.LocalDateTime, deviceId: kotlin.Array? = null, groupId: kotlin.Array? = null): kotlin.Array { - 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? = null, + groupId: kotlin.Array? = null + ): kotlin.Array { + 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>( - localVariableConfig + localVariableConfig ) return when (response.responseType) { ResponseType.Success -> (response as Success<*>).data as kotlin.Array 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/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/Position.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Position.kt index 9a16615..5286b46 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Position.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Position.kt @@ -46,11 +46,11 @@ data class Position ( val deviceId: Int? = null, val protocol: String? = null, /* in IS0 8601 format. eg. `1963-11-22T18:30:00Z` */ -// val deviceTime: LocalDateTime? = null, + val deviceTime: String? = null, /* in IS0 8601 format. eg. `1963-11-22T18:30:00Z` */ -// val fixTime: LocalDateTime? = null, + val fixTime: String? = null, /* in IS0 8601 format. eg. `1963-11-22T18:30:00Z` */ -// val serverTime: LocalDateTime? = null, + val serverTime: String? = null, val outdated: Boolean? = null, val valid: Boolean? = null, val latitude: Double? = 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/ReportStops.kt deleted file mode 100644 index bdd4cbe..0000000 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/ReportStops.kt +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Traccar - * Traccar GPS tracking server API documentation. To use the API you need to have a server instance. For testing purposes you can use one of free [demo servers](https://www.traccar.org/demo-server/). For production use you can install your own server or get a [subscription service](https://www.traccar.org/product/tracking-server/). - * - * OpenAPI spec version: 4.14 - * Contact: support@traccar.org - * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git - * Do not edit the class manually. - */ -package mx.trackermap.TrackerMap.client.models - - -/** - * - * @param deviceId - * @param deviceName - * @param duration - * @param startTime in IS0 8601 format. eg. `1963-11-22T18:30:00Z` - * @param address - * @param lat - * @param lon - * @param endTime in IS0 8601 format. eg. `1963-11-22T18:30:00Z` - * @param spentFuel in liters - * @param engineHours - */ -data class ReportStops ( - - 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 address: kotlin.String? = null, - val lat: java.math.BigDecimal? = null, - val lon: java.math.BigDecimal? = null, - /* in IS0 8601 format. eg. `1963-11-22T18:30:00Z` */ - val endTime: java.time.LocalDateTime? = null, - /* in liters */ - val spentFuel: java.math.BigDecimal? = null, - val engineHours: kotlin.Int? = null -) { -} \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Stop.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Stop.kt new file mode 100644 index 0000000..c06b864 --- /dev/null +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Stop.kt @@ -0,0 +1,47 @@ +/** + * Traccar + * Traccar GPS tracking server API documentation. To use the API you need to have a server instance. For testing purposes you can use one of free [demo servers](https://www.traccar.org/demo-server/). For production use you can install your own server or get a [subscription service](https://www.traccar.org/product/tracking-server/). + * + * OpenAPI spec version: 4.14 + * Contact: support@traccar.org + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ +package mx.trackermap.TrackerMap.client.models + +import kotlinx.serialization.Serializable + + +/** + * + * @param deviceId + * @param deviceName + * @param duration + * @param startTime in IS0 8601 format. eg. `1963-11-22T18:30:00Z` + * @param address + * @param lat + * @param lon + * @param endTime in IS0 8601 format. eg. `1963-11-22T18:30:00Z` + * @param spentFuel in liters + * @param engineHours + */ +@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: String? = null, + val address: kotlin.String? = null, + val lat: Double? = null, + val lon: Double? = null, + /* in IS0 8601 format. eg. `1963-11-22T18:30:00Z` */ + val endTime: String? = null, + /* in liters */ + val spentFuel: Double? = null, + val engineHours: kotlin.Int? = null +) { +} \ No newline at end of file -- cgit v1.2.3