fixes and changes
This commit is contained in:
parent
7cfa612a9c
commit
981a354441
@ -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"
|
||||
}
|
||||
|
||||
|
@ -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
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
@ -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?
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.insanusmokrassar.postssystem.core.post
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.post.api.PostsAPI
|
||||
|
||||
class BusinessPublishablePostsAPI(
|
||||
/**
|
||||
* Will be used for storing of unpublished data
|
||||
*/
|
||||
private val repoPostsAPI: PostsAPI,
|
||||
/**
|
||||
* Will be used to send information ab
|
||||
*/
|
||||
private val publishedPostsAPI: PostsAPI
|
||||
) : PostsAPI by repoPostsAPI {
|
||||
override suspend fun deletePost(id: PostId): Boolean {
|
||||
return getPostById(id) ?.let { post ->
|
||||
publishedPostsAPI.createPost(post)
|
||||
repoPostsAPI.deletePost(id)
|
||||
} ?: return false
|
||||
}
|
||||
}
|
@ -1,10 +1,3 @@
|
||||
package com.insanusmokrassar.postssystem.core.post.api
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.post.RegisteredPost
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface PostsAPI : ReadPostsAPI, WritePostsAPI {
|
||||
val postCreatedFlow: Flow<RegisteredPost>
|
||||
val postDeletedFlow: Flow<RegisteredPost>
|
||||
val postUpdatedFlow: Flow<RegisteredPost>
|
||||
}
|
||||
interface PostsAPI : ReadPostsAPI, WritePostsAPI
|
||||
|
@ -1,8 +1,13 @@
|
||||
package com.insanusmokrassar.postssystem.core.post.api
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.post.*
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface WritePostsAPI {
|
||||
val postCreatedFlow: Flow<RegisteredPost>
|
||||
val postDeletedFlow: Flow<RegisteredPost>
|
||||
val postUpdatedFlow: Flow<RegisteredPost>
|
||||
|
||||
/**
|
||||
* 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]
|
||||
|
@ -0,0 +1,23 @@
|
||||
package com.insanusmokrassar.postssystem.core.utils
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.supervisorScope
|
||||
|
||||
|
||||
typealias ExceptionHandler<T> = suspend (Throwable) -> T
|
||||
/**
|
||||
* It will run [block] inside of [supervisorScope] to avoid problems with catching of exceptions
|
||||
*
|
||||
* @param [onException] Will be called when happen exception inside of [block]. By default will throw exception - this
|
||||
* exception will be available for catching
|
||||
*/
|
||||
suspend inline fun <T> safely(
|
||||
noinline onException: ExceptionHandler<T> = { throw it },
|
||||
noinline block: suspend CoroutineScope.() -> T
|
||||
): T {
|
||||
return try {
|
||||
supervisorScope(block)
|
||||
} catch (e: Throwable) {
|
||||
onException(e)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user