fixes and changes
This commit is contained in:
parent
7cfa612a9c
commit
981a354441
@ -13,14 +13,13 @@ buildscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version"
|
||||||
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
|
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
project.version = "$core_version"
|
project.version = "$core_version"
|
||||||
project.group = "com.insanusmokrassar"
|
project.group = "com.insanusmokrassar"
|
||||||
|
|
||||||
apply plugin: "java-library"
|
|
||||||
apply plugin: "kotlin"
|
|
||||||
apply from: "./publish.gradle"
|
apply from: "./publish.gradle"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
@ -30,15 +29,48 @@ repositories {
|
|||||||
maven { url "https://kotlin.bintray.com/kotlinx" }
|
maven { url "https://kotlin.bintray.com/kotlinx" }
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
kotlin {
|
||||||
api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
jvm()
|
||||||
|
js()
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
implementation kotlin('stdlib')
|
||||||
|
|
||||||
if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") {
|
if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") {
|
||||||
api "com.insanusmokrassar:postssystem.core:$core_version"
|
api "com.insanusmokrassar:postssystem.core:$core_version"
|
||||||
} else {
|
} else {
|
||||||
implementation project(":postssystem.core")
|
implementation project(":postssystem.core")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
testImplementation "org.jetbrains.kotlin:kotlin-test"
|
}
|
||||||
testImplementation "org.jetbrains.kotlin:kotlin-test-junit"
|
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')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,16 +5,17 @@ import com.insanusmokrassar.postssystem.core.publishing.repos.PublishingKeysRepo
|
|||||||
import kotlinx.coroutines.channels.BroadcastChannel
|
import kotlinx.coroutines.channels.BroadcastChannel
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.asFlow
|
||||||
|
|
||||||
typealias TriggerControlKey = String
|
typealias TriggerControlKey = String
|
||||||
|
|
||||||
interface ReadPublishingRegistrator {
|
interface ReadPublishingRegistrar {
|
||||||
suspend fun getPostIdByTriggerControlKey(
|
suspend fun getPostIdByTriggerControlKey(
|
||||||
key: TriggerControlKey
|
key: TriggerControlKey
|
||||||
): PostId?
|
): PostId?
|
||||||
}
|
}
|
||||||
|
|
||||||
interface WritePublishingRegistrator {
|
interface WritePublishingRegistrar {
|
||||||
val unregisteredKeysFlow: Flow<TriggerControlKey>
|
val unregisteredKeysFlow: Flow<TriggerControlKey>
|
||||||
|
|
||||||
suspend fun registerTriggerForPost(
|
suspend fun registerTriggerForPost(
|
||||||
@ -23,14 +24,13 @@ interface WritePublishingRegistrator {
|
|||||||
): Boolean
|
): Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PublishingRegistrator : ReadPublishingRegistrator, WritePublishingRegistrator
|
interface PublishingRegistrar : ReadPublishingRegistrar, WritePublishingRegistrar
|
||||||
|
|
||||||
class BusinessPublishingRegistrator(
|
class BusinessPublishingRegistrar(
|
||||||
private val repo: PublishingKeysRepo
|
private val repo: PublishingKeysRepo
|
||||||
) : PublishingRegistrator {
|
) : PublishingRegistrar {
|
||||||
private val unregisteredKeysChannel: BroadcastChannel<TriggerControlKey> = BroadcastChannel(Channel.BUFFERED)
|
private val unregisteredKeysChannel: BroadcastChannel<TriggerControlKey> = BroadcastChannel(Channel.BUFFERED)
|
||||||
override val unregisteredKeysFlow: Flow<TriggerControlKey>
|
override val unregisteredKeysFlow: Flow<TriggerControlKey> = unregisteredKeysChannel.asFlow()
|
||||||
get() = TODO("Not yet implemented")
|
|
||||||
|
|
||||||
override suspend fun getPostIdByTriggerControlKey(
|
override suspend fun getPostIdByTriggerControlKey(
|
||||||
key: TriggerControlKey
|
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.post.PostId
|
||||||
import com.insanusmokrassar.postssystem.core.publishing.TriggerControlKey
|
import com.insanusmokrassar.postssystem.core.publishing.TriggerControlKey
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
interface ReadPublishingKeysRepo {
|
interface ReadPublishingKeysRepo {
|
||||||
suspend fun getPostIdByTriggerControlKey(
|
suspend fun getPostIdByTriggerControlKey(
|
||||||
@ -14,8 +13,6 @@ interface ReadPublishingKeysRepo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface WritePublishingKeysRepo {
|
interface WritePublishingKeysRepo {
|
||||||
val postTriggerControlKeyUpdated: Flow<Pair<PostId, TriggerControlKey>>
|
|
||||||
val postTriggerControlKeyUnset: Flow<PostId>
|
|
||||||
suspend fun setPostTriggerControlKey(
|
suspend fun setPostTriggerControlKey(
|
||||||
postId: PostId,
|
postId: PostId,
|
||||||
key: TriggerControlKey
|
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
|
package com.insanusmokrassar.postssystem.core.post.api
|
||||||
|
|
||||||
import com.insanusmokrassar.postssystem.core.post.RegisteredPost
|
interface PostsAPI : ReadPostsAPI, WritePostsAPI
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
interface PostsAPI : ReadPostsAPI, WritePostsAPI {
|
|
||||||
val postCreatedFlow: Flow<RegisteredPost>
|
|
||||||
val postDeletedFlow: Flow<RegisteredPost>
|
|
||||||
val postUpdatedFlow: Flow<RegisteredPost>
|
|
||||||
}
|
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
package com.insanusmokrassar.postssystem.core.post.api
|
package com.insanusmokrassar.postssystem.core.post.api
|
||||||
|
|
||||||
import com.insanusmokrassar.postssystem.core.post.*
|
import com.insanusmokrassar.postssystem.core.post.*
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
interface WritePostsAPI {
|
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]
|
* 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]
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user