ExposedPostsRepo now using post also as RegisteredContent (if is)

This commit is contained in:
InsanusMokrassar 2020-08-15 14:34:27 +06:00
parent 277d978f9e
commit dbf8e3716c
3 changed files with 12 additions and 8 deletions

View File

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

View File

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

View File

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