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.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 {
|
||||
override suspend fun registerContent(content: Content): RegisteredContent? {
|
||||
TODO("Not yet implemented")
|
||||
class WriteContentRepoKtorClient(
|
||||
private val client: HttpClient,
|
||||
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 {
|
||||
TODO("Not yet implemented")
|
||||
override suspend fun deleteContent(id: ContentId): Boolean = client.post<ByteArray> {
|
||||
url("$baseUrl/$registerContentRoute")
|
||||
body = standardKtorSerializer.dump(ContentId.serializer(), id)
|
||||
}.let {
|
||||
standardKtorSerializer.load(Boolean.serializer(), it)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user