fixes and changes

This commit is contained in:
2020-07-27 12:35:59 +06:00
parent 7cfa612a9c
commit 981a354441
9 changed files with 139 additions and 43 deletions

View File

@@ -13,14 +13,13 @@ buildscript {
}
plugins {
id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version"
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
}
project.version = "$core_version"
project.group = "com.insanusmokrassar"
apply plugin: "java-library"
apply plugin: "kotlin"
apply from: "./publish.gradle"
repositories {
@@ -30,15 +29,48 @@ repositories {
maven { url "https://kotlin.bintray.com/kotlinx" }
}
dependencies {
api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
kotlin {
jvm()
js()
if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") {
api "com.insanusmokrassar:postssystem.core:$core_version"
} else {
implementation project(":postssystem.core")
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib')
if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") {
api "com.insanusmokrassar:postssystem.core:$core_version"
} else {
implementation project(":postssystem.core")
}
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
jvmMain {
dependencies {
implementation kotlin('stdlib-jdk8')
}
}
jvmTest {
dependencies {
implementation kotlin('test-junit')
}
}
jsMain {
dependencies {
implementation kotlin('stdlib-js')
}
}
jsTest {
dependencies {
implementation kotlin('test-junit-js')
}
}
}
testImplementation "org.jetbrains.kotlin:kotlin-test"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit"
}

View File

@@ -5,16 +5,17 @@ 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 ReadPublishingRegistrator {
interface ReadPublishingRegistrar {
suspend fun getPostIdByTriggerControlKey(
key: TriggerControlKey
): PostId?
}
interface WritePublishingRegistrator {
interface WritePublishingRegistrar {
val unregisteredKeysFlow: Flow<TriggerControlKey>
suspend fun registerTriggerForPost(
@@ -23,14 +24,13 @@ interface WritePublishingRegistrator {
): Boolean
}
interface PublishingRegistrator : ReadPublishingRegistrator, WritePublishingRegistrator
interface PublishingRegistrar : ReadPublishingRegistrar, WritePublishingRegistrar
class BusinessPublishingRegistrator(
class BusinessPublishingRegistrar(
private val repo: PublishingKeysRepo
) : PublishingRegistrator {
) : PublishingRegistrar {
private val unregisteredKeysChannel: BroadcastChannel<TriggerControlKey> = BroadcastChannel(Channel.BUFFERED)
override val unregisteredKeysFlow: Flow<TriggerControlKey>
get() = TODO("Not yet implemented")
override val unregisteredKeysFlow: Flow<TriggerControlKey> = unregisteredKeysChannel.asFlow()
override suspend fun getPostIdByTriggerControlKey(
key: TriggerControlKey

View File

@@ -0,0 +1,39 @@
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.api.PostsAPI
import com.insanusmokrassar.postssystem.core.publishing.repos.PublishingKeysRepo
import kotlinx.coroutines.channels.BroadcastChannel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.*
interface PublishingTrigger {
val postingTriggeredFlow: Flow<RegisteredPost>
suspend fun triggerPosting(
triggerControlKey: TriggerControlKey
): PostId?
}
class BusinessPublishingTrigger(
private val postsAPI: PostsAPI,
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 postsAPI.getPostById(postId) ?.let { post ->
if (postsAPI.deletePost(postId)) {
postingTriggeredChannel.send(post)
postId
} else {
null
}
}
}
}

View File

@@ -2,7 +2,6 @@ package com.insanusmokrassar.postssystem.core.publishing.repos
import com.insanusmokrassar.postssystem.core.post.PostId
import com.insanusmokrassar.postssystem.core.publishing.TriggerControlKey
import kotlinx.coroutines.flow.Flow
interface ReadPublishingKeysRepo {
suspend fun getPostIdByTriggerControlKey(
@@ -14,8 +13,6 @@ interface ReadPublishingKeysRepo {
}
interface WritePublishingKeysRepo {
val postTriggerControlKeyUpdated: Flow<Pair<PostId, TriggerControlKey>>
val postTriggerControlKeyUnset: Flow<PostId>
suspend fun setPostTriggerControlKey(
postId: PostId,
key: TriggerControlKey

View File

@@ -1,14 +0,0 @@
package com.insanusmokrassar.postssystem.core.publishing
import com.insanusmokrassar.postssystem.core.post.PostId
import kotlinx.coroutines.flow.Flow
interface PublishingTrigger {
val postingTriggeredFlow: Flow<PostId>
suspend fun triggerPosting(
triggerControlKey: TriggerControlKey
): PostId?
}