Source adding.

This commit is contained in:
aminecmi 2022-05-22 10:46:32 +02:00
parent 4c69e72499
commit 23c823f1a4
3 changed files with 24 additions and 22 deletions

View File

@ -31,7 +31,7 @@ fun SelfossModel.Source.toEntity(): SourceEntity =
this.tags.joinToString(","), this.tags.joinToString(","),
this.spout, this.spout,
this.error, this.error,
this.icon this.icon.orEmpty()
) )
fun SelfossModel.Tag.toEntity(): TagEntity = fun SelfossModel.Tag.toEntity(): TagEntity =

View File

@ -159,9 +159,9 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) {
version: Int version: Int
): SelfossModel.SuccessResponse? = ): SelfossModel.SuccessResponse? =
if (version > 1) { if (version > 1) {
createSource(title, url, spout, tags, filter)
} else {
createSource2(title, url, spout, tags, filter) createSource2(title, url, spout, tags, filter)
} else {
createSource(title, url, spout, tags, filter)
} }
private suspend fun createSource( private suspend fun createSource(
@ -171,15 +171,16 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) {
tags: String, tags: String,
filter: String filter: String
): SelfossModel.SuccessResponse? = ): SelfossModel.SuccessResponse? =
client.post(url("/source")) { client.submitForm(
parameter("username", apiDetailsService.getUserName()) url = url("/source?username=${apiDetailsService.getUserName()}&password=${apiDetailsService.getPassword()}"),
parameter("password", apiDetailsService.getPassword()) formParameters = Parameters.build {
parameter("title", title) append("title", title)
parameter("url", url) append("url", url)
parameter("spout", spout) append("spout", spout)
parameter("tags", tags) append("tags", tags)
parameter("filter", filter) append("filter", filter)
}.body() }
).body()
private suspend fun createSource2( private suspend fun createSource2(
title: String, title: String,
@ -188,15 +189,16 @@ class SelfossApi(private val apiDetailsService: ApiDetailsService) {
tags: String, tags: String,
filter: String filter: String
): SelfossModel.SuccessResponse? = ): SelfossModel.SuccessResponse? =
client.post(url("/source")) { client.submitForm(
parameter("username", apiDetailsService.getUserName()) url = url("/source?username=${apiDetailsService.getUserName()}&password=${apiDetailsService.getPassword()}"),
parameter("password", apiDetailsService.getPassword()) formParameters = Parameters.build {
parameter("title", title) append("title", title)
parameter("url", url) append("url", url)
parameter("spout", spout) append("spout", spout)
parameter("tags[]", tags) append("tags[]", tags)
parameter("filter", filter) append("filter", filter)
}.body() }
).body()
suspend fun deleteSource(id: Int): SelfossModel.SuccessResponse? = suspend fun deleteSource(id: Int): SelfossModel.SuccessResponse? =
client.delete(url("/source/$id")) { client.delete(url("/source/$id")) {

View File

@ -57,7 +57,7 @@ class SelfossModel {
val tags: List<String>, val tags: List<String>,
val spout: String, val spout: String,
val error: String, val error: String,
val icon: String val icon: String?
) )
@Serializable @Serializable