update creating case
This commit is contained in:
@@ -1,31 +1,26 @@
|
||||
package dev.inmo.postssystem.business_cases.post_creating.server
|
||||
|
||||
import com.benasher44.uuid.uuid4
|
||||
import dev.inmo.micro_utils.repos.set
|
||||
import dev.inmo.postssystem.core.content.Content
|
||||
import dev.inmo.postssystem.core.content.api.ContentRepo
|
||||
import dev.inmo.postssystem.core.post.*
|
||||
import dev.inmo.postssystem.core.post.repo.PostsRepo
|
||||
import dev.inmo.postssystem.core.publishing.*
|
||||
import dev.inmo.postssystem.core.publishing.repos.WriteTriggersToPostsRepo
|
||||
|
||||
//class BusinessPostCreatingCase(
|
||||
// private val postsRepo: PostsRepo,
|
||||
// private val contentRepo: ContentRepo,
|
||||
// private val publishingRegistrar: PublishingRegistrar,
|
||||
// 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 {
|
||||
// val key = postKeyGenerator(post.id, triggerId)
|
||||
//
|
||||
// if (publishingRegistrar.registerTriggerForPost(key, post.id)) {
|
||||
// publishingKeyReceiverGetter(it) ?.acceptKey(post.id, key)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return post
|
||||
// }
|
||||
//}
|
||||
class BusinessPostCreatingCase(
|
||||
private val postsRepo: PostsRepo,
|
||||
private val contentRepo: ContentRepo,
|
||||
private val postsTriggersToPostsRepo: WriteTriggersToPostsRepo
|
||||
) : PostCreatingCase {
|
||||
override suspend fun createPost(postContent: List<Content>, triggerId: TriggerId?): RegisteredPost? {
|
||||
val content = contentRepo.create(postContent)
|
||||
val post = postsRepo.createPost(SimplePost(content.map { it.id })) ?: return null
|
||||
|
||||
triggerId ?.let {
|
||||
postsTriggersToPostsRepo.set(post.id, triggerId)
|
||||
}
|
||||
|
||||
return post
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user