From 23c823f1a4c129496fbce9c6d91cc6b462afc806 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Sun, 22 May 2022 10:46:32 +0200 Subject: [PATCH] Source adding. --- .../utils/persistence/EntitiesUtils.kt | 2 +- .../readerforselfossv2/rest/SelfossApi.kt | 42 ++++++++++--------- .../readerforselfossv2/rest/SelfossModel.kt | 2 +- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/persistence/EntitiesUtils.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/persistence/EntitiesUtils.kt index d0144bc..d165c97 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/persistence/EntitiesUtils.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/persistence/EntitiesUtils.kt @@ -31,7 +31,7 @@ fun SelfossModel.Source.toEntity(): SourceEntity = this.tags.joinToString(","), this.spout, this.error, - this.icon + this.icon.orEmpty() ) fun SelfossModel.Tag.toEntity(): TagEntity = diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt index d63c722..23fc2bd 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt @@ -159,9 +159,9 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) { version: Int ): SelfossModel.SuccessResponse? = if (version > 1) { - createSource(title, url, spout, tags, filter) - } else { createSource2(title, url, spout, tags, filter) + } else { + createSource(title, url, spout, tags, filter) } private suspend fun createSource( @@ -171,15 +171,16 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) { tags: String, filter: String ): SelfossModel.SuccessResponse? = - client.post(url("/source")) { - parameter("username", apiDetailsService.getUserName()) - parameter("password", apiDetailsService.getPassword()) - parameter("title", title) - parameter("url", url) - parameter("spout", spout) - parameter("tags", tags) - parameter("filter", filter) - }.body() + client.submitForm( + url = url("/source?username=${apiDetailsService.getUserName()}&password=${apiDetailsService.getPassword()}"), + formParameters = Parameters.build { + append("title", title) + append("url", url) + append("spout", spout) + append("tags", tags) + append("filter", filter) + } + ).body() private suspend fun createSource2( title: String, @@ -188,15 +189,16 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) { tags: String, filter: String ): SelfossModel.SuccessResponse? = - client.post(url("/source")) { - parameter("username", apiDetailsService.getUserName()) - parameter("password", apiDetailsService.getPassword()) - parameter("title", title) - parameter("url", url) - parameter("spout", spout) - parameter("tags[]", tags) - parameter("filter", filter) - }.body() + client.submitForm( + url = url("/source?username=${apiDetailsService.getUserName()}&password=${apiDetailsService.getPassword()}"), + formParameters = Parameters.build { + append("title", title) + append("url", url) + append("spout", spout) + append("tags[]", tags) + append("filter", filter) + } + ).body() suspend fun deleteSource(id: Int): SelfossModel.SuccessResponse? = client.delete(url("/source/$id")) { diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossModel.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossModel.kt index 396abfa..d620f1d 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossModel.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossModel.kt @@ -57,7 +57,7 @@ class SelfossModel { val tags: List, val spout: String, val error: String, - val icon: String + val icon: String? ) @Serializable