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 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

View File

@ -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)
} }