From 9421edcb858839539dd7e9b3c346412557b1a397 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 10 Aug 2020 19:13:58 +0600 Subject: [PATCH] complete client part for content in core --- .../content/WriteContentRepoKtorClient.kt | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/core/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/ktor/client/content/WriteContentRepoKtorClient.kt b/core/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/ktor/client/content/WriteContentRepoKtorClient.kt index 4d667694..1c10b109 100644 --- a/core/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/ktor/client/content/WriteContentRepoKtorClient.kt +++ b/core/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/ktor/client/content/WriteContentRepoKtorClient.kt @@ -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 { + 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 { + url("$baseUrl/$registerContentRoute") + body = standardKtorSerializer.dump(ContentId.serializer(), id) + }.let { + standardKtorSerializer.load(Boolean.serializer(), it) } - } \ No newline at end of file