make triggerId optinal in create post case

This commit is contained in:
InsanusMokrassar 2020-09-10 15:59:17 +06:00
parent 60725d9fa3
commit ac28704fdc
3 changed files with 10 additions and 10 deletions

View File

@ -8,14 +8,13 @@ import com.insanusmokrassar.postssystem.ktor.buildStandardUrl
import com.insanusmokrassar.postssystem.ktor.client.BodyPair import com.insanusmokrassar.postssystem.ktor.client.BodyPair
import com.insanusmokrassar.postssystem.ktor.client.unipost import com.insanusmokrassar.postssystem.ktor.client.unipost
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.request.post
class PostCreatingClientCase( class PostCreatingClientCase(
private val baseUrl: String, private val baseUrl: String,
private val client: HttpClient private val client: HttpClient
) : PostCreatingCase { ) : PostCreatingCase {
private val realBaseUrl = "$baseUrl/$postCreatingRootRoute" private val realBaseUrl = "$baseUrl/$postCreatingRootRoute"
override suspend fun createPost(postContent: List<Content>, triggerId: TriggerId): RegisteredPost? = client.unipost( override suspend fun createPost(postContent: List<Content>, triggerId: TriggerId?): RegisteredPost? = client.unipost(
buildStandardUrl(realBaseUrl, postCreatingCreatePostRoute), buildStandardUrl(realBaseUrl, postCreatingCreatePostRoute),
BodyPair(PostCreatingCreatePostModel.serializer(), PostCreatingCreatePostModel(postContent, triggerId)), BodyPair(PostCreatingCreatePostModel.serializer(), PostCreatingCreatePostModel(postContent, triggerId)),
RegisteredPost.serializer() RegisteredPost.serializer()

View File

@ -13,14 +13,16 @@ class BusinessPostCreatingCase(
private val publishingRegistrar: PublishingRegistrar, private val publishingRegistrar: PublishingRegistrar,
private val postKeyGenerator: PostKeyGenerator = { _, _ -> uuid4().toString() } private val postKeyGenerator: PostKeyGenerator = { _, _ -> uuid4().toString() }
) : 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 {
publishingRegistrar.registerTriggerForPost( publishingRegistrar.registerTriggerForPost(
postKeyGenerator(post.id, triggerId), postKeyGenerator(post.id, triggerId),
post.id post.id
) )
}
return post return post
} }

View File

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