ExposedPostsRepo now using post also as RegisteredContent (if is)
This commit is contained in:
parent
277d978f9e
commit
dbf8e3716c
@ -10,7 +10,9 @@ interface WritePostsRepo {
|
||||
|
||||
/**
|
||||
* For creating of post you need to create all its [com.insanusmokrassar.postssystem.core.content.RegisteredContent]
|
||||
* and (or just) retrieve their [ContentIds] and put it into some [Post] implementation line [SimplePost]
|
||||
* and (or just) retrieve their [ContentIds] and put it into some [Post] implementation line [SimplePost].
|
||||
*
|
||||
* This method SHOULD use [PostId] of [RegisteredPost.id] in case if [RegisteredPost] passed
|
||||
*/
|
||||
suspend fun createPost(post: Post): RegisteredPost?
|
||||
suspend fun deletePost(id: PostId): Boolean
|
||||
|
@ -105,7 +105,7 @@ private class PostsRepoDatabaseTable(
|
||||
}
|
||||
|
||||
override suspend fun createPost(post: Post): RegisteredPost? {
|
||||
val id = generatePostId()
|
||||
val id = (post as? RegisteredPost) ?.let { it.id } ?: generatePostId()
|
||||
return transaction(
|
||||
db = database
|
||||
) {
|
||||
|
@ -31,12 +31,14 @@ class BusinessPublishingTrigger(
|
||||
publishingKeysRepo.unsetPostTriggerControlKey(postId)
|
||||
|
||||
return postsRepo.getPostById(postId) ?.let { post ->
|
||||
if (postsRepo.deletePost(postId)) {
|
||||
publishedPostsRepo.createPost(post)
|
||||
postingTriggeredChannel.send(post)
|
||||
postId
|
||||
} else {
|
||||
null
|
||||
publishedPostsRepo.createPost(post) ?.let { publishedPost ->
|
||||
if (postsRepo.deletePost(postId)) {
|
||||
postingTriggeredChannel.send(post)
|
||||
postId
|
||||
} else {
|
||||
publishedPostsRepo.deletePost(publishedPost.id)
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user