small update

This commit is contained in:
2020-11-28 12:53:50 +06:00
parent 4d0aae2b91
commit 4b6544131f
8 changed files with 77 additions and 43 deletions

View File

@@ -0,0 +1,3 @@
package com.insanusmokrassar.postssystem.publishing.ktor
const val setTriggerRoute = "set_trigger"

View File

@@ -0,0 +1,33 @@
package com.insanusmokrassar.postssystem.publishing.ktor.server
import dev.inmo.micro_utils.ktor.server.UnifiedRouter
import dev.inmo.postssystem.core.post.PostId
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.Route
import io.ktor.routing.post
import kotlinx.serialization.builtins.serializer
fun Route.configureTriggerSetter(
postKeyGenerator: PostKeyGenerator,
publishingKeyReceiverGetter: PublishingKeyReceiverGetter,
unifiedRouter: UnifiedRouter
) {
post("set_trigger/{post_id}/{trigger_id}") {
unifiedRouter.apply {
val postId = decodeUrlQueryValueOrSendError("post_id", PostId.serializer()) ?: return@post
val triggerId = decodeUrlQueryValueOrSendError("trigger_id", TriggerId.serializer()) ?: return@post
val publishingKeyReceiver = publishingKeyReceiverGetter(triggerId) ?: call.respond(
HttpStatusCode.BadRequest,
"Unknown trigger id $triggerId"
).let { return@post }
val triggerControlKey = postKeyGenerator(postId, triggerId)
publishingKeyReceiver.acceptKey(postId, triggerControlKey)
call.respond(HttpStatusCode.OK)
}
}
}

View File

@@ -1,4 +1,4 @@
package dev.inmo.postssystem.publishing.ktor.server
package com.insanusmokrassar.postssystem.publishing.ktor.server.publishing_keys_repo
import dev.inmo.postssystem.core.publishing.repos.PublishingKeysRepo
import dev.inmo.postssystem.publishing.ktor.publishingKeysRootRoute

View File

@@ -1,4 +1,4 @@
package dev.inmo.postssystem.publishing.ktor.server
package com.insanusmokrassar.postssystem.publishing.ktor.server.publishing_keys_repo
import dev.inmo.postssystem.core.post.PostId
import dev.inmo.postssystem.core.publishing.TriggerControlKey

View File

@@ -1,4 +1,4 @@
package dev.inmo.postssystem.publishing.ktor.server
package com.insanusmokrassar.postssystem.publishing.ktor.server.publishing_keys_repo
import dev.inmo.postssystem.core.post.PostId
import dev.inmo.postssystem.core.publishing.repos.WritePublishingKeysRepo