update BusinessContentRepo to reuse content id from link to content

This commit is contained in:
2020-12-01 12:43:12 +06:00
parent 85faf0b850
commit cc5a498436
4 changed files with 18 additions and 13 deletions
PostsSystem.drawio
core/api/src/commonMain/kotlin/dev/inmo/postssystem/core/content
publishing/api/src/commonMain/kotlin/dev/inmo/postssystem/core/publishing

@ -5,13 +5,10 @@ import dev.inmo.postssystem.core.post.RegisteredPost
import dev.inmo.postssystem.core.post.repo.PostsRepo
import dev.inmo.postssystem.core.publishing.repos.PublishedPostsWriteRepo
import dev.inmo.postssystem.core.publishing.repos.PublishingKeysRepo
import kotlinx.coroutines.channels.BroadcastChannel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.*
interface PublishingTrigger {
val postingTriggeredFlow: Flow<RegisteredPost>
val postingTriggeredFlow: SharedFlow<RegisteredPost>
suspend fun triggerPosting(
triggerControlKey: TriggerControlKey
@ -23,8 +20,8 @@ class BusinessPublishingTrigger(
private val publishedPostsRepo: PublishedPostsWriteRepo,
private val publishingKeysRepo: PublishingKeysRepo
) : PublishingTrigger {
private val postingTriggeredChannel: BroadcastChannel<RegisteredPost> = BroadcastChannel(Channel.BUFFERED)
override val postingTriggeredFlow: Flow<RegisteredPost> = postingTriggeredChannel.asFlow()
private val _postingTriggeredFlow: MutableSharedFlow<RegisteredPost> = MutableSharedFlow()
override val postingTriggeredFlow: SharedFlow<RegisteredPost> = _postingTriggeredFlow.asSharedFlow()
override suspend fun triggerPosting(triggerControlKey: TriggerControlKey): PostId? {
val postId = publishingKeysRepo.getPostIdByTriggerControlKey(triggerControlKey) ?: return null
@ -33,7 +30,7 @@ class BusinessPublishingTrigger(
return postsRepo.getPostById(postId) ?.let { post ->
publishedPostsRepo.registerPublishedPost(post) ?.let { publishedPost ->
if (postsRepo.deletePost(postId)) {
postingTriggeredChannel.send(post)
_postingTriggeredFlow.emit(post)
postId
} else {
publishedPostsRepo.unpublishPost(publishedPost.id)