Merge branch 'posting-ktor-common' of PostsSystem/Core into master
This commit is contained in:
commit
ae51e728d4
78
publishing/ktor/client/build.gradle
Normal file
78
publishing/ktor/client/build.gradle
Normal 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')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
0
publishing/ktor/client/publish.gradle
Normal file
0
publishing/ktor/client/publish.gradle
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
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
|
||||||
|
import com.insanusmokrassar.postssystem.publishing.ktor.publishingKeysRootRoute
|
||||||
|
import io.ktor.client.HttpClient
|
||||||
|
import io.ktor.client.features.websocket.WebSockets
|
||||||
|
|
||||||
|
class PublishingKeysRepoKtorClient private constructor (
|
||||||
|
readPublishingKeysClient: ReadPublishingKeysRepoKtorClient,
|
||||||
|
writePublishingKeysClient: WritePublishingKeysRepoKtorClient
|
||||||
|
) : PublishingKeysRepo, ReadPublishingKeysRepo by readPublishingKeysClient, WritePublishingKeysRepo by writePublishingKeysClient {
|
||||||
|
constructor(
|
||||||
|
baseUrl: String,
|
||||||
|
client: HttpClient = HttpClient {
|
||||||
|
install(WebSockets)
|
||||||
|
}
|
||||||
|
) : this (
|
||||||
|
ReadPublishingKeysRepoKtorClient (
|
||||||
|
"$baseUrl/$publishingKeysRootRoute",
|
||||||
|
client
|
||||||
|
),
|
||||||
|
WritePublishingKeysRepoKtorClient(
|
||||||
|
"$baseUrl/$publishingKeysRootRoute",
|
||||||
|
client
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
@ -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/$key",
|
||||||
|
PostId.serializer().nullable
|
||||||
|
)
|
||||||
|
|
||||||
|
override suspend fun getTriggerControlKeyByPostId(postId: PostId): TriggerControlKey? = client.uniget(
|
||||||
|
"$baseUrl/$getTriggerControlKeyByPostIdRoute/$postId",
|
||||||
|
TriggerControlKey.serializer().nullable
|
||||||
|
)
|
||||||
|
}
|
@ -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()
|
||||||
|
)
|
||||||
|
}
|
76
publishing/ktor/common/build.gradle
Normal file
76
publishing/ktor/common/build.gradle
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
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()
|
||||||
|
|
||||||
|
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.ktor.common:$core_version"
|
||||||
|
api "com.insanusmokrassar:postssystem.publishing.api:$core_version"
|
||||||
|
} else {
|
||||||
|
api projectByName("postssystem.ktor.common")
|
||||||
|
api projectByName("postssystem.publishing.api")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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,9 @@
|
|||||||
|
package com.insanusmokrassar.postssystem.publishing.ktor
|
||||||
|
|
||||||
|
const val publishingKeysRootRoute = "publishingKeys"
|
||||||
|
|
||||||
|
const val getPostIdByTriggerControlKeyRoute = "getPostIdByTriggerControlKey"
|
||||||
|
const val getTriggerControlKeyByPostIdRoute = "getTriggerControlKeyByPostId"
|
||||||
|
|
||||||
|
const val setPostTriggerControlKeyRoute = "setPostTriggerControlKey"
|
||||||
|
const val unsetPostTriggerControlKeyRoute = "unsetPostTriggerControlKey"
|
@ -0,0 +1,4 @@
|
|||||||
|
package com.insanusmokrassar.postssystem.publishing.ktor
|
||||||
|
|
||||||
|
//const val getPostIdByTriggerControlKeyRoute = "getPostIdByTriggerControlKey"
|
||||||
|
const val registerTriggerForPostRoute = "registerTriggerForPost"
|
@ -0,0 +1,3 @@
|
|||||||
|
package com.insanusmokrassar.postssystem.publishing.ktor
|
||||||
|
|
||||||
|
const val triggerPostingRoute = "triggerPosting"
|
@ -0,0 +1,6 @@
|
|||||||
|
package com.insanusmokrassar.postssystem.publishing.ktor
|
||||||
|
|
||||||
|
import com.insanusmokrassar.postssystem.ktor.setIdsSerializer
|
||||||
|
|
||||||
|
val postsIdSerializer = setIdsSerializer
|
||||||
|
val triggerControlKeysSerializer = setIdsSerializer
|
@ -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
|
||||||
|
)
|
41
publishing/ktor/server/build.gradle
Normal file
41
publishing/ktor/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("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"
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.insanusmokrassar.postssystem.publishing.ktor.server
|
||||||
|
|
||||||
|
import com.insanusmokrassar.postssystem.core.publishing.repos.PublishingKeysRepo
|
||||||
|
import com.insanusmokrassar.postssystem.ktor.server.configurators.ApplicationRoutingConfigurator
|
||||||
|
import com.insanusmokrassar.postssystem.publishing.ktor.publishingKeysRootRoute
|
||||||
|
import io.ktor.routing.Route
|
||||||
|
import io.ktor.routing.route
|
||||||
|
|
||||||
|
fun Route.configurePublishingKeysRepoRoutes (
|
||||||
|
proxyTo: PublishingKeysRepo
|
||||||
|
) {
|
||||||
|
route(publishingKeysRootRoute) {
|
||||||
|
configureReadPublishingKeysRepoRoutes(proxyTo)
|
||||||
|
configureWritePublishingKeysRepoRoutes(proxyTo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PublishingKeysRepoRoutingConfigurator (
|
||||||
|
private val proxyTo: PublishingKeysRepo
|
||||||
|
) : ApplicationRoutingConfigurator.Element {
|
||||||
|
override fun Route.invoke() {
|
||||||
|
configurePublishingKeysRepoRoutes(proxyTo)
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
||||||
|
)
|
@ -22,6 +22,9 @@ String[] includes = [
|
|||||||
|
|
||||||
':publishing:api',
|
':publishing:api',
|
||||||
':publishing:exposed',
|
':publishing:exposed',
|
||||||
|
':publishing:ktor:common',
|
||||||
|
':publishing:ktor:client',
|
||||||
|
':publishing:ktor:server',
|
||||||
|
|
||||||
':markups:commons',
|
':markups:commons',
|
||||||
':markups:html'
|
':markups:html'
|
||||||
|
Loading…
Reference in New Issue
Block a user