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]
|
* 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
|
||||||
|
@ -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
|
||||||
) {
|
) {
|
||||||
|
@ -31,13 +31,15 @@ class BusinessPublishingTrigger(
|
|||||||
publishingKeysRepo.unsetPostTriggerControlKey(postId)
|
publishingKeysRepo.unsetPostTriggerControlKey(postId)
|
||||||
|
|
||||||
return postsRepo.getPostById(postId) ?.let { post ->
|
return postsRepo.getPostById(postId) ?.let { post ->
|
||||||
|
publishedPostsRepo.createPost(post) ?.let { publishedPost ->
|
||||||
if (postsRepo.deletePost(postId)) {
|
if (postsRepo.deletePost(postId)) {
|
||||||
publishedPostsRepo.createPost(post)
|
|
||||||
postingTriggeredChannel.send(post)
|
postingTriggeredChannel.send(post)
|
||||||
postId
|
postId
|
||||||
} else {
|
} else {
|
||||||
|
publishedPostsRepo.deletePost(publishedPost.id)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user