add target and telegram target
This commit is contained in:
features
content
binary
common
common
src
commonMain
kotlin
dev
inmo
postssystem
features
content
common
server
src
jvmMain
kotlin
dev
inmo
postssystem
features
publication
server
settings.gradletargets/telegram/publication/server
@ -12,6 +12,7 @@ kotlin {
|
||||
dependencies {
|
||||
api project(":postssystem.features.common.common")
|
||||
api project(":postssystem.features.content.common")
|
||||
api "dev.inmo:micro_utils.mime_types:$microutils_version"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,14 @@
|
||||
package dev.inmo.postssystem.features.content.binary.common
|
||||
|
||||
import dev.inmo.micro_utils.common.ByteArrayAllocator
|
||||
import dev.inmo.micro_utils.common.FileName
|
||||
import dev.inmo.micro_utils.mime_types.MimeType
|
||||
import dev.inmo.postssystem.features.content.common.Content
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class BinaryContent(
|
||||
val bytes: ByteArray
|
||||
) : Content
|
||||
val filename: FileName,
|
||||
val mimeType: MimeType,
|
||||
val bytesAllocator: ByteArrayAllocator
|
||||
) : Content
|
||||
|
@ -2,7 +2,8 @@ package dev.inmo.postssystem.features.content.common
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
typealias ContentId = String
|
||||
@Serializable
|
||||
value class ContentId(val string: String)
|
||||
|
||||
/**
|
||||
* Content which is planned to be registered in database
|
||||
|
6
features/content/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/server/ServerContentStorage.kt
Normal file
6
features/content/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/server/ServerContentStorage.kt
Normal file
@ -0,0 +1,6 @@
|
||||
package dev.inmo.postssystem.features.content.server
|
||||
|
||||
import dev.inmo.micro_utils.repos.CRUDRepo
|
||||
import dev.inmo.postssystem.features.content.common.*
|
||||
|
||||
interface ServerContentStorage : ServerReadContentStorage, ServerWriteContentStorage, CRUDRepo<RegisteredContent, ContentId, Content>
|
7
features/content/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/server/ServerReadContentStorage.kt
Normal file
7
features/content/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/server/ServerReadContentStorage.kt
Normal file
@ -0,0 +1,7 @@
|
||||
package dev.inmo.postssystem.features.content.server
|
||||
|
||||
import dev.inmo.micro_utils.repos.ReadCRUDRepo
|
||||
import dev.inmo.postssystem.features.content.common.ContentId
|
||||
import dev.inmo.postssystem.features.content.common.RegisteredContent
|
||||
|
||||
interface ServerReadContentStorage : ReadCRUDRepo<RegisteredContent, ContentId>
|
6
features/content/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/server/ServerWriteContentStorage.kt
Normal file
6
features/content/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/content/server/ServerWriteContentStorage.kt
Normal file
@ -0,0 +1,6 @@
|
||||
package dev.inmo.postssystem.features.content.server
|
||||
|
||||
import dev.inmo.micro_utils.repos.WriteCRUDRepo
|
||||
import dev.inmo.postssystem.features.content.common.*
|
||||
|
||||
interface ServerWriteContentStorage : WriteCRUDRepo<RegisteredContent, ContentId, Content>
|
18
features/publication/client/build.gradle
Normal file
18
features/publication/client/build.gradle
Normal file
@ -0,0 +1,18 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api project(":postssystem.features.publication.common")
|
||||
api project(":postssystem.features.common.client")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1
features/publication/client/src/main/AndroidManifest.xml
Normal file
1
features/publication/client/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1 @@
|
||||
<manifest package="dev.inmo.postssystem.features.publication.client"/>
|
19
features/publication/common/build.gradle
Normal file
19
features/publication/common/build.gradle
Normal file
@ -0,0 +1,19 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api project(":postssystem.features.common.common")
|
||||
api project(":postssystem.features.content.common")
|
||||
api project(":postssystem.features.posts.common")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1
features/publication/common/src/main/AndroidManifest.xml
Normal file
1
features/publication/common/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1 @@
|
||||
<manifest package="dev.inmo.postssystem.features.publication.common"/>
|
19
features/publication/server/build.gradle
Normal file
19
features/publication/server/build.gradle
Normal file
@ -0,0 +1,19 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
}
|
||||
|
||||
apply from: "$mppJavaProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api project(":postssystem.features.publication.common")
|
||||
api project(":postssystem.features.common.server")
|
||||
api project(":postssystem.features.content.server")
|
||||
api project(":postssystem.features.posts.server")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
33
features/publication/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/publication/server/PublicationManager.kt
Normal file
33
features/publication/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/publication/server/PublicationManager.kt
Normal file
@ -0,0 +1,33 @@
|
||||
package dev.inmo.postssystem.features.publication.server
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.asyncSafelyWithoutExceptions
|
||||
import dev.inmo.postssystem.features.content.server.ServerReadContentStorage
|
||||
import dev.inmo.postssystem.features.posts.common.PostId
|
||||
import dev.inmo.postssystem.features.posts.server.ServerReadPostsStorage
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
class PublicationManager (
|
||||
private val targets: List<PublicationTarget>,
|
||||
private val postsRepo: ServerReadPostsStorage,
|
||||
private val contentRepo: ServerReadContentStorage,
|
||||
private val scope: CoroutineScope
|
||||
) {
|
||||
suspend fun publish(
|
||||
postId: PostId
|
||||
) {
|
||||
val post = postsRepo.getById(postId) ?: return
|
||||
val content = post.content.map {
|
||||
scope.async {
|
||||
contentRepo.getById(it)
|
||||
}
|
||||
}.awaitAll().filterNotNull()
|
||||
|
||||
val publicationPost = PublicationPost(post, content)
|
||||
|
||||
targets.map {
|
||||
scope.asyncSafelyWithoutExceptions {
|
||||
it.publish(publicationPost)
|
||||
}
|
||||
}.awaitAll()
|
||||
}
|
||||
}
|
11
features/publication/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/publication/server/PublicationPost.kt
Normal file
11
features/publication/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/publication/server/PublicationPost.kt
Normal file
@ -0,0 +1,11 @@
|
||||
package dev.inmo.postssystem.features.publication.server
|
||||
|
||||
import dev.inmo.postssystem.features.content.common.RegisteredContent
|
||||
import dev.inmo.postssystem.features.posts.common.RegisteredPost
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class PublicationPost(
|
||||
val post: RegisteredPost,
|
||||
val content: List<RegisteredContent>
|
||||
)
|
5
features/publication/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/publication/server/PublicationTarget.kt
Normal file
5
features/publication/server/src/jvmMain/kotlin/dev/inmo/postssystem/features/publication/server/PublicationTarget.kt
Normal file
@ -0,0 +1,5 @@
|
||||
package dev.inmo.postssystem.features.publication.server
|
||||
|
||||
fun interface PublicationTarget {
|
||||
suspend fun publish(post: PublicationPost)
|
||||
}
|
Reference in New Issue
Block a user