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.spout,
this.error,
this.icon
this.icon.orEmpty()
)
fun SelfossModel.Tag.toEntity(): TagEntity =

View File

@ -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")) {

View File

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