add post creating business case
This commit is contained in:
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)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user