small update
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package dev.inmo.postssystem.core.publishing.repos
|
||||
|
||||
import dev.inmo.micro_utils.pagination.FirstPagePagination
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
import dev.inmo.postssystem.core.post.PostId
|
||||
import dev.inmo.postssystem.core.publishing.TriggerControlKey
|
||||
|
||||
@@ -23,3 +25,30 @@ interface WritePublishingKeysRepo {
|
||||
}
|
||||
|
||||
interface PublishingKeysRepo : ReadPublishingKeysRepo, WritePublishingKeysRepo
|
||||
|
||||
fun PublishingKeysRepo(
|
||||
keyValueRepo: KeyValueRepo<PostId, TriggerControlKey>
|
||||
) = object : PublishingKeysRepo {
|
||||
override suspend fun getPostIdByTriggerControlKey(
|
||||
key: TriggerControlKey
|
||||
): PostId? = keyValueRepo.keys(key, FirstPagePagination(1)).results.firstOrNull()
|
||||
|
||||
override suspend fun getTriggerControlKeyByPostId(
|
||||
postId: PostId
|
||||
): TriggerControlKey? = keyValueRepo.get(postId)
|
||||
|
||||
override suspend fun setPostTriggerControlKey(
|
||||
postId: PostId,
|
||||
key: TriggerControlKey
|
||||
): Boolean {
|
||||
keyValueRepo.set(postId, key)
|
||||
return true
|
||||
}
|
||||
|
||||
override suspend fun unsetPostTriggerControlKey(
|
||||
postId: PostId
|
||||
): Boolean {
|
||||
keyValueRepo.unset(postId)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,3 @@
|
||||
package com.insanusmokrassar.postssystem.publishing.ktor
|
||||
|
||||
const val setTriggerRoute = "set_trigger"
|
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
@@ -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
|
@@ -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
|
@@ -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
|
Reference in New Issue
Block a user