add post creating business case

This commit is contained in:
2020-09-10 00:04:25 +06:00
parent cf1aa3ae0f
commit 60725d9fa3
31 changed files with 332 additions and 37 deletions

View File

@@ -0,0 +1,27 @@
package com.insanusmokrassar.postssystem.business_cases.post_creating.server
import com.benasher44.uuid.uuid4
import com.insanusmokrassar.postssystem.core.content.Content
import com.insanusmokrassar.postssystem.core.content.api.ContentRepo
import com.insanusmokrassar.postssystem.core.post.*
import com.insanusmokrassar.postssystem.core.post.repo.PostsRepo
import com.insanusmokrassar.postssystem.core.publishing.*
class BusinessPostCreatingCase(
private val postsRepo: PostsRepo,
private val contentRepo: ContentRepo,
private val publishingRegistrar: PublishingRegistrar,
private val postKeyGenerator: PostKeyGenerator = { _, _ -> uuid4().toString() }
) : 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
publishingRegistrar.registerTriggerForPost(
postKeyGenerator(post.id, triggerId),
post.id
)
return post
}
}

View File

@@ -0,0 +1,20 @@
package com.insanusmokrassar.postssystem.business_cases.post_creating.server
import com.insanusmokrassar.postssystem.core.content.Content
import com.insanusmokrassar.postssystem.core.post.RegisteredPost
import com.insanusmokrassar.postssystem.core.publishing.PublishingKeyReceiver
import com.insanusmokrassar.postssystem.core.publishing.TriggerId
import kotlinx.serialization.Serializable
@Serializable
data class PostCreatingCreatePostModel(
val postContent: List<Content>,
val triggerId: TriggerId
)
interface PostCreatingCase {
suspend fun createPost(
postContent: List<Content>,
triggerId: TriggerId
): RegisteredPost?
}

View File

@@ -0,0 +1,5 @@
package com.insanusmokrassar.postssystem.business_cases.post_creating.server
const val postCreatingRootRoute = "postCreating"
const val postCreatingCreatePostRoute = "createPost"