temporal push for keeping history
This commit is contained in:
core
api
build.gradlemaven.publish.gradlepublish.gradlepublish_config.json
src
commonMain
kotlin
com
insanusmokrassar
commonTest
kotlin
com
insanusmokrassar
postssystem
core
exposed
build.gradlegradle.propertiesmaven.publish.gradlepublish.gradlepublish_config.json
src
main
kotlin
com
insanusmokrassar
test
kotlin
com
insanusmokrassar
postssystem
ktor
client
build.gradlegradle.propertiespublish.gradlepublish_config.jsonsettings.gradle
src
commonMain
kotlin
com
insanusmokrassar
postssystem
core
ktor
client
content
common
build.gradlegradle.propertiespublish.gradlepublish_config.json
src
commonMain
kotlin
com
insanusmokrassar
postssystem
core
ktor
exposed/commons
build.gradlegradle.propertiesmaven.publish.gradlepublish.gradlepublish_config.kpsb
gradle.propertiessrc
main
kotlin
com
insanusmokrassar
postssystem
exposed
commons
gradle/wrapper
ktor
client
common
markups
build.gradle
html
build.gradlegradle.propertiesmaven.publish.gradlepublish.gradlepublish_config.kpsb
maven.publish.gradlepublish.gradlepublish_config.kpsbsrc
jsMain
kotlin
com
insanusmokrassar
postssystem
markups
jvmMain
kotlin
com
insanusmokrassar
postssystem
markups
src
commonMain
kotlin
com
insanusmokrassar
postssystem
postssystem.markups.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/markups/core
postssystem.markups.html/src
jsMain
kotlin
com
insanusmokrassar
postssystem
markups
jvmMain
kotlin
com
insanusmokrassar
postssystem
markups
publishing
api
build.gradlemaven.publish.gradlepublish.gradlepublish_config.kpsb
src
commonMain
kotlin
com
insanusmokrassar
postssystem
core
exposed
build.gradlegradle.propertiesmaven.publish.gradlepublish.gradlepublish_config.kpsb
src
main
kotlin
com
insanusmokrassar
postssystem
core
publishing
exposed
utils/repos
build.gradle
exposed
build.gradlegradle.propertiesmaven.publish.gradlepublish.gradlepublish_config.kpsb
maven.publish.gradlepublish.gradlepublish_config.kpsbsrc
main
kotlin
com
insanusmokrassar
postssystem
utils
repos
exposed
src
commonMain
kotlin
com
insanusmokrassar
52
publishing/api/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingRegistrar.kt
Normal file
52
publishing/api/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingRegistrar.kt
Normal file
@ -0,0 +1,52 @@
|
||||
package com.insanusmokrassar.postssystem.core.publishing
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.post.PostId
|
||||
import com.insanusmokrassar.postssystem.core.publishing.repos.PublishingKeysRepo
|
||||
import kotlinx.coroutines.channels.BroadcastChannel
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
|
||||
typealias TriggerControlKey = String
|
||||
|
||||
interface ReadPublishingRegistrar {
|
||||
suspend fun getPostIdByTriggerControlKey(
|
||||
key: TriggerControlKey
|
||||
): PostId?
|
||||
}
|
||||
|
||||
interface WritePublishingRegistrar {
|
||||
val unregisteredKeysFlow: Flow<TriggerControlKey>
|
||||
|
||||
suspend fun registerTriggerForPost(
|
||||
key: TriggerControlKey,
|
||||
postId: PostId
|
||||
): Boolean
|
||||
}
|
||||
|
||||
interface PublishingRegistrar : ReadPublishingRegistrar, WritePublishingRegistrar
|
||||
|
||||
class BusinessPublishingRegistrar(
|
||||
private val repo: PublishingKeysRepo
|
||||
) : PublishingRegistrar {
|
||||
private val unregisteredKeysChannel: BroadcastChannel<TriggerControlKey> = BroadcastChannel(Channel.BUFFERED)
|
||||
override val unregisteredKeysFlow: Flow<TriggerControlKey> = unregisteredKeysChannel.asFlow()
|
||||
|
||||
override suspend fun getPostIdByTriggerControlKey(
|
||||
key: TriggerControlKey
|
||||
): PostId? = repo.getPostIdByTriggerControlKey(key)
|
||||
|
||||
override suspend fun registerTriggerForPost(
|
||||
key: TriggerControlKey,
|
||||
postId: PostId
|
||||
): Boolean = repo.getTriggerControlKeyByPostId(
|
||||
postId
|
||||
).let { previousKey ->
|
||||
repo.setPostTriggerControlKey(postId, key).also { inserted ->
|
||||
if (inserted && previousKey != null) {
|
||||
unregisteredKeysChannel.send(previousKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
40
publishing/api/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingTrigger.kt
Normal file
40
publishing/api/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingTrigger.kt
Normal file
@ -0,0 +1,40 @@
|
||||
package com.insanusmokrassar.postssystem.core.publishing
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.post.PostId
|
||||
import com.insanusmokrassar.postssystem.core.post.RegisteredPost
|
||||
import com.insanusmokrassar.postssystem.core.post.repo.PostsRepo
|
||||
import com.insanusmokrassar.postssystem.core.publishing.repos.PublishingKeysRepo
|
||||
import kotlinx.coroutines.channels.BroadcastChannel
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
|
||||
interface PublishingTrigger {
|
||||
val postingTriggeredFlow: Flow<RegisteredPost>
|
||||
|
||||
suspend fun triggerPosting(
|
||||
triggerControlKey: TriggerControlKey
|
||||
): PostId?
|
||||
}
|
||||
|
||||
class BusinessPublishingTrigger(
|
||||
private val postsRepo: PostsRepo,
|
||||
private val publishingKeysRepo: PublishingKeysRepo
|
||||
) : PublishingTrigger {
|
||||
private val postingTriggeredChannel: BroadcastChannel<RegisteredPost> = BroadcastChannel(Channel.BUFFERED)
|
||||
override val postingTriggeredFlow: Flow<RegisteredPost> = postingTriggeredChannel.asFlow()
|
||||
|
||||
override suspend fun triggerPosting(triggerControlKey: TriggerControlKey): PostId? {
|
||||
val postId = publishingKeysRepo.getPostIdByTriggerControlKey(triggerControlKey) ?: return null
|
||||
publishingKeysRepo.unsetPostTriggerControlKey(postId)
|
||||
|
||||
return postsRepo.getPostById(postId) ?.let { post ->
|
||||
if (postsRepo.deletePost(postId)) {
|
||||
postingTriggeredChannel.send(post)
|
||||
postId
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
25
publishing/api/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/repos/PublishingKeysRepo.kt
Normal file
25
publishing/api/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/repos/PublishingKeysRepo.kt
Normal file
@ -0,0 +1,25 @@
|
||||
package com.insanusmokrassar.postssystem.core.publishing.repos
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.post.PostId
|
||||
import com.insanusmokrassar.postssystem.core.publishing.TriggerControlKey
|
||||
|
||||
interface ReadPublishingKeysRepo {
|
||||
suspend fun getPostIdByTriggerControlKey(
|
||||
key: TriggerControlKey
|
||||
): PostId?
|
||||
suspend fun getTriggerControlKeyByPostId(
|
||||
postId: PostId
|
||||
): TriggerControlKey?
|
||||
}
|
||||
|
||||
interface WritePublishingKeysRepo {
|
||||
suspend fun setPostTriggerControlKey(
|
||||
postId: PostId,
|
||||
key: TriggerControlKey
|
||||
): Boolean
|
||||
suspend fun unsetPostTriggerControlKey(
|
||||
postId: PostId
|
||||
): Boolean
|
||||
}
|
||||
|
||||
interface PublishingKeysRepo : ReadPublishingKeysRepo, WritePublishingKeysRepo
|
Reference in New Issue
Block a user