update BusinessContentRepo to reuse content id from link to content

This commit is contained in:
InsanusMokrassar 2020-12-01 12:43:12 +06:00
parent 85faf0b850
commit cc5a498436
4 changed files with 18 additions and 13 deletions

File diff suppressed because one or more lines are too long

View File

@ -14,12 +14,12 @@ typealias ContentId = String
interface Content
/**
* It is content, which was added by some external source to use inside of some plugins. For example, you can use
* location as content inside your target system and add this type of content specially for this system only
* That is a content which in fact just a link to another content. It would be useful in case when user wish to reuse
* some content
*/
@Serializable
data class SpecialContent(
val internalId: ContentId
data class OtherContentLinkContent(
val otherId: ContentId
) : Content

View File

@ -59,6 +59,14 @@ class BusinessWriteContentRepo(
override suspend fun create(values: List<Content>): List<RegisteredContent> {
return values.mapNotNull { content ->
if (content is OtherContentLinkContent) {
adapters.forEach {
return@mapNotNull RegisteredContent(
content.otherId,
it.getContent(content.otherId) ?: return@forEach
)
}
}
val contentId = generateContentId()
val adapter = adapters.firstOrNull { it.storeContent(contentId, content) } ?: return@mapNotNull null
if (!helperRepo.saveType(contentId, adapter.type)) {

View File

@ -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)