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 postsRepo: PostsRepo,
|
||||||
private val contentRepo: ContentRepo,
|
private val contentRepo: ContentRepo,
|
||||||
private val publishingRegistrar: PublishingRegistrar,
|
private val publishingRegistrar: PublishingRegistrar,
|
||||||
private val postKeyGenerator: PostKeyGenerator = { _, _ -> uuid4().toString() }
|
private val postKeyGenerator: PostKeyGenerator = { _, _ -> uuid4().toString() },
|
||||||
|
private val publishingKeyReceiverGetter: PublishingKeyReceiverGetter
|
||||||
) : PostCreatingCase {
|
) : PostCreatingCase {
|
||||||
override suspend fun createPost(postContent: List<Content>, triggerId: TriggerId?): RegisteredPost? {
|
override suspend fun createPost(postContent: List<Content>, triggerId: TriggerId?): RegisteredPost? {
|
||||||
val content = postContent.mapNotNull { contentRepo.registerContent(it) }
|
val content = postContent.mapNotNull { contentRepo.registerContent(it) }
|
||||||
val post = postsRepo.createPost(SimplePost(content.map { it.id })) ?: return null
|
val post = postsRepo.createPost(SimplePost(content.map { it.id })) ?: return null
|
||||||
|
|
||||||
triggerId ?.let {
|
triggerId ?.let {
|
||||||
publishingRegistrar.registerTriggerForPost(
|
val key = postKeyGenerator(post.id, triggerId)
|
||||||
postKeyGenerator(post.id, triggerId),
|
|
||||||
post.id
|
if (publishingRegistrar.registerTriggerForPost(key, post.id)) {
|
||||||
)
|
publishingKeyReceiverGetter(it) ?.acceptKey(post.id, key)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return post
|
return post
|
||||||
|
@ -2,6 +2,8 @@ package com.insanusmokrassar.postssystem.core.publishing
|
|||||||
|
|
||||||
import com.insanusmokrassar.postssystem.core.post.PostId
|
import com.insanusmokrassar.postssystem.core.post.PostId
|
||||||
|
|
||||||
|
typealias PublishingKeyReceiverGetter = suspend (TriggerId) -> PublishingKeyReceiver?
|
||||||
|
|
||||||
interface PublishingKeyReceiver : Trigger {
|
interface PublishingKeyReceiver : Trigger {
|
||||||
suspend fun acceptKey(postId: PostId, publishingKey: TriggerControlKey)
|
suspend fun acceptKey(postId: PostId, publishingKey: TriggerControlKey)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user