add post creating business case
This commit is contained in:
parent
cf1aa3ae0f
commit
60725d9fa3
74
business_cases/post_creating/client/build.gradle
Normal file
74
business_cases/post_creating/client/build.gradle
Normal file
@ -0,0 +1,74 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
||||
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version"
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url "https://kotlin.bintray.com/kotlinx" }
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
js (BOTH) {
|
||||
browser()
|
||||
nodejs()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
|
||||
api projectByName("business_cases.post_creating.common")
|
||||
api projectByName("core.ktor.client")
|
||||
}
|
||||
}
|
||||
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-js')
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.insanusmokrassar.postssystem.business_cases.post_creating.client
|
||||
|
||||
import com.insanusmokrassar.postssystem.business_cases.post_creating.server.*
|
||||
import com.insanusmokrassar.postssystem.core.content.Content
|
||||
import com.insanusmokrassar.postssystem.core.post.RegisteredPost
|
||||
import com.insanusmokrassar.postssystem.core.publishing.TriggerId
|
||||
import com.insanusmokrassar.postssystem.ktor.buildStandardUrl
|
||||
import com.insanusmokrassar.postssystem.ktor.client.BodyPair
|
||||
import com.insanusmokrassar.postssystem.ktor.client.unipost
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.post
|
||||
|
||||
class PostCreatingClientCase(
|
||||
private val baseUrl: String,
|
||||
private val client: HttpClient
|
||||
) : PostCreatingCase {
|
||||
private val realBaseUrl = "$baseUrl/$postCreatingRootRoute"
|
||||
override suspend fun createPost(postContent: List<Content>, triggerId: TriggerId): RegisteredPost? = client.unipost(
|
||||
buildStandardUrl(realBaseUrl, postCreatingCreatePostRoute),
|
||||
BodyPair(PostCreatingCreatePostModel.serializer(), PostCreatingCreatePostModel(postContent, triggerId)),
|
||||
RegisteredPost.serializer()
|
||||
)
|
||||
}
|
74
business_cases/post_creating/common/build.gradle
Normal file
74
business_cases/post_creating/common/build.gradle
Normal file
@ -0,0 +1,74 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
||||
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version"
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url "https://kotlin.bintray.com/kotlinx" }
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
js (BOTH) {
|
||||
browser()
|
||||
nodejs()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
|
||||
api projectByName("core.ktor.common")
|
||||
api projectByName("publishing.ktor.common")
|
||||
}
|
||||
}
|
||||
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-js')
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.insanusmokrassar.postssystem.business_cases.post_creating.server
|
||||
|
||||
import com.benasher44.uuid.uuid4
|
||||
import com.insanusmokrassar.postssystem.core.content.Content
|
||||
import com.insanusmokrassar.postssystem.core.content.api.ContentRepo
|
||||
import com.insanusmokrassar.postssystem.core.post.*
|
||||
import com.insanusmokrassar.postssystem.core.post.repo.PostsRepo
|
||||
import com.insanusmokrassar.postssystem.core.publishing.*
|
||||
|
||||
class BusinessPostCreatingCase(
|
||||
private val postsRepo: PostsRepo,
|
||||
private val contentRepo: ContentRepo,
|
||||
private val publishingRegistrar: PublishingRegistrar,
|
||||
private val postKeyGenerator: PostKeyGenerator = { _, _ -> uuid4().toString() }
|
||||
) : PostCreatingCase {
|
||||
override suspend fun createPost(postContent: List<Content>, triggerId: TriggerId): RegisteredPost? {
|
||||
val content = postContent.mapNotNull { contentRepo.registerContent(it) }
|
||||
val post = postsRepo.createPost(SimplePost(content.map { it.id })) ?: return null
|
||||
|
||||
publishingRegistrar.registerTriggerForPost(
|
||||
postKeyGenerator(post.id, triggerId),
|
||||
post.id
|
||||
)
|
||||
|
||||
return post
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.insanusmokrassar.postssystem.business_cases.post_creating.server
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.content.Content
|
||||
import com.insanusmokrassar.postssystem.core.post.RegisteredPost
|
||||
import com.insanusmokrassar.postssystem.core.publishing.PublishingKeyReceiver
|
||||
import com.insanusmokrassar.postssystem.core.publishing.TriggerId
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class PostCreatingCreatePostModel(
|
||||
val postContent: List<Content>,
|
||||
val triggerId: TriggerId
|
||||
)
|
||||
|
||||
interface PostCreatingCase {
|
||||
suspend fun createPost(
|
||||
postContent: List<Content>,
|
||||
triggerId: TriggerId
|
||||
): RegisteredPost?
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.insanusmokrassar.postssystem.business_cases.post_creating.server
|
||||
|
||||
const val postCreatingRootRoute = "postCreating"
|
||||
|
||||
const val postCreatingCreatePostRoute = "createPost"
|
41
business_cases/post_creating/server/build.gradle
Normal file
41
business_cases/post_creating/server/build.gradle
Normal file
@ -0,0 +1,41 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
||||
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version"
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
|
||||
}
|
||||
|
||||
project.version = "$core_version"
|
||||
project.group = "com.insanusmokrassar"
|
||||
|
||||
apply plugin: "java-library"
|
||||
apply plugin: "kotlin"
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url "https://kotlin.bintray.com/kotlinx" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
|
||||
api projectByName("business_cases.post_creating.common")
|
||||
api projectByName("core.ktor.server")
|
||||
|
||||
testImplementation "org.xerial:sqlite-jdbc:$test_sqlite_version"
|
||||
testImplementation "org.jetbrains.kotlin:kotlin-test"
|
||||
testImplementation "org.jetbrains.kotlin:kotlin-test-junit"
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.insanusmokrassar.postssystem.business_cases.post_creating.server
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.post.RegisteredPost
|
||||
import com.insanusmokrassar.postssystem.ktor.server.unianswer
|
||||
import com.insanusmokrassar.postssystem.ktor.server.uniload
|
||||
import io.ktor.application.call
|
||||
import io.ktor.routing.*
|
||||
import kotlinx.serialization.builtins.nullable
|
||||
|
||||
fun Route.configurePostCreatingRoutes(
|
||||
origin: PostCreatingCase
|
||||
) {
|
||||
route(postCreatingRootRoute) {
|
||||
post(postCreatingCreatePostRoute) {
|
||||
val model = call.uniload(PostCreatingCreatePostModel.serializer())
|
||||
|
||||
call.unianswer(
|
||||
RegisteredPost.serializer().nullable,
|
||||
origin.createPost(model.postContent, model.triggerId)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -46,8 +46,8 @@ kotlin {
|
||||
api "com.insanusmokrassar:postssystem.utils.common:$core_version"
|
||||
api "com.insanusmokrassar:postssystem.utils.repos.common:$core_version"
|
||||
} else {
|
||||
api projectByName("postssystem.utils.common")
|
||||
api projectByName("postssystem.utils.repos.common")
|
||||
api projectByName("utils.common")
|
||||
api projectByName("utils.repos.common")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ dependencies {
|
||||
api "com.insanusmokrassar:postssystem.core.api:$core_version"
|
||||
api "com.insanusmokrassar:postssystem.exposed.commons:$core_version"
|
||||
} else {
|
||||
api projectByName("postssystem.core.api")
|
||||
api projectByName("postssystem.exposed.commons")
|
||||
api projectByName("core.api")
|
||||
api projectByName("exposed.commons")
|
||||
}
|
||||
|
||||
testImplementation "org.xerial:sqlite-jdbc:$test_sqlite_version"
|
||||
|
@ -45,8 +45,8 @@ kotlin {
|
||||
api "com.insanusmokrassar:postssystem.core.ktor.common:$core_version"
|
||||
api "com.insanusmokrassar:postssystem.ktor.client:$core_version"
|
||||
} else {
|
||||
api projectByName("postssystem.core.ktor.common")
|
||||
api projectByName("postssystem.ktor.client")
|
||||
api projectByName("core.ktor.common")
|
||||
api projectByName("ktor.client")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ kotlin {
|
||||
api "com.insanusmokrassar:postssystem.ktor.common:$core_version"
|
||||
api "com.insanusmokrassar:postssystem.core.api:$core_version"
|
||||
} else {
|
||||
api projectByName("postssystem.ktor.common")
|
||||
api projectByName("postssystem.core.api")
|
||||
api projectByName("ktor.common")
|
||||
api projectByName("core.api")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -32,8 +32,8 @@ repositories {
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
|
||||
api projectByName("postssystem.core.ktor.common")
|
||||
api projectByName("postssystem.ktor.server")
|
||||
api projectByName("core.ktor.common")
|
||||
api projectByName("ktor.server")
|
||||
|
||||
testImplementation "org.xerial:sqlite-jdbc:$test_sqlite_version"
|
||||
testImplementation "org.jetbrains.kotlin:kotlin-test"
|
||||
|
@ -38,7 +38,7 @@ dependencies {
|
||||
if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") {
|
||||
api "com.insanusmokrassar:postssystem.utils.repos:$core_version"
|
||||
} else {
|
||||
api projectByName("postssystem.utils.repos.common")
|
||||
api projectByName("utils.repos.common")
|
||||
}
|
||||
|
||||
testImplementation "org.jetbrains.kotlin:kotlin-test"
|
||||
|
@ -44,7 +44,7 @@ kotlin {
|
||||
if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") {
|
||||
api "com.insanusmokrassar:postssystem.ktor.common:$core_version"
|
||||
} else {
|
||||
api projectByName("postssystem.ktor.common")
|
||||
api projectByName("ktor.common")
|
||||
}
|
||||
|
||||
api "io.ktor:ktor-client-core:$ktor_version"
|
||||
|
@ -43,7 +43,7 @@ kotlin {
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlin_serialisation_core_version"
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-cbor:$kotlin_serialisation_core_version"
|
||||
|
||||
api projectByName("postssystem.utils.common")
|
||||
api projectByName("utils.common")
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
|
@ -38,7 +38,7 @@ kotlin {
|
||||
implementation kotlin('stdlib')
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||
|
||||
api projectByName("postssystem.ktor.common")
|
||||
api projectByName("ktor.common")
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
|
@ -31,8 +31,8 @@ repositories {
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
|
||||
api projectByName("postssystem.ktor.client")
|
||||
api projectByName("postssystem.ktor.server")
|
||||
api projectByName("ktor.client")
|
||||
api projectByName("ktor.server")
|
||||
|
||||
testImplementation "org.jetbrains.kotlin:kotlin-test"
|
||||
testImplementation "org.jetbrains.kotlin:kotlin-test-junit"
|
||||
|
@ -44,7 +44,7 @@ kotlin {
|
||||
if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") {
|
||||
api "com.insanusmokrassar:postssystem.core.api:$core_version"
|
||||
} else {
|
||||
api projectByName("postssystem.core.api")
|
||||
api projectByName("core.api")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.insanusmokrassar.postssystem.core.publishing
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.post.PostId
|
||||
|
||||
typealias PostKeyGenerator = suspend (PostId, TriggerId) -> TriggerControlKey
|
@ -37,8 +37,8 @@ dependencies {
|
||||
api "com.insanusmokrassar:postssystem.core.publishing:$core_version"
|
||||
api "com.insanusmokrassar:postssystem.exposed.commons:$core_version"
|
||||
} else {
|
||||
api projectByName("postssystem.publishing.api")
|
||||
api projectByName("postssystem.exposed.commons")
|
||||
api projectByName("publishing.api")
|
||||
api projectByName("exposed.commons")
|
||||
}
|
||||
|
||||
testImplementation "org.xerial:sqlite-jdbc:$test_sqlite_version"
|
||||
|
@ -45,8 +45,8 @@ kotlin {
|
||||
api "com.insanusmokrassar:postssystem.core.ktor.common:$core_version"
|
||||
api "com.insanusmokrassar:postssystem.ktor.client:$core_version"
|
||||
} else {
|
||||
api projectByName("postssystem.publishing.ktor.common")
|
||||
api projectByName("postssystem.ktor.client")
|
||||
api projectByName("publishing.ktor.common")
|
||||
api projectByName("ktor.client")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,8 +43,8 @@ kotlin {
|
||||
api "com.insanusmokrassar:postssystem.ktor.common:$core_version"
|
||||
api "com.insanusmokrassar:postssystem.publishing.api:$core_version"
|
||||
} else {
|
||||
api projectByName("postssystem.ktor.common")
|
||||
api projectByName("postssystem.publishing.api")
|
||||
api projectByName("ktor.common")
|
||||
api projectByName("publishing.api")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ repositories {
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
|
||||
api projectByName("postssystem.publishing.ktor.common")
|
||||
api projectByName("postssystem.ktor.server")
|
||||
api projectByName("publishing.ktor.common")
|
||||
api projectByName("ktor.server")
|
||||
|
||||
testImplementation "org.xerial:sqlite-jdbc:$test_sqlite_version"
|
||||
testImplementation "org.jetbrains.kotlin:kotlin-test"
|
||||
|
@ -27,12 +27,16 @@ String[] includes = [
|
||||
':publishing:exposed',
|
||||
':publishing:ktor:common',
|
||||
':publishing:ktor:client',
|
||||
':publishing:ktor:server'
|
||||
':publishing:ktor:server',
|
||||
|
||||
':business_cases:post_creating:server',
|
||||
':business_cases:post_creating:common',
|
||||
':business_cases:post_creating:client',
|
||||
]
|
||||
|
||||
|
||||
includes.each {
|
||||
include it
|
||||
ProjectDescriptor project = project(it)
|
||||
project.name = rootProject.name + project.projectDir.absolutePath.replace(rootDir.absolutePath, "").replace(File.separator, ".")
|
||||
project.name = project.projectDir.absolutePath.replace("${rootDir.absolutePath}${File.separator}", "").replace(File.separator, ".")
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ kotlin {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
|
||||
api projectByName("postssystem.utils.common")
|
||||
api projectByName("utils.common")
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
|
@ -37,8 +37,8 @@ dependencies {
|
||||
api "com.insanusmokrassar:postssystem.utils.repos:$core_version"
|
||||
api "com.insanusmokrassar:postssystem.exposed.commons:$core_version"
|
||||
} else {
|
||||
api projectByName("postssystem.utils.repos.common")
|
||||
api projectByName("postssystem.exposed.commons")
|
||||
api projectByName("utils.repos.common")
|
||||
api projectByName("exposed.commons")
|
||||
}
|
||||
|
||||
testImplementation "org.xerial:sqlite-jdbc:$test_sqlite_version"
|
||||
|
@ -39,8 +39,8 @@ kotlin {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
|
||||
api projectByName("postssystem.utils.repos.ktor.common")
|
||||
api projectByName("postssystem.ktor.client")
|
||||
api projectByName("utils.repos.ktor.common")
|
||||
api projectByName("ktor.client")
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
|
@ -39,8 +39,8 @@ kotlin {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
|
||||
api projectByName("postssystem.utils.repos.common")
|
||||
api projectByName("postssystem.ktor.common")
|
||||
api projectByName("utils.repos.common")
|
||||
api projectByName("ktor.common")
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
|
@ -36,8 +36,8 @@ kotlin {
|
||||
implementation kotlin('stdlib')
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||
|
||||
api projectByName("postssystem.utils.repos.ktor.common")
|
||||
api projectByName("postssystem.ktor.server")
|
||||
api projectByName("utils.repos.ktor.common")
|
||||
api projectByName("ktor.server")
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
|
Loading…
Reference in New Issue
Block a user