aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2021-12-04 14:08:43 -0600
committerIván Ávalos <avalos@disroot.org>2021-12-04 14:08:43 -0600
commit707250d85de9459fac363bb31562a812cd095769 (patch)
treefdec150435fe1bbeb9e8583864d442ea30861d31 /shared/src/commonMain/kotlin/mx/trackermap/TrackerMap
parent3d1d65282ac4159a539c1158e6d0ec74f971e177 (diff)
downloadetbsa-trackermap-mobile-707250d85de9459fac363bb31562a812cd095769.tar.gz
etbsa-trackermap-mobile-707250d85de9459fac363bb31562a812cd095769.tar.bz2
etbsa-trackermap-mobile-707250d85de9459fac363bb31562a812cd095769.zip
Replaced Java stuff with Kotlin native stuff, and deleted ApplicationDelegates (probably useless)
Diffstat (limited to 'shared/src/commonMain/kotlin/mx/trackermap/TrackerMap')
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt2
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApplicationDelegates.kt29
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/Errors.kt3
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateAdapter.kt8
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateTimeAdapter.kt8
5 files changed, 8 insertions, 42 deletions
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 0f1d7da..c44d473 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
@@ -8,7 +8,6 @@ import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.util.*
-import java.io.File
open class ApiClient(val baseUrl: String) {
companion object {
@@ -35,7 +34,6 @@ open class ApiClient(val baseUrl: String) {
protected inline fun <reified T> fillRequest(requestBuilder: HttpRequestBuilder, content: T, mediaType: String = ApiJsonMediaType) {
when {
- content is File -> TODO("i don't know what to do here.")
mediaType == ApiFormDataMediaType && content is Map<*, *> -> {
val parametersBuilder = ParametersBuilder()
content.forEach { map ->
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApplicationDelegates.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApplicationDelegates.kt
deleted file mode 100644
index 7b91344..0000000
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApplicationDelegates.kt
+++ /dev/null
@@ -1,29 +0,0 @@
-package mx.trackermap.TrackerMap.client.infrastructure
-
-import kotlin.properties.ReadWriteProperty
-import kotlin.reflect.KProperty
-
-object ApplicationDelegates {
- /**
- * Provides a property delegate, allowing the property to be set once and only once.
- *
- * If unset (no default value), a get on the property will throw [IllegalStateException].
- */
- fun <T> setOnce(defaultValue: T? = null): ReadWriteProperty<Any?, T> = SetOnce(defaultValue)
-
- private class SetOnce<T>(defaultValue: T? = null) : ReadWriteProperty<Any?, T> {
- private var isSet = false
- private var value: T? = defaultValue
-
- override fun getValue(thisRef: Any?, property: KProperty<*>): T {
- return value ?: throw IllegalStateException("${property.name} not initialized")
- }
-
- override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) = synchronized(this) {
- if (!isSet) {
- this.value = value
- isSet = true
- }
- }
- }
-} \ No newline at end of file
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/Errors.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/Errors.kt
index 8932856..3c44140 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/Errors.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/Errors.kt
@@ -1,8 +1,5 @@
-@file:Suppress("unused")
package mx.trackermap.TrackerMap.client.infrastructure
-import java.lang.RuntimeException
-
open class ClientException : RuntimeException {
/**
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateAdapter.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateAdapter.kt
index 6b73b60..7142665 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateAdapter.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateAdapter.kt
@@ -1,14 +1,14 @@
package mx.trackermap.TrackerMap.client.infrastructure
-import java.time.LocalDate
-import java.time.format.DateTimeFormatter
+import kotlinx.datetime.LocalDate
+
class LocalDateAdapter {
fun toJson(value: LocalDate): String {
- return DateTimeFormatter.ISO_LOCAL_DATE.format(value)
+ return value.toString()
}
fun fromJson(value: String): LocalDate {
- return LocalDate.parse(value, DateTimeFormatter.ISO_LOCAL_DATE_TIME)
+ return LocalDate.parse(value)
}
} \ No newline at end of file
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateTimeAdapter.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateTimeAdapter.kt
index 1534448..d073ff4 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateTimeAdapter.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/LocalDateTimeAdapter.kt
@@ -1,15 +1,15 @@
package mx.trackermap.TrackerMap.client.infrastructure
-import java.time.LocalDateTime
-import java.time.format.DateTimeFormatter
+import kotlinx.datetime.LocalDateTime
+
class LocalDateTimeAdapter {
fun toJson(value: LocalDateTime): String {
- return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(value)
+ return value.toString()
}
fun fromJson(value: String): LocalDateTime {
- return LocalDateTime.parse(value, DateTimeFormatter.ISO_LOCAL_DATE_TIME)
+ return LocalDateTime.parse(value)
}
} \ No newline at end of file