improve business post creating case
This commit is contained in:
parent
ac28704fdc
commit
58d92849fc
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user