From eacd0fb9c439b75a9f49b7ec5ef15a655407d11f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 28 Nov 2020 23:07:42 +0600 Subject: [PATCH] remove unnecessary triggers management service --- .../publishing/TriggersManagementService.kt | 40 ------------------ .../ktor/client/TriggerSetterClient.kt | 26 ------------ .../ktor/server/TriggerSetterConfigurator.kt | 42 ------------------- 3 files changed, 108 deletions(-) delete mode 100644 publishing/api/src/commonMain/kotlin/dev/inmo/postssystem/core/publishing/TriggersManagementService.kt delete mode 100644 publishing/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/publishing/ktor/client/TriggerSetterClient.kt delete mode 100644 publishing/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/publishing/ktor/server/TriggerSetterConfigurator.kt diff --git a/publishing/api/src/commonMain/kotlin/dev/inmo/postssystem/core/publishing/TriggersManagementService.kt b/publishing/api/src/commonMain/kotlin/dev/inmo/postssystem/core/publishing/TriggersManagementService.kt deleted file mode 100644 index 4f625dd0..00000000 --- a/publishing/api/src/commonMain/kotlin/dev/inmo/postssystem/core/publishing/TriggersManagementService.kt +++ /dev/null @@ -1,40 +0,0 @@ -package dev.inmo.postssystem.core.publishing - -import dev.inmo.postssystem.core.post.PostId - -class TriggerSetterServiceUnknownTriggerIdException( - triggerId: TriggerId -) : IllegalArgumentException( - "Unknown trigger id $triggerId" -) - -interface ReadTriggersManagementService { - @Throws(TriggerSetterServiceUnknownTriggerIdException::class) - suspend fun getTrigger(postId: PostId): TriggerId? -} - -interface WriteTriggersManagementService { - @Throws(TriggerSetterServiceUnknownTriggerIdException::class) - suspend fun setTrigger(postId: PostId, triggerId: TriggerId): Boolean -} - -interface TriggersManagementService : ReadTriggersManagementService, WriteTriggersManagementService - -class BusinessTriggersManagementService( - private val postKeyGenerator: PostKeyGenerator, - private val publishingKeyReceiverGetter: PublishingKeyReceiverGetter, - private val keysRegistrar: PublishingKeysRegistrar -) : TriggersManagementService { - override suspend fun getTrigger(postId: PostId): TriggerId? { - TODO("Not yet implemented") - } - - override suspend fun setTrigger(postId: PostId, triggerId: TriggerId): Boolean { - val publishingKeyReceiver = publishingKeyReceiverGetter(triggerId) ?: throw TriggerSetterServiceUnknownTriggerIdException(triggerId) - val triggerControlKey = postKeyGenerator(postId, triggerId) - - keysRegistrar.registerTriggerForPost(triggerControlKey, postId) - publishingKeyReceiver.acceptKey(postId, triggerControlKey) - return true - } -} diff --git a/publishing/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/publishing/ktor/client/TriggerSetterClient.kt b/publishing/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/publishing/ktor/client/TriggerSetterClient.kt deleted file mode 100644 index d874e7c4..00000000 --- a/publishing/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/publishing/ktor/client/TriggerSetterClient.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.insanusmokrassar.postssystem.publishing.ktor.client - -import com.insanusmokrassar.postssystem.publishing.ktor.* -import dev.inmo.micro_utils.ktor.client.BodyPair -import dev.inmo.micro_utils.ktor.client.UnifiedRequester -import dev.inmo.micro_utils.ktor.common.buildStandardUrl -import dev.inmo.postssystem.core.post.PostId -import dev.inmo.postssystem.core.publishing.TriggerId -import dev.inmo.postssystem.core.publishing.TriggersManagementService -import kotlinx.serialization.builtins.serializer - -class TriggersManagementKtorClient( - private val baseUrl: String, - private val subRoute: String? = triggersRootRoute, - private val unifiedRequester: UnifiedRequester -) : TriggersManagementService { - private val apiRootUrl = subRoute ?.let { "$baseUrl/$it" } ?: baseUrl - override suspend fun setTrigger(postId: PostId, triggerId: TriggerId): Boolean = unifiedRequester.unipost( - buildStandardUrl( - apiRootUrl, - "$setTriggerSubRoute/" - ), - BodyPair(TriggerSettingData.serializer(), TriggerSettingData(postId, triggerId)), - Boolean.serializer() - ) -} diff --git a/publishing/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/publishing/ktor/server/TriggerSetterConfigurator.kt b/publishing/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/publishing/ktor/server/TriggerSetterConfigurator.kt deleted file mode 100644 index 36e80b49..00000000 --- a/publishing/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/publishing/ktor/server/TriggerSetterConfigurator.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.insanusmokrassar.postssystem.publishing.ktor.server - -import com.insanusmokrassar.postssystem.publishing.ktor.* -import dev.inmo.micro_utils.ktor.server.UnifiedRouter -import dev.inmo.postssystem.core.publishing.* -import io.ktor.application.call -import io.ktor.http.HttpStatusCode -import io.ktor.response.respond -import io.ktor.routing.* -import kotlinx.serialization.builtins.serializer - -private inline fun Route.configureTriggersManagement(triggerSetterService: TriggerSetterService, unifiedRouter: UnifiedRouter) { - post("$setTriggerSubRoute/{post_id}/{trigger_id}") { - unifiedRouter.apply { - val (postId, triggerId) = uniload(TriggerSettingData.serializer()) - - try { - unianswer( - Boolean.serializer(), - triggerSetterService.setTrigger(postId, triggerId) - ) - } catch (e: TriggerSetterServiceUnknownTriggerIdException) { - call.respond( - HttpStatusCode.BadRequest, - "Unknown trigger id $triggerId" - ) - } - } - } -} - -fun Route.configureTriggersManagement( - subRoute: String? = triggersRootRoute, - triggerSetterService: TriggerSetterService, - unifiedRouter: UnifiedRouter -) { - subRoute ?.also { - route(it) { - configureTriggersManagement(triggerSetterService, unifiedRouter) - } - } ?: configureTriggersManagement(triggerSetterService, unifiedRouter) -}