complete client part for content in core

This commit is contained in:
InsanusMokrassar 2020-08-10 19:13:58 +06:00
parent 14a40bfef0
commit 9421edcb85

View File

@ -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)
} }
} }