complete client part for content in core
This commit is contained in:
parent
14a40bfef0
commit
9421edcb85
@ -2,14 +2,29 @@ package com.insanusmokrassar.postssystem.core.ktor.client.content
|
|||||||
|
|
||||||
import com.insanusmokrassar.postssystem.core.content.*
|
import com.insanusmokrassar.postssystem.core.content.*
|
||||||
import com.insanusmokrassar.postssystem.core.content.api.WriteContentRepo
|
import com.insanusmokrassar.postssystem.core.content.api.WriteContentRepo
|
||||||
|
import com.insanusmokrassar.postssystem.core.ktor.registerContentRoute
|
||||||
|
import com.insanusmokrassar.postssystem.ktor.standardKtorSerializer
|
||||||
|
import io.ktor.client.HttpClient
|
||||||
|
import io.ktor.client.request.post
|
||||||
|
import io.ktor.client.request.url
|
||||||
|
import kotlinx.serialization.builtins.nullable
|
||||||
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
class WriteContentRepoKtorClient : WriteContentRepo {
|
class WriteContentRepoKtorClient(
|
||||||
override suspend fun registerContent(content: Content): RegisteredContent? {
|
private val client: HttpClient,
|
||||||
TODO("Not yet implemented")
|
private val baseUrl: String
|
||||||
|
) : WriteContentRepo {
|
||||||
|
override suspend fun registerContent(content: Content): RegisteredContent? = client.post<ByteArray> {
|
||||||
|
url("$baseUrl/$registerContentRoute")
|
||||||
|
body = standardKtorSerializer.dump(Content.serializer(), content)
|
||||||
|
}.let {
|
||||||
|
standardKtorSerializer.load(RegisteredContent.serializer().nullable, it)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun deleteContent(id: ContentId): Boolean {
|
override suspend fun deleteContent(id: ContentId): Boolean = client.post<ByteArray> {
|
||||||
TODO("Not yet implemented")
|
url("$baseUrl/$registerContentRoute")
|
||||||
|
body = standardKtorSerializer.dump(ContentId.serializer(), id)
|
||||||
|
}.let {
|
||||||
|
standardKtorSerializer.load(Boolean.serializer(), it)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user