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