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] * 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 createPost(post: Post): RegisteredPost?
suspend fun deletePost(id: PostId): Boolean suspend fun deletePost(id: PostId): Boolean

View File

@ -105,7 +105,7 @@ private class PostsRepoDatabaseTable(
} }
override suspend fun createPost(post: Post): RegisteredPost? { override suspend fun createPost(post: Post): RegisteredPost? {
val id = generatePostId() val id = (post as? RegisteredPost) ?.let { it.id } ?: generatePostId()
return transaction( return transaction(
db = database db = database
) { ) {

View File

@ -31,12 +31,14 @@ class BusinessPublishingTrigger(
publishingKeysRepo.unsetPostTriggerControlKey(postId) publishingKeysRepo.unsetPostTriggerControlKey(postId)
return postsRepo.getPostById(postId) ?.let { post -> return postsRepo.getPostById(postId) ?.let { post ->
if (postsRepo.deletePost(postId)) { publishedPostsRepo.createPost(post) ?.let { publishedPost ->
publishedPostsRepo.createPost(post) if (postsRepo.deletePost(postId)) {
postingTriggeredChannel.send(post) postingTriggeredChannel.send(post)
postId postId
} else { } else {
null publishedPostsRepo.deletePost(publishedPost.id)
null
}
} }
} }
} }