diff options
28 files changed, 195 insertions, 117 deletions
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 1811733..2901dbb 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt @@ -29,14 +29,13 @@ open class TrackerApp : Application() { super.onCreate() val appModule = module { - single { "https://etbsa.net/api" } - factory { SessionApi(get()) } - factory { UsersApi(get()) } - factory { DevicesApi(get()) } - factory { PositionsApi(get()) } - factory { CommandsApi(get()) } - factory { ReportsApi(get()) } - factory { GeofencesApi(get()) } + factory { SessionApi() } + factory { UsersApi() } + factory { DevicesApi() } + factory { PositionsApi() } + factory { CommandsApi() } + factory { ReportsApi() } + factory { GeofencesApi() } factory { SessionController(get(), get()) } factory { UnitsController(get(), get()) } diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt index f1b23a6..c87e134 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt @@ -7,7 +7,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast -import androidx.core.widget.doAfterTextChanged import androidx.fragment.app.Fragment import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.preference.PreferenceManager @@ -43,6 +42,14 @@ class LoginFragment : Fragment() { setupEvents() setupObservers() broadcastManager = LocalBroadcastManager.getInstance(activity!!) + binding.urlEditText.setText( + PreferenceManager + .getDefaultSharedPreferences(activity) + .getString( + PREFERENCE_SERVER_URL, + getString(R.string.default_server_url) + ) ?: getString(R.string.default_server_url) + ) loginViewModel.restoreSession() } @@ -67,6 +74,7 @@ class LoginFragment : Fragment() { loginViewModel.login( binding.usernameEditText.text.toString(), binding.passwordEditText.text.toString(), + binding.urlEditText.text.toString(), PreferenceManager .getDefaultSharedPreferences(activity) .getString(PREFERENCE_TOKEN, null) @@ -84,6 +92,10 @@ class LoginFragment : Fragment() { SessionController.LoginState.Loading -> { binding.infoLoading.root.visibility = View.VISIBLE } + SessionController.LoginState.UrlMissing -> { + binding.infoLoading.root.visibility = View.GONE + Toast.makeText(context, getString(R.string.login_url_missing), Toast.LENGTH_SHORT).show() + } SessionController.LoginState.EmailMissing -> { binding.infoLoading.root.visibility = View.GONE Toast.makeText(context, getString(R.string.login_username_missing), Toast.LENGTH_SHORT).show() @@ -97,6 +109,12 @@ class LoginFragment : Fragment() { Toast.makeText(context, getString(R.string.login_login_failed), Toast.LENGTH_SHORT).show() } SessionController.LoginState.Success -> { + PreferenceManager + .getDefaultSharedPreferences(activity) + .edit() + .putString(PREFERENCE_SERVER_URL, binding.urlEditText.text.toString()) + .apply() + broadcastManager.sendBroadcast(Intent(EVENT_LOGIN)) val activity = requireActivity() val intent = Intent(activity.applicationContext, UnitsActivity::class.java) @@ -126,6 +144,7 @@ class LoginFragment : Fragment() { const val EVENT_TOKEN = "eventToken" const val KEY_TOKEN = "keyToken" + const val PREFERENCE_SERVER_URL = "server_url" const val PREFERENCE_TOKEN = "token" } }
\ No newline at end of file diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt index 88b56cf..b5516e7 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt @@ -40,7 +40,7 @@ class LoginViewModel : ViewModel(), KoinComponent { sessionController.restoreSession() } - fun login(email: String, password: String, token: String?) { - sessionController.login(SessionBody(email, password, token)) + fun login(email: String, password: String, url: String, token: String?) { + sessionController.login(SessionBody(url, email, password, token)) } }
\ No newline at end of file diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/UserInformationActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/UserInformationActivity.kt index 5fad118..81577c7 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/UserInformationActivity.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/UserInformationActivity.kt @@ -65,6 +65,11 @@ class UserInformationActivity : AppCompatActivity() { emailInfo.text = user.email ?: "" idInfo.text = "${user.id ?: "--"}" adminInfo.text = "${user.administrator}" + serverInfo.text = "${ + PreferenceManager + .getDefaultSharedPreferences(this@UserInformationActivity) + .getString(LoginFragment.PREFERENCE_SERVER_URL, getString(R.string.default_server_url)) + }" user.deviceLimit?.let { deviceLimitInfo.text = "${user.deviceLimit ?: "--"}" if (it > 0) { diff --git a/androidApp/src/main/res/layout/login.xml b/androidApp/src/main/res/layout/login.xml index 7c79e5c..78c3e46 100644 --- a/androidApp/src/main/res/layout/login.xml +++ b/androidApp/src/main/res/layout/login.xml @@ -70,8 +70,8 @@ app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/usernameInputLayout" - app:layout_constraintBottom_toTopOf="@id/signinButton" - android:layout_marginTop="24dp"> + app:layout_constraintBottom_toTopOf="@id/urlInputLayout" + android:layout_marginTop="@dimen/fields_spacing"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/passwordEditText" @@ -81,17 +81,38 @@ </com.google.android.material.textfield.TextInputLayout> + <com.google.android.material.textfield.TextInputLayout + android:id="@+id/urlInputLayout" + style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:hint="@string/login_url" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.5" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/passwordInputLayout" + app:layout_constraintBottom_toTopOf="@id/signinButton" + android:layout_marginTop="@dimen/fields_spacing"> + + <com.google.android.material.textfield.TextInputEditText + android:id="@+id/urlEditText" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:inputType="textUri"/> + + </com.google.android.material.textfield.TextInputLayout> + <com.google.android.material.button.MaterialButton android:id="@+id/signinButton" android:layout_width="0dp" android:layout_height="wrap_content" app:layout_constraintWidth_percent="0.5" - app:layout_constraintTop_toBottomOf="@id/passwordInputLayout" + app:layout_constraintTop_toBottomOf="@id/urlInputLayout" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_bias="0.5" - android:layout_marginTop="24dp" + android:layout_marginTop="@dimen/fields_large_spacing" android:text="@string/login_login"/> </androidx.constraintlayout.widget.ConstraintLayout> diff --git a/androidApp/src/main/res/layout/user_information_activity.xml b/androidApp/src/main/res/layout/user_information_activity.xml index 45e747c..f223522 100644 --- a/androidApp/src/main/res/layout/user_information_activity.xml +++ b/androidApp/src/main/res/layout/user_information_activity.xml @@ -131,6 +131,20 @@ android:layout_marginBottom="@dimen/fields_spacing" tools:text="Admin" /> + <TextView + android:id="@+id/serverInfoLabel" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/login_url" + android:textAppearance="@style/TextAppearance.AppCompat.Body2"/> + + <TextView + android:id="@+id/serverInfo" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/fields_spacing" + tools:text="@string/default_server_url" /> + <com.google.android.material.button.MaterialButton android:id="@+id/signoutButton" android:layout_width="match_parent" diff --git a/androidApp/src/main/res/values-es-rMX/strings.xml b/androidApp/src/main/res/values-es-rMX/strings.xml index 2645205..8792b08 100644 --- a/androidApp/src/main/res/values-es-rMX/strings.xml +++ b/androidApp/src/main/res/values-es-rMX/strings.xml @@ -10,10 +10,12 @@ <!-- LoginActivity --> <string name="login_username">Nombre de usuario</string> <string name="login_password">Contraseña</string> + <string name="login_url">URL del servidor</string> <string name="login_login">Iniciar sesión</string> <string name="login_username_missing">Falta el nombre de usuario</string> <string name="login_password_missing">Falta la contraseña</string> + <string name="login_url_missing">Falta la URL del servidor</string> <string name="login_login_failed">Falló el inicio de sesión</string> <!-- UnitsActivity --> diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index 8e59b14..a6cba19 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name" translatable="false">TrackerMap</string> + <string name="default_server_url" translatable="false">https://gps.trackermap.mx/api</string> <!-- Non translatable --> <string name="app_website_url" translatable="false">https://trackermap.mx/</string> @@ -23,10 +24,12 @@ <!-- LoginActivity --> <string name="login_username">Username</string> <string name="login_password">Password</string> + <string name="login_url">Server URL</string> <string name="login_login">Login</string> <string name="login_username_missing">Username is missing</string> <string name="login_password_missing">Password is missing</string> + <string name="login_url_missing">Server URL is missing</string> <string name="login_login_failed">Login failed</string> <!-- UnitsActivity --> diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/AttributesApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/AttributesApi.kt index 388df19..1c9b663 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/AttributesApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/AttributesApi.kt @@ -15,7 +15,7 @@ import mx.trackermap.TrackerMap.client.models.Attribute import mx.trackermap.TrackerMap.client.infrastructure.* -class AttributesApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class AttributesApi : ApiClient() { /** * Fetch a list of Attributes @@ -28,18 +28,18 @@ class AttributesApi(basePath: kotlin.String = "https://demo.traccar.org/api") : * @return kotlin.Array<Attribute> */ @Suppress("UNCHECKED_CAST") - suspend fun attributesComputedGet(all: kotlin.Boolean? = null, userId: kotlin.Int? = null, deviceId: kotlin.Int? = null, groupId: kotlin.Int? = null, refresh: kotlin.Boolean? = null): kotlin.Array<Attribute> { + suspend fun attributesComputedGet(all: Boolean? = null, userId: Int? = null, deviceId: Int? = null, groupId: Int? = null, refresh: Boolean? = null): Array<Attribute> { 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 localVariableConfig = RequestConfig( RequestMethod.GET, "/attributes/computed", query = localVariableQuery ) - val response = request<kotlin.Array<Attribute>>( + val response = request<Array<Attribute>>( localVariableConfig ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Attribute> + ResponseType.Success -> (response as Success<*>).data as Array<Attribute> ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") @@ -52,7 +52,7 @@ class AttributesApi(basePath: kotlin.String = "https://demo.traccar.org/api") : * @param id * @return void */ - suspend fun attributesComputedIdDelete(id: kotlin.Int): Unit { + suspend fun attributesComputedIdDelete(id: Int) { val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -78,8 +78,8 @@ class AttributesApi(basePath: kotlin.String = "https://demo.traccar.org/api") : * @return Attribute */ @Suppress("UNCHECKED_CAST") - suspend fun attributesComputedIdPut(body: Attribute, id: kotlin.Int): Attribute { - val localVariableBody: kotlin.Any? = body + suspend fun attributesComputedIdPut(body: Attribute, id: Int): Attribute { + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -105,7 +105,7 @@ class AttributesApi(basePath: kotlin.String = "https://demo.traccar.org/api") : */ @Suppress("UNCHECKED_CAST") suspend fun attributesComputedPost(body: Attribute): Attribute { - val localVariableBody: kotlin.Any? = body + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/CalendarsApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/CalendarsApi.kt index 70e3a02..56ee7b5 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/CalendarsApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/CalendarsApi.kt @@ -15,7 +15,7 @@ import mx.trackermap.TrackerMap.client.models.Calendar import mx.trackermap.TrackerMap.client.infrastructure.* -class CalendarsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class CalendarsApi : ApiClient() { /** * Fetch a list of Calendars @@ -25,18 +25,18 @@ class CalendarsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : A * @return kotlin.Array<Calendar> */ @Suppress("UNCHECKED_CAST") - suspend fun calendarsGet(all: kotlin.Boolean? = null, userId: kotlin.Int? = null): kotlin.Array<Calendar> { + suspend fun calendarsGet(all: Boolean? = null, userId: Int? = null): Array<Calendar> { val localVariableQuery: MultiValueMap = mapOf("all" to listOf("$all"), "userId" to listOf("$userId")) val localVariableConfig = RequestConfig( RequestMethod.GET, "/calendars", query = localVariableQuery ) - val response = request<kotlin.Array<Calendar>>( + val response = request<Array<Calendar>>( localVariableConfig ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Calendar> + ResponseType.Success -> (response as Success<*>).data as Array<Calendar> ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") @@ -49,7 +49,7 @@ class CalendarsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : A * @param id * @return void */ - suspend fun calendarsIdDelete(id: kotlin.Int): Unit { + suspend fun calendarsIdDelete(id: Int) { val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -75,8 +75,8 @@ class CalendarsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : A * @return Calendar */ @Suppress("UNCHECKED_CAST") - suspend fun calendarsIdPut(body: Calendar, id: kotlin.Int): Calendar { - val localVariableBody: kotlin.Any? = body + suspend fun calendarsIdPut(body: Calendar, id: Int): Calendar { + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -102,7 +102,7 @@ class CalendarsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : A */ @Suppress("UNCHECKED_CAST") suspend fun calendarsPost(body: Calendar): Calendar { - val localVariableBody: kotlin.Any? = body + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.POST, 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 e840888..f00bc93 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 @@ -16,7 +16,7 @@ import mx.trackermap.TrackerMap.client.models.CommandType import mx.trackermap.TrackerMap.client.infrastructure.* -class CommandsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class CommandsApi : ApiClient() { /** * Fetch a list of Saved Commands @@ -29,7 +29,7 @@ class CommandsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Ap * @return kotlin.Array<Command> */ @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> { + suspend fun commandsGet(all: Boolean? = null, userId: Int? = null, deviceId: Int? = null, groupId: Int? = null, refresh: Boolean? = null): Array<Command> { val query: MutableMap<String, List<String>> = mutableMapOf() all?.let { query["all"] = listOf("$it") } userId?.let { query["userId"] = listOf("$it") } @@ -42,12 +42,12 @@ class CommandsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Ap RequestMethod.GET, "/commands", query = localVariableQuery ) - val response = request<kotlin.Array<Command>>( + val response = request<Array<Command>>( localVariableConfig ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Command> + ResponseType.Success -> (response as Success<*>).data as Array<Command> ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") @@ -60,7 +60,7 @@ class CommandsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Ap * @param id * @return void */ - suspend fun commandsIdDelete(id: kotlin.Int): Unit { + suspend fun commandsIdDelete(id: Int) { val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -86,8 +86,8 @@ class CommandsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Ap * @return Command */ @Suppress("UNCHECKED_CAST") - suspend fun commandsIdPut(body: Command, id: kotlin.Int): Command { - val localVariableBody: kotlin.Any? = body + suspend fun commandsIdPut(body: Command, id: Int): Command { + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -113,7 +113,7 @@ class CommandsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Ap */ @Suppress("UNCHECKED_CAST") suspend fun commandsPost(body: Command): Command { - val localVariableBody: kotlin.Any? = body + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -138,18 +138,18 @@ class CommandsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Ap * @return kotlin.Array<Command> */ @Suppress("UNCHECKED_CAST") - suspend fun commandsSendGet(deviceId: kotlin.Int? = null): kotlin.Array<Command> { + suspend fun commandsSendGet(deviceId: Int? = null): Array<Command> { val localVariableQuery: MultiValueMap = mapOf("deviceId" to listOf("$deviceId")) val localVariableConfig = RequestConfig( RequestMethod.GET, "/commands/send", query = localVariableQuery ) - val response = request<kotlin.Array<Command>>( + val response = request<Array<Command>>( localVariableConfig ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Command> + ResponseType.Success -> (response as Success<*>).data as Array<Command> ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") @@ -164,7 +164,7 @@ class CommandsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Ap */ @Suppress("UNCHECKED_CAST") suspend fun commandsSendPost(body: Command): Command { - val localVariableBody: kotlin.Any? = body + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -191,18 +191,18 @@ class CommandsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Ap * @return kotlin.Array<CommandType> */ @Suppress("UNCHECKED_CAST") - suspend fun commandsTypesGet(deviceId: kotlin.Int? = null, protocol: kotlin.String? = null, textChannel: kotlin.Boolean? = null): kotlin.Array<CommandType> { + suspend fun commandsTypesGet(deviceId: Int? = null, protocol: String? = null, textChannel: Boolean? = null): Array<CommandType> { val localVariableQuery: MultiValueMap = mapOf("deviceId" to listOf("$deviceId"), "protocol" to listOf("$protocol"), "textChannel" to listOf("$textChannel")) val localVariableConfig = RequestConfig( RequestMethod.GET, "/commands/types", query = localVariableQuery ) - val response = request<kotlin.Array<CommandType>>( + val response = request<Array<CommandType>>( localVariableConfig ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array<CommandType> + ResponseType.Success -> (response as Success<*>).data as Array<CommandType> ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/DevicesApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/DevicesApi.kt index 331cc4e..22903d1 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/DevicesApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/DevicesApi.kt @@ -16,7 +16,7 @@ import mx.trackermap.TrackerMap.client.models.DeviceAccumulators import mx.trackermap.TrackerMap.client.infrastructure.* -class DevicesApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class DevicesApi : ApiClient() { /** * Fetch a list of Devices @@ -28,24 +28,24 @@ class DevicesApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Api * @return kotlin.Array<Device> */ @Suppress("UNCHECKED_CAST") - suspend fun devicesGet(all: kotlin.Boolean? = null, userId: kotlin.Int? = null, id: kotlin.Int? = null, uniqueId: kotlin.String? = null): kotlin.Array<Device> { + suspend fun devicesGet(all: Boolean? = null, userId: Int? = null, id: Int? = null, uniqueId: String? = null): Array<Device> { val query: MutableMap<String, List<String>> = mutableMapOf() all?.let { query["all"] = listOf("$it") } userId?.let { query["userId"] = listOf("$it") } id?.let { query["id"] = listOf("$it") } - uniqueId?.let { query["uniqueId"] = listOf("$it") } + uniqueId?.let { query["uniqueId"] = listOf(it) } val localVariableQuery: MultiValueMap = query val localVariableConfig = RequestConfig( RequestMethod.GET, "/devices", query = localVariableQuery ) - val response = request<kotlin.Array<Device>>( + val response = request<Array<Device>>( localVariableConfig ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Device> + ResponseType.Success -> (response as Success<*>).data as Array<Device> ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") @@ -59,8 +59,8 @@ class DevicesApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Api * @param id * @return void */ - suspend fun devicesIdAccumulatorsPut(body: DeviceAccumulators, id: kotlin.Int): Unit { - val localVariableBody: kotlin.Any? = body + suspend fun devicesIdAccumulatorsPut(body: DeviceAccumulators, id: Int) { + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -84,7 +84,7 @@ class DevicesApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Api * @param id * @return void */ - suspend fun devicesIdDelete(id: kotlin.Int): Unit { + suspend fun devicesIdDelete(id: Int) { val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -110,8 +110,8 @@ class DevicesApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Api * @return Device */ @Suppress("UNCHECKED_CAST") - suspend fun devicesIdPut(body: Device, id: kotlin.Int): Device { - val localVariableBody: kotlin.Any? = body + suspend fun devicesIdPut(body: Device, id: Int): Device { + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -137,7 +137,7 @@ class DevicesApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Api */ @Suppress("UNCHECKED_CAST") suspend fun devicesPost(body: Device): Device { - val localVariableBody: kotlin.Any? = body + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/DriversApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/DriversApi.kt index 2a8f92c..7cf26d0 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/DriversApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/DriversApi.kt @@ -15,7 +15,7 @@ import mx.trackermap.TrackerMap.client.models.Driver import mx.trackermap.TrackerMap.client.infrastructure.* -class DriversApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class DriversApi : ApiClient() { /** * Fetch a list of Drivers @@ -28,18 +28,18 @@ class DriversApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Api * @return kotlin.Array<Driver> */ @Suppress("UNCHECKED_CAST") - suspend fun driversGet(all: kotlin.Boolean? = null, userId: kotlin.Int? = null, deviceId: kotlin.Int? = null, groupId: kotlin.Int? = null, refresh: kotlin.Boolean? = null): kotlin.Array<Driver> { + suspend fun driversGet(all: Boolean? = null, userId: Int? = null, deviceId: Int? = null, groupId: Int? = null, refresh: Boolean? = null): Array<Driver> { 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 localVariableConfig = RequestConfig( RequestMethod.GET, "/drivers", query = localVariableQuery ) - val response = request<kotlin.Array<Driver>>( + val response = request<Array<Driver>>( localVariableConfig ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Driver> + ResponseType.Success -> (response as Success<*>).data as Array<Driver> ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") @@ -52,7 +52,7 @@ class DriversApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Api * @param id * @return void */ - suspend fun driversIdDelete(id: kotlin.Int): Unit { + suspend fun driversIdDelete(id: Int) { val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -78,8 +78,8 @@ class DriversApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Api * @return Driver */ @Suppress("UNCHECKED_CAST") - suspend fun driversIdPut(body: Driver, id: kotlin.Int): Driver { - val localVariableBody: kotlin.Any? = body + suspend fun driversIdPut(body: Driver, id: Int): Driver { + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -105,7 +105,7 @@ class DriversApi(basePath: kotlin.String = "https://demo.traccar.org/api") : Api */ @Suppress("UNCHECKED_CAST") suspend fun driversPost(body: Driver): Driver { - val localVariableBody: kotlin.Any? = body + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/EventsApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/EventsApi.kt index 8c1f2b0..5e5b8e6 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/EventsApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/EventsApi.kt @@ -15,7 +15,7 @@ import mx.trackermap.TrackerMap.client.models.Event import mx.trackermap.TrackerMap.client.infrastructure.* -class EventsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class EventsApi : ApiClient() { /** * @@ -24,7 +24,7 @@ class EventsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiC * @return Event */ @Suppress("UNCHECKED_CAST") - suspend fun eventsIdGet(id: kotlin.Int): Event { + suspend fun eventsIdGet(id: Int): Event { val localVariableConfig = RequestConfig( RequestMethod.GET, diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/GeofencesApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/GeofencesApi.kt index dd9c89d..23ac8c8 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/GeofencesApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/GeofencesApi.kt @@ -15,7 +15,7 @@ import mx.trackermap.TrackerMap.client.models.Geofence import mx.trackermap.TrackerMap.client.infrastructure.* -class GeofencesApi(basePath: String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class GeofencesApi : ApiClient() { /** * Fetch a list of Geofences diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/GroupsApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/GroupsApi.kt index c86e66c..3b0dfa1 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/GroupsApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/GroupsApi.kt @@ -15,7 +15,7 @@ import mx.trackermap.TrackerMap.client.models.Group import mx.trackermap.TrackerMap.client.infrastructure.* -class GroupsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class GroupsApi : ApiClient() { /** * Fetch a list of Groups @@ -25,18 +25,18 @@ class GroupsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiC * @return kotlin.Array<Group> */ @Suppress("UNCHECKED_CAST") - suspend fun groupsGet(all: kotlin.Boolean? = null, userId: kotlin.Int? = null): kotlin.Array<Group> { + suspend fun groupsGet(all: Boolean? = null, userId: Int? = null): Array<Group> { val localVariableQuery: MultiValueMap = mapOf("all" to listOf("$all"), "userId" to listOf("$userId")) val localVariableConfig = RequestConfig( RequestMethod.GET, "/groups", query = localVariableQuery ) - val response = request<kotlin.Array<Group>>( + val response = request<Array<Group>>( localVariableConfig ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Group> + ResponseType.Success -> (response as Success<*>).data as Array<Group> ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") @@ -49,7 +49,7 @@ class GroupsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiC * @param id * @return void */ - suspend fun groupsIdDelete(id: kotlin.Int): Unit { + suspend fun groupsIdDelete(id: Int) { val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -75,8 +75,8 @@ class GroupsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiC * @return Group */ @Suppress("UNCHECKED_CAST") - suspend fun groupsIdPut(body: Group, id: kotlin.Int): Group { - val localVariableBody: kotlin.Any? = body + suspend fun groupsIdPut(body: Group, id: Int): Group { + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -102,7 +102,7 @@ class GroupsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiC */ @Suppress("UNCHECKED_CAST") suspend fun groupsPost(body: Group): Group { - val localVariableBody: kotlin.Any? = body + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/MaintenanceApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/MaintenanceApi.kt index 7fcee92..92480fe 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/MaintenanceApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/MaintenanceApi.kt @@ -15,7 +15,7 @@ import mx.trackermap.TrackerMap.client.models.Maintenance import mx.trackermap.TrackerMap.client.infrastructure.* -class MaintenanceApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class MaintenanceApi : ApiClient() { /** * Fetch a list of Maintenance @@ -28,18 +28,18 @@ class MaintenanceApi(basePath: kotlin.String = "https://demo.traccar.org/api") : * @return kotlin.Array<Maintenance> */ @Suppress("UNCHECKED_CAST") - suspend fun maintenanceGet(all: kotlin.Boolean? = null, userId: kotlin.Int? = null, deviceId: kotlin.Int? = null, groupId: kotlin.Int? = null, refresh: kotlin.Boolean? = null): kotlin.Array<Maintenance> { + suspend fun maintenanceGet(all: Boolean? = null, userId: Int? = null, deviceId: Int? = null, groupId: Int? = null, refresh: Boolean? = null): Array<Maintenance> { 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 localVariableConfig = RequestConfig( RequestMethod.GET, "/maintenance", query = localVariableQuery ) - val response = request<kotlin.Array<Maintenance>>( + val response = request<Array<Maintenance>>( localVariableConfig ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Maintenance> + ResponseType.Success -> (response as Success<*>).data as Array<Maintenance> ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") @@ -52,7 +52,7 @@ class MaintenanceApi(basePath: kotlin.String = "https://demo.traccar.org/api") : * @param id * @return void */ - suspend fun maintenanceIdDelete(id: kotlin.Int): Unit { + suspend fun maintenanceIdDelete(id: Int) { val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -78,8 +78,8 @@ class MaintenanceApi(basePath: kotlin.String = "https://demo.traccar.org/api") : * @return Maintenance */ @Suppress("UNCHECKED_CAST") - suspend fun maintenanceIdPut(body: Maintenance, id: kotlin.Int): Maintenance { - val localVariableBody: kotlin.Any? = body + suspend fun maintenanceIdPut(body: Maintenance, id: Int): Maintenance { + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -105,7 +105,7 @@ class MaintenanceApi(basePath: kotlin.String = "https://demo.traccar.org/api") : */ @Suppress("UNCHECKED_CAST") suspend fun maintenancePost(body: Maintenance): Maintenance { - val localVariableBody: kotlin.Any? = body + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/NotificationsApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/NotificationsApi.kt index 86c34d0..1f0d744 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/NotificationsApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/NotificationsApi.kt @@ -16,7 +16,7 @@ import mx.trackermap.TrackerMap.client.models.NotificationType import mx.trackermap.TrackerMap.client.infrastructure.* -class NotificationsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class NotificationsApi : ApiClient() { /** * Fetch a list of Notifications @@ -29,18 +29,18 @@ class NotificationsApi(basePath: kotlin.String = "https://demo.traccar.org/api") * @return kotlin.Array<Notification> */ @Suppress("UNCHECKED_CAST") - suspend fun notificationsGet(all: kotlin.Boolean? = null, userId: kotlin.Int? = null, deviceId: kotlin.Int? = null, groupId: kotlin.Int? = null, refresh: kotlin.Boolean? = null): kotlin.Array<Notification> { + suspend fun notificationsGet(all: Boolean? = null, userId: Int? = null, deviceId: Int? = null, groupId: Int? = null, refresh: Boolean? = null): Array<Notification> { 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 localVariableConfig = RequestConfig( RequestMethod.GET, "/notifications", query = localVariableQuery ) - val response = request<kotlin.Array<Notification>>( + val response = request<Array<Notification>>( localVariableConfig ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Notification> + ResponseType.Success -> (response as Success<*>).data as Array<Notification> ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") @@ -53,7 +53,7 @@ class NotificationsApi(basePath: kotlin.String = "https://demo.traccar.org/api") * @param id * @return void */ - suspend fun notificationsIdDelete(id: kotlin.Int): Unit { + suspend fun notificationsIdDelete(id: Int) { val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -79,8 +79,8 @@ class NotificationsApi(basePath: kotlin.String = "https://demo.traccar.org/api") * @return Notification */ @Suppress("UNCHECKED_CAST") - suspend fun notificationsIdPut(body: Notification, id: kotlin.Int): Notification { - val localVariableBody: kotlin.Any? = body + suspend fun notificationsIdPut(body: Notification, id: Int): Notification { + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -106,7 +106,7 @@ class NotificationsApi(basePath: kotlin.String = "https://demo.traccar.org/api") */ @Suppress("UNCHECKED_CAST") suspend fun notificationsPost(body: Notification): Notification { - val localVariableBody: kotlin.Any? = body + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -129,7 +129,7 @@ class NotificationsApi(basePath: kotlin.String = "https://demo.traccar.org/api") * * @return void */ - suspend fun notificationsTestPost(): Unit { + suspend fun notificationsTestPost(){ val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -153,18 +153,18 @@ class NotificationsApi(basePath: kotlin.String = "https://demo.traccar.org/api") * @return kotlin.Array<NotificationType> */ @Suppress("UNCHECKED_CAST") - suspend fun notificationsTypesGet(): kotlin.Array<NotificationType> { + suspend fun notificationsTypesGet(): Array<NotificationType> { val localVariableConfig = RequestConfig( RequestMethod.GET, "/notifications/types" ) - val response = request<kotlin.Array<NotificationType>>( + val response = request<Array<NotificationType>>( localVariableConfig ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array<NotificationType> + ResponseType.Success -> (response as Success<*>).data as Array<NotificationType> ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/PermissionsApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/PermissionsApi.kt index bfa2c2e..02c9348 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/PermissionsApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/PermissionsApi.kt @@ -15,7 +15,7 @@ import mx.trackermap.TrackerMap.client.models.Permission import mx.trackermap.TrackerMap.client.infrastructure.* -class PermissionsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class PermissionsApi : ApiClient() { /** * Unlink an Object from another Object @@ -23,8 +23,8 @@ class PermissionsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : * @param body * @return void */ - suspend fun permissionsDelete(body: Permission): Unit { - val localVariableBody: kotlin.Any? = body + suspend fun permissionsDelete(body: Permission) { + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -50,7 +50,7 @@ class PermissionsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : */ @Suppress("UNCHECKED_CAST") suspend fun permissionsPost(body: Permission): Permission { - val localVariableBody: kotlin.Any? = body + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/PositionsApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/PositionsApi.kt index 278611f..ecbf649 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/PositionsApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/PositionsApi.kt @@ -15,7 +15,7 @@ import mx.trackermap.TrackerMap.client.models.Position import mx.trackermap.TrackerMap.client.infrastructure.* -class PositionsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class PositionsApi : ApiClient() { /** * Fetches a list of Positions @@ -27,7 +27,7 @@ class PositionsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : A * @return kotlin.Array<Position> */ @Suppress("UNCHECKED_CAST") - suspend fun positionsGet(deviceId: kotlin.Int? = null, from: LocalDateTimeAdapter? = null, to: LocalDateTimeAdapter? = null, id: kotlin.Int? = null): kotlin.Array<Position> { + suspend fun positionsGet(deviceId: Int? = null, from: LocalDateTimeAdapter? = null, to: LocalDateTimeAdapter? = null, id: Int? = null): Array<Position> { val query: MutableMap<String, List<String>> = mutableMapOf() deviceId?.let { query["deviceId"] = listOf("$it") } from?.let { query["from"] = listOf("$it") } @@ -39,12 +39,12 @@ class PositionsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : A RequestMethod.GET, "/positions", query = localVariableQuery ) - val response = request<kotlin.Array<Position>>( + val response = request<Array<Position>>( localVariableConfig ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Position> + ResponseType.Success -> (response as Success<*>).data as Array<Position> ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") 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 d77064e..3dbee22 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 @@ -20,7 +20,7 @@ import mx.trackermap.TrackerMap.client.models.ReportTrips import mx.trackermap.TrackerMap.client.infrastructure.* -class ReportsApi(basePath: String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class ReportsApi : ApiClient() { /** * Fetch a list of Events within the time period for the Devices or Groups diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ServerApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ServerApi.kt index 659761b..3c7787d 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ServerApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/ServerApi.kt @@ -15,7 +15,7 @@ import mx.trackermap.TrackerMap.client.models.Server import mx.trackermap.TrackerMap.client.infrastructure.* -class ServerApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class ServerApi : ApiClient() { /** * Fetch Server information @@ -49,7 +49,7 @@ class ServerApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiC */ @Suppress("UNCHECKED_CAST") suspend fun serverPut(body: Server): Server { - val localVariableBody: kotlin.Any? = body + val localVariableBody: Any = body val localVariableConfig = RequestConfig( RequestMethod.PUT, diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/SessionApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/SessionApi.kt index b57f126..ad9e450 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/SessionApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/SessionApi.kt @@ -15,9 +15,10 @@ import com.russhwolf.settings.Settings import mx.trackermap.TrackerMap.client.models.User import mx.trackermap.TrackerMap.client.infrastructure.* +const val SERVER_URL_KEY = "server_url" const val ACCESS_TOKEN_KEY = "access_token" -class SessionApi(basePath: String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class SessionApi : ApiClient() { /** * Close the Session @@ -90,7 +91,6 @@ class SessionApi(basePath: String = "https://demo.traccar.org/api") : ApiClient( @Suppress("UNCHECKED_CAST") suspend fun sessionPost(email: String, password: String): User { val localVariableBody = mapOf("email" to email, "password" to password) - val localVariableHeaders = mapOf("Content-Type" to "application/x-www-form-urlencoded") val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/StatisticsApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/StatisticsApi.kt index f7651ac..1857cc5 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/StatisticsApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/StatisticsApi.kt @@ -15,7 +15,7 @@ import mx.trackermap.TrackerMap.client.models.Statistics import mx.trackermap.TrackerMap.client.infrastructure.* -class StatisticsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class StatisticsApi : ApiClient() { /** * Fetch server Statistics @@ -25,18 +25,18 @@ class StatisticsApi(basePath: kotlin.String = "https://demo.traccar.org/api") : * @return kotlin.Array<Statistics> */ @Suppress("UNCHECKED_CAST") - suspend fun statisticsGet(from: java.time.LocalDateTime, to: java.time.LocalDateTime): kotlin.Array<Statistics> { + suspend fun statisticsGet(from: java.time.LocalDateTime, to: java.time.LocalDateTime): Array<Statistics> { val localVariableQuery: MultiValueMap = mapOf("from" to listOf("$from"), "to" to listOf("$to")) val localVariableConfig = RequestConfig( RequestMethod.GET, "/statistics", query = localVariableQuery ) - val response = request<kotlin.Array<Statistics>>( + val response = request<Array<Statistics>>( localVariableConfig ) return when (response.responseType) { - ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Statistics> + ResponseType.Success -> (response as Success<*>).data as Array<Statistics> ResponseType.Informational -> TODO() ResponseType.Redirection -> TODO() ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error") diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/UsersApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/UsersApi.kt index 858cd10..7b8d837 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/UsersApi.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/UsersApi.kt @@ -15,7 +15,7 @@ import mx.trackermap.TrackerMap.client.models.User import mx.trackermap.TrackerMap.client.infrastructure.* -class UsersApi(basePath: String = "https://demo.traccar.org/api") : ApiClient(basePath) { +class UsersApi : ApiClient() { /** * Fetch a list of Users diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt index 606fef0..88aaa26 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt @@ -17,9 +17,10 @@ import io.ktor.client.statement.* import io.ktor.http.* import io.ktor.util.* import mx.trackermap.TrackerMap.client.apis.ACCESS_TOKEN_KEY +import mx.trackermap.TrackerMap.client.apis.SERVER_URL_KEY import kotlinx.serialization.json.Json as KotlinJson -open class ApiClient(val baseUrl: String) { +open class ApiClient() { companion object { protected const val ApiContentType = "Content-Type" protected const val ApiAccept = "Accept" @@ -58,10 +59,12 @@ open class ApiClient(val baseUrl: String) { ) } + var baseUrl: String = "" var token: String = "" init { val settings = Settings() + baseUrl = settings.getString(SERVER_URL_KEY, "") token = settings.getString(ACCESS_TOKEN_KEY, "") } diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Session_body.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Session_body.kt index e98ff34..52c5abc 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Session_body.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/Session_body.kt @@ -12,11 +12,14 @@ package mx.trackermap.TrackerMap.client.models /** - * + * + * @param url * @param email - * @param password + * @param password + * @param fcmToken */ data class SessionBody ( + val url: String, val email: String, val password: String, val fcmToken: String? = null diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt index 2ce4dc6..7d944b7 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt @@ -20,6 +20,7 @@ class SessionController( sealed class LoginState { object Nothing: LoginState() object Loading: LoginState() + object UrlMissing: LoginState() object EmailMissing : LoginState() object PasswordMissing : LoginState() object Failure : LoginState() @@ -58,10 +59,16 @@ class SessionController( } fun login(body: SessionBody) { + val url = body.url.trim() val email = body.email.trim() val password = body.password.trim() val token = body.fcmToken + if (url.isEmpty()) { + loginStateFlow.value = LoginState.UrlMissing + return + } + if (email.isEmpty()) { loginStateFlow.value = LoginState.EmailMissing return @@ -75,6 +82,8 @@ class SessionController( loginStateFlow.value = LoginState.Loading GlobalScope.launch { try { + sessionApi.baseUrl = url + usersApi.baseUrl = sessionApi.baseUrl val session = sessionApi.sessionPost(email, password) userFlow.value = session usersApi.token = sessionApi.token |