update BusinessContentRepo to reuse content id from link to content
This commit is contained in:
parent
85faf0b850
commit
cc5a498436
File diff suppressed because one or more lines are too long
@ -14,12 +14,12 @@ typealias ContentId = String
|
|||||||
interface Content
|
interface Content
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It is content, which was added by some external source to use inside of some plugins. For example, you can use
|
* That is a content which in fact just a link to another content. It would be useful in case when user wish to reuse
|
||||||
* location as content inside your target system and add this type of content specially for this system only
|
* some content
|
||||||
*/
|
*/
|
||||||
@Serializable
|
@Serializable
|
||||||
data class SpecialContent(
|
data class OtherContentLinkContent(
|
||||||
val internalId: ContentId
|
val otherId: ContentId
|
||||||
) : Content
|
) : Content
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,6 +59,14 @@ class BusinessWriteContentRepo(
|
|||||||
|
|
||||||
override suspend fun create(values: List<Content>): List<RegisteredContent> {
|
override suspend fun create(values: List<Content>): List<RegisteredContent> {
|
||||||
return values.mapNotNull { content ->
|
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 contentId = generateContentId()
|
||||||
val adapter = adapters.firstOrNull { it.storeContent(contentId, content) } ?: return@mapNotNull null
|
val adapter = adapters.firstOrNull { it.storeContent(contentId, content) } ?: return@mapNotNull null
|
||||||
if (!helperRepo.saveType(contentId, adapter.type)) {
|
if (!helperRepo.saveType(contentId, adapter.type)) {
|
||||||
|
@ -5,13 +5,10 @@ import dev.inmo.postssystem.core.post.RegisteredPost
|
|||||||
import dev.inmo.postssystem.core.post.repo.PostsRepo
|
import dev.inmo.postssystem.core.post.repo.PostsRepo
|
||||||
import dev.inmo.postssystem.core.publishing.repos.PublishedPostsWriteRepo
|
import dev.inmo.postssystem.core.publishing.repos.PublishedPostsWriteRepo
|
||||||
import dev.inmo.postssystem.core.publishing.repos.PublishingKeysRepo
|
import dev.inmo.postssystem.core.publishing.repos.PublishingKeysRepo
|
||||||
import kotlinx.coroutines.channels.BroadcastChannel
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.channels.Channel
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
import kotlinx.coroutines.flow.asFlow
|
|
||||||
|
|
||||||
interface PublishingTrigger {
|
interface PublishingTrigger {
|
||||||
val postingTriggeredFlow: Flow<RegisteredPost>
|
val postingTriggeredFlow: SharedFlow<RegisteredPost>
|
||||||
|
|
||||||
suspend fun triggerPosting(
|
suspend fun triggerPosting(
|
||||||
triggerControlKey: TriggerControlKey
|
triggerControlKey: TriggerControlKey
|
||||||
@ -23,8 +20,8 @@ class BusinessPublishingTrigger(
|
|||||||
private val publishedPostsRepo: PublishedPostsWriteRepo,
|
private val publishedPostsRepo: PublishedPostsWriteRepo,
|
||||||
private val publishingKeysRepo: PublishingKeysRepo
|
private val publishingKeysRepo: PublishingKeysRepo
|
||||||
) : PublishingTrigger {
|
) : PublishingTrigger {
|
||||||
private val postingTriggeredChannel: BroadcastChannel<RegisteredPost> = BroadcastChannel(Channel.BUFFERED)
|
private val _postingTriggeredFlow: MutableSharedFlow<RegisteredPost> = MutableSharedFlow()
|
||||||
override val postingTriggeredFlow: Flow<RegisteredPost> = postingTriggeredChannel.asFlow()
|
override val postingTriggeredFlow: SharedFlow<RegisteredPost> = _postingTriggeredFlow.asSharedFlow()
|
||||||
|
|
||||||
override suspend fun triggerPosting(triggerControlKey: TriggerControlKey): PostId? {
|
override suspend fun triggerPosting(triggerControlKey: TriggerControlKey): PostId? {
|
||||||
val postId = publishingKeysRepo.getPostIdByTriggerControlKey(triggerControlKey) ?: return null
|
val postId = publishingKeysRepo.getPostIdByTriggerControlKey(triggerControlKey) ?: return null
|
||||||
@ -33,7 +30,7 @@ class BusinessPublishingTrigger(
|
|||||||
return postsRepo.getPostById(postId) ?.let { post ->
|
return postsRepo.getPostById(postId) ?.let { post ->
|
||||||
publishedPostsRepo.registerPublishedPost(post) ?.let { publishedPost ->
|
publishedPostsRepo.registerPublishedPost(post) ?.let { publishedPost ->
|
||||||
if (postsRepo.deletePost(postId)) {
|
if (postsRepo.deletePost(postId)) {
|
||||||
postingTriggeredChannel.send(post)
|
_postingTriggeredFlow.emit(post)
|
||||||
postId
|
postId
|
||||||
} else {
|
} else {
|
||||||
publishedPostsRepo.unpublishPost(publishedPost.id)
|
publishedPostsRepo.unpublishPost(publishedPost.id)
|
||||||
|
Loading…
Reference in New Issue
Block a user