remove unnecessary triggers management service
This commit is contained in:
parent
72c48794fc
commit
eacd0fb9c4
@ -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
|
||||
}
|
||||
}
|
@ -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()
|
||||
)
|
||||
}
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user