improve business post creating case

This commit is contained in:
InsanusMokrassar 2020-09-10 16:19:05 +06:00
parent ac28704fdc
commit 58d92849fc
2 changed files with 9 additions and 5 deletions

View File

@ -11,17 +11,19 @@ class BusinessPostCreatingCase(
private val postsRepo: PostsRepo,
private val contentRepo: ContentRepo,
private val publishingRegistrar: PublishingRegistrar,
private val postKeyGenerator: PostKeyGenerator = { _, _ -> uuid4().toString() }
private val postKeyGenerator: PostKeyGenerator = { _, _ -> uuid4().toString() },
private val publishingKeyReceiverGetter: PublishingKeyReceiverGetter
) : PostCreatingCase {
override suspend fun createPost(postContent: List<Content>, triggerId: TriggerId?): RegisteredPost? {
val content = postContent.mapNotNull { contentRepo.registerContent(it) }
val post = postsRepo.createPost(SimplePost(content.map { it.id })) ?: return null
triggerId ?.let {
publishingRegistrar.registerTriggerForPost(
postKeyGenerator(post.id, triggerId),
post.id
)
val key = postKeyGenerator(post.id, triggerId)
if (publishingRegistrar.registerTriggerForPost(key, post.id)) {
publishingKeyReceiverGetter(it) ?.acceptKey(post.id, key)
}
}
return post

View File

@ -2,6 +2,8 @@ package com.insanusmokrassar.postssystem.core.publishing
import com.insanusmokrassar.postssystem.core.post.PostId
typealias PublishingKeyReceiverGetter = suspend (TriggerId) -> PublishingKeyReceiver?
interface PublishingKeyReceiver : Trigger {
suspend fun acceptKey(postId: PostId, publishingKey: TriggerControlKey)
}