add PublishedPostsRepo
This commit is contained in:
parent
dbf8e3716c
commit
13ddb106ad
@ -4,6 +4,7 @@ import com.insanusmokrassar.postssystem.core.post.PostId
|
||||
import com.insanusmokrassar.postssystem.core.post.RegisteredPost
|
||||
import com.insanusmokrassar.postssystem.core.post.repo.PostsRepo
|
||||
import com.insanusmokrassar.postssystem.core.post.repo.WritePostsRepo
|
||||
import com.insanusmokrassar.postssystem.core.publishing.repos.PublishedPostsWriteRepo
|
||||
import com.insanusmokrassar.postssystem.core.publishing.repos.PublishingKeysRepo
|
||||
import kotlinx.coroutines.channels.BroadcastChannel
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
@ -20,7 +21,7 @@ interface PublishingTrigger {
|
||||
|
||||
class BusinessPublishingTrigger(
|
||||
private val postsRepo: PostsRepo,
|
||||
private val publishedPostsRepo: WritePostsRepo,
|
||||
private val publishedPostsRepo: PublishedPostsWriteRepo,
|
||||
private val publishingKeysRepo: PublishingKeysRepo
|
||||
) : PublishingTrigger {
|
||||
private val postingTriggeredChannel: BroadcastChannel<RegisteredPost> = BroadcastChannel(Channel.BUFFERED)
|
||||
@ -31,12 +32,12 @@ class BusinessPublishingTrigger(
|
||||
publishingKeysRepo.unsetPostTriggerControlKey(postId)
|
||||
|
||||
return postsRepo.getPostById(postId) ?.let { post ->
|
||||
publishedPostsRepo.createPost(post) ?.let { publishedPost ->
|
||||
publishedPostsRepo.registerPublishedPost(post) ?.let { publishedPost ->
|
||||
if (postsRepo.deletePost(postId)) {
|
||||
postingTriggeredChannel.send(post)
|
||||
postId
|
||||
} else {
|
||||
publishedPostsRepo.deletePost(publishedPost.id)
|
||||
publishedPostsRepo.unpublishPost(publishedPost.id)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.insanusmokrassar.postssystem.core.publishing.repos
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.post.PostId
|
||||
import com.insanusmokrassar.postssystem.core.post.RegisteredPost
|
||||
import com.insanusmokrassar.postssystem.core.post.repo.PostsRepo
|
||||
import com.insanusmokrassar.postssystem.core.post.repo.ReadPostsRepo
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface PublishedPostsReadRepo : ReadPostsRepo
|
||||
interface PublishedPostsWriteRepo {
|
||||
val postPublishedFlow: Flow<RegisteredPost>
|
||||
val postUnpublishedFlow: Flow<RegisteredPost>
|
||||
|
||||
suspend fun registerPublishedPost(registeredPost: RegisteredPost): RegisteredPost?
|
||||
suspend fun unpublishPost(postId: PostId): Boolean?
|
||||
}
|
||||
|
||||
interface PublishedPostsRepo : PublishedPostsReadRepo, PublishedPostsWriteRepo
|
||||
|
||||
class BusinessPublishedPostsRepo(
|
||||
private val realPostsRepoWithPublishedPosts: PostsRepo
|
||||
) : PublishedPostsRepo, ReadPostsRepo by realPostsRepoWithPublishedPosts {
|
||||
override val postPublishedFlow: Flow<RegisteredPost>
|
||||
get() = realPostsRepoWithPublishedPosts.postCreatedFlow
|
||||
override val postUnpublishedFlow: Flow<RegisteredPost>
|
||||
get() = realPostsRepoWithPublishedPosts.postDeletedFlow
|
||||
|
||||
override suspend fun registerPublishedPost(
|
||||
registeredPost: RegisteredPost
|
||||
): RegisteredPost? = realPostsRepoWithPublishedPosts.createPost(registeredPost)
|
||||
|
||||
override suspend fun unpublishPost(
|
||||
postId: PostId
|
||||
): Boolean? = realPostsRepoWithPublishedPosts.deletePost(postId)
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user