core/business_cases/post_creating/common/src/commonMain/kotlin/dev/inmo/postssystem/business_cases/post_creating/server/BusinessPostCreatingCase.kt

27 lines
1004 B
Kotlin

package dev.inmo.postssystem.business_cases.post_creating.server
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 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
}
}