impl publishing klient and kerver

This commit is contained in:
000Sanya 2020-08-15 16:37:52 +10:00
parent 544a74588c
commit 626edccc7d
11 changed files with 301 additions and 0 deletions

View File

@ -0,0 +1,78 @@
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"
apply from: "publish.gradle"
repositories {
mavenLocal()
jcenter()
mavenCentral()
maven { url "https://kotlin.bintray.com/kotlinx" }
}
kotlin {
jvm()
js()
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.ktor.common:$core_version"
api "com.insanusmokrassar:postssystem.ktor.client:$core_version"
} else {
api projectByName("postssystem.publishing.ktor.common")
api projectByName("postssystem.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')
}
}
}
}

View File

View File

@ -0,0 +1,10 @@
package com.insanusmokrassar.postssystem.publishing.ktor.client
import com.insanusmokrassar.postssystem.core.publishing.repos.PublishingKeysRepo
import com.insanusmokrassar.postssystem.core.publishing.repos.ReadPublishingKeysRepo
import com.insanusmokrassar.postssystem.core.publishing.repos.WritePublishingKeysRepo
class PublishingKeysRepoKtorClient (
readPublishingKeysClient: ReadPublishingKeysRepoKtorClient,
writePublishingKeysClient: WritePublishingKeysRepoKtorClient
) : PublishingKeysRepo, ReadPublishingKeysRepo by readPublishingKeysClient, WritePublishingKeysRepo by writePublishingKeysClient

View File

@ -0,0 +1,26 @@
package com.insanusmokrassar.postssystem.publishing.ktor.client
import com.insanusmokrassar.postssystem.core.post.PostId
import com.insanusmokrassar.postssystem.core.publishing.TriggerControlKey
import com.insanusmokrassar.postssystem.core.publishing.repos.ReadPublishingKeysRepo
import com.insanusmokrassar.postssystem.ktor.client.uniget
import com.insanusmokrassar.postssystem.publishing.ktor.getPostIdByTriggerControlKeyRoute
import com.insanusmokrassar.postssystem.publishing.ktor.getTriggerControlKeyByPostIdRoute
import io.ktor.client.HttpClient
import kotlinx.serialization.builtins.nullable
import kotlinx.serialization.builtins.serializer
class ReadPublishingKeysRepoKtorClient (
private val baseUrl: String,
private val client: HttpClient = HttpClient()
) : ReadPublishingKeysRepo {
override suspend fun getPostIdByTriggerControlKey(key: TriggerControlKey): PostId? = client.uniget(
"$baseUrl/$getPostIdByTriggerControlKeyRoute",
PostId.serializer().nullable
)
override suspend fun getTriggerControlKeyByPostId(postId: PostId): TriggerControlKey? = client.uniget(
"$baseUrl/$getTriggerControlKeyByPostIdRoute",
TriggerControlKey.serializer().nullable
)
}

View File

@ -0,0 +1,29 @@
package com.insanusmokrassar.postssystem.publishing.ktor.client
import com.insanusmokrassar.postssystem.core.post.PostId
import com.insanusmokrassar.postssystem.core.publishing.TriggerControlKey
import com.insanusmokrassar.postssystem.core.publishing.repos.WritePublishingKeysRepo
import com.insanusmokrassar.postssystem.ktor.client.BodyPair
import com.insanusmokrassar.postssystem.ktor.client.unipost
import com.insanusmokrassar.postssystem.publishing.ktor.SetPostTriggerControlKeyObject
import com.insanusmokrassar.postssystem.publishing.ktor.setPostTriggerControlKeyRoute
import com.insanusmokrassar.postssystem.publishing.ktor.unsetPostTriggerControlKeyRoute
import io.ktor.client.HttpClient
import kotlinx.serialization.builtins.serializer
class WritePublishingKeysRepoKtorClient (
private val baseUrl: String,
private val client: HttpClient = HttpClient()
) : WritePublishingKeysRepo {
override suspend fun setPostTriggerControlKey(postId: PostId, key: TriggerControlKey): Boolean = client.unipost(
"$baseUrl/$setPostTriggerControlKeyRoute",
BodyPair(SetPostTriggerControlKeyObject.serializer(), SetPostTriggerControlKeyObject(postId, key)),
Boolean.serializer()
)
override suspend fun unsetPostTriggerControlKey(postId: PostId): Boolean = client.unipost(
"$baseUrl/$unsetPostTriggerControlKeyRoute",
BodyPair(PostId.serializer(), postId),
Boolean.serializer()
)
}

View File

@ -0,0 +1,11 @@
package com.insanusmokrassar.postssystem.publishing.ktor
import com.insanusmokrassar.postssystem.core.post.PostId
import com.insanusmokrassar.postssystem.core.publishing.TriggerControlKey
import kotlinx.serialization.Serializable
@Serializable
data class SetPostTriggerControlKeyObject (
val postId: PostId,
val key: TriggerControlKey
)

View 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("postssystem.publishing.ktor.common")
api projectByName("postssystem.ktor.server")
testImplementation "org.xerial:sqlite-jdbc:$test_sqlite_version"
testImplementation "org.jetbrains.kotlin:kotlin-test"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit"
}

View File

@ -0,0 +1,20 @@
package com.insanusmokrassar.postssystem.publishing.ktor.server
import com.insanusmokrassar.postssystem.core.publishing.repos.PublishingKeysRepo
import com.insanusmokrassar.postssystem.ktor.server.configurators.ApplicationRoutingConfigurator
import io.ktor.routing.Route
fun Route.configurePublishingKeysRepoRoutes (
proxyTo: PublishingKeysRepo
) {
configureReadPublishingKeysRepoRoutes(proxyTo)
configureWritePublishingKeysRepoRoutes(proxyTo)
}
class PublishingKeysRepoRoutingConfigurator (
private val proxyTo: PublishingKeysRepo
) : ApplicationRoutingConfigurator.Element {
override fun Route.invoke() {
configurePublishingKeysRepoRoutes(proxyTo)
}
}

View File

@ -0,0 +1,45 @@
package com.insanusmokrassar.postssystem.publishing.ktor.server
import com.insanusmokrassar.postssystem.core.post.PostId
import com.insanusmokrassar.postssystem.core.publishing.TriggerControlKey
import com.insanusmokrassar.postssystem.core.publishing.repos.ReadPublishingKeysRepo
import com.insanusmokrassar.postssystem.ktor.server.configurators.ApplicationRoutingConfigurator
import com.insanusmokrassar.postssystem.ktor.server.getParameterOrSendError
import com.insanusmokrassar.postssystem.ktor.server.unianswer
import com.insanusmokrassar.postssystem.publishing.ktor.getPostIdByTriggerControlKeyRoute
import com.insanusmokrassar.postssystem.publishing.ktor.getTriggerControlKeyByPostIdRoute
import io.ktor.application.call
import io.ktor.routing.Route
import io.ktor.routing.get
import kotlinx.serialization.builtins.nullable
import kotlinx.serialization.builtins.serializer
fun Route.configureReadPublishingKeysRepoRoutes (
proxyTo: ReadPublishingKeysRepo
) {
get("$getPostIdByTriggerControlKeyRoute/{key}") {
val key: TriggerControlKey = call.getParameterOrSendError("key") ?: return@get
call.unianswer(
PostId.serializer().nullable,
proxyTo.getPostIdByTriggerControlKey(key)
)
}
get("$getTriggerControlKeyByPostIdRoute/{postId}") {
val postId: PostId = call.getParameterOrSendError("postId") ?: return@get
call.unianswer(
TriggerControlKey.serializer().nullable,
proxyTo.getTriggerControlKeyByPostId(postId)
)
}
}
class ReadPublishingKeysRepoRoutingConfigurator (
private val proxyTo: ReadPublishingKeysRepo
) : ApplicationRoutingConfigurator.Element {
override fun Route.invoke() {
configureReadPublishingKeysRepoRoutes(proxyTo)
}
}

View File

@ -0,0 +1,39 @@
package com.insanusmokrassar.postssystem.publishing.ktor.server
import com.insanusmokrassar.postssystem.core.post.PostId
import com.insanusmokrassar.postssystem.core.publishing.repos.WritePublishingKeysRepo
import com.insanusmokrassar.postssystem.ktor.server.unianswer
import com.insanusmokrassar.postssystem.ktor.server.uniload
import com.insanusmokrassar.postssystem.publishing.ktor.SetPostTriggerControlKeyObject
import com.insanusmokrassar.postssystem.publishing.ktor.setPostTriggerControlKeyRoute
import com.insanusmokrassar.postssystem.publishing.ktor.unsetPostTriggerControlKeyRoute
import io.ktor.application.call
import io.ktor.routing.Route
import io.ktor.routing.post
import kotlinx.serialization.builtins.serializer
fun Route.configureWritePublishingKeysRepoRoutes (
proxyTo: WritePublishingKeysRepo
) {
post(setPostTriggerControlKeyRoute) {
val obj = call.uniload(SetPostTriggerControlKeyObject.serializer())
call.unianswer(
Boolean.serializer(),
proxyTo.setPostTriggerControlKey(obj.postId, obj.key)
)
}
post(unsetPostTriggerControlKeyRoute) {
val postId = call.uniload(PostId.serializer())
call.unianswer(
Boolean.serializer(),
proxyTo.unsetPostTriggerControlKey(postId)
)
}
}
class WritePublishingKeysRepoRoutingConfigurator (
private val proxyTo: WritePublishingKeysRepo
)

View File

@ -23,6 +23,8 @@ String[] includes = [
':publishing:api',
':publishing:exposed',
':publishing:ktor:common',
':publishing:ktor:client',
':publishing:ktor:server',
':markups:commons',
':markups:html'