diff --git a/core/api/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/repo/WritePostsRepo.kt b/core/api/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/repo/WritePostsRepo.kt index bf24cb64..6139694f 100644 --- a/core/api/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/repo/WritePostsRepo.kt +++ b/core/api/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/repo/WritePostsRepo.kt @@ -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 diff --git a/core/exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepo.kt b/core/exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepo.kt index 383c7894..aa7fc25c 100644 --- a/core/exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepo.kt +++ b/core/exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepo.kt @@ -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 ) { diff --git a/publishing/api/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingTrigger.kt b/publishing/api/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingTrigger.kt index 8c9d3605..26733612 100644 --- a/publishing/api/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingTrigger.kt +++ b/publishing/api/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingTrigger.kt @@ -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 + } } } }