From 3795b858274054957b4f0eaea5ba8e4c9ae0ad59 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 30 Jul 2020 15:28:11 +0600 Subject: [PATCH] just commit --- postssystem.core.exposed/build.gradle | 8 +-- .../postssystem/core/exposed/ChannelsSizes.kt | 3 - .../core/exposed/ExposedContentAPI.kt | 5 +- ...ExposedPostsAPI.kt => ExposedPostsRepo.kt} | 19 ++++--- ...ests.kt => ExposedPostsRepoCommonTests.kt} | 6 +- .../build.gradle | 47 ++++++++++++++++ .../gradle.properties | 2 + .../maven.publish.gradle | 53 ++++++++++++++++++ .../publish.gradle | 55 ++++++++++++++++++ .../publish_config.kpsb | 1 + .../exposed/ExposedPublishingKeysRepo.kt | 56 +++++++++++++++++++ postssystem.core.publishing/build.gradle | 5 +- .../core/publishing/PublishingTrigger.kt | 8 +-- .../publishing/repos/PublishingKeysRepo.kt | 2 +- postssystem.core/build.gradle | 3 +- .../postssystem/core/content/Content.kt | 2 +- ...API.kt => BusinessPublishablePostsRepo.kt} | 14 ++--- .../postssystem/core/post/Post.kt | 4 +- .../postssystem/core/post/api/PostsAPI.kt | 3 - .../postssystem/core/post/repo/PostsRepo.kt | 3 + .../ReadPostsAPI.kt => repo/ReadPostsRepo.kt} | 6 +- .../WritePostsRepo.kt} | 4 +- postssystem.exposed.commons/build.gradle | 47 ++++++++++++++++ postssystem.exposed.commons/gradle.properties | 2 + .../maven.publish.gradle | 53 ++++++++++++++++++ postssystem.exposed.commons/publish.gradle | 55 ++++++++++++++++++ .../publish_config.kpsb | 1 + .../exposed/commons/QueryExtensions.kt | 7 +++ settings.gradle | 2 + 29 files changed, 429 insertions(+), 47 deletions(-) delete mode 100644 postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ChannelsSizes.kt rename postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/{ExposedPostsAPI.kt => ExposedPostsRepo.kt} (94%) rename postssystem.core.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/{ExposedPostsAPICommonTests.kt => ExposedPostsRepoCommonTests.kt} (94%) create mode 100644 postssystem.core.publishing.exposed/build.gradle create mode 100644 postssystem.core.publishing.exposed/gradle.properties create mode 100644 postssystem.core.publishing.exposed/maven.publish.gradle create mode 100644 postssystem.core.publishing.exposed/publish.gradle create mode 100644 postssystem.core.publishing.exposed/publish_config.kpsb create mode 100644 postssystem.core.publishing.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/exposed/ExposedPublishingKeysRepo.kt rename postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/{BusinessPublishablePostsAPI.kt => BusinessPublishablePostsRepo.kt} (50%) delete mode 100644 postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/api/PostsAPI.kt create mode 100644 postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/repo/PostsRepo.kt rename postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/{api/ReadPostsAPI.kt => repo/ReadPostsRepo.kt} (92%) rename postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/{api/WritePostsAPI.kt => repo/WritePostsRepo.kt} (88%) create mode 100644 postssystem.exposed.commons/build.gradle create mode 100644 postssystem.exposed.commons/gradle.properties create mode 100644 postssystem.exposed.commons/maven.publish.gradle create mode 100644 postssystem.exposed.commons/publish.gradle create mode 100644 postssystem.exposed.commons/publish_config.kpsb create mode 100644 postssystem.exposed.commons/src/main/kotlin/com/insanusmokrassar/postssystem/exposed/commons/QueryExtensions.kt diff --git a/postssystem.core.exposed/build.gradle b/postssystem.core.exposed/build.gradle index b72a37e3..29ca7dde 100644 --- a/postssystem.core.exposed/build.gradle +++ b/postssystem.core.exposed/build.gradle @@ -31,14 +31,14 @@ repositories { } dependencies { - api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - api "org.jetbrains.exposed:exposed-core:$exposed_version" - api "org.jetbrains.exposed:exposed-jdbc:$exposed_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") { api "com.insanusmokrassar:postssystem.core:$core_version" + api "com.insanusmokrassar:postssystem.exposed.commons:$core_version" } else { - implementation project(":postssystem.core") + api project(":postssystem.core") + api project(":postssystem.exposed.commons") } testImplementation "org.xerial:sqlite-jdbc:$test_sqlite_version" diff --git a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ChannelsSizes.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ChannelsSizes.kt deleted file mode 100644 index a95847b6..00000000 --- a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ChannelsSizes.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.insanusmokrassar.postssystem.core.exposed - -internal const val ChannelDefaultSize = 64 diff --git a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPI.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPI.kt index 3c74c501..1bc3e0d8 100644 --- a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPI.kt +++ b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedContentAPI.kt @@ -6,6 +6,7 @@ import com.insanusmokrassar.postssystem.core.exposed.content.* import com.insanusmokrassar.postssystem.core.utils.generateContentId import com.insanusmokrassar.postssystem.core.utils.pagination.* import kotlinx.coroutines.channels.BroadcastChannel +import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.asFlow import org.jetbrains.exposed.sql.* @@ -33,8 +34,8 @@ private class ContentAPIDatabaseTable( } } - private val contentCreatedBroadcastChannel = BroadcastChannel(ChannelDefaultSize) - private val contentDeletedBroadcastChannel = BroadcastChannel(ChannelDefaultSize) + private val contentCreatedBroadcastChannel = BroadcastChannel(Channel.BUFFERED) + private val contentDeletedBroadcastChannel = BroadcastChannel(Channel.BUFFERED) override val contentCreatedFlow: Flow = contentCreatedBroadcastChannel.asFlow() override val contentDeletedFlow: Flow = contentDeletedBroadcastChannel.asFlow() diff --git a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsAPI.kt b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepo.kt similarity index 94% rename from postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsAPI.kt rename to postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepo.kt index 29931928..8377ec00 100644 --- a/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsAPI.kt +++ b/postssystem.core.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepo.kt @@ -2,11 +2,12 @@ package com.insanusmokrassar.postssystem.core.exposed import com.insanusmokrassar.postssystem.core.content.ContentId import com.insanusmokrassar.postssystem.core.post.* -import com.insanusmokrassar.postssystem.core.post.api.PostsAPI +import com.insanusmokrassar.postssystem.core.post.repo.PostsRepo import com.insanusmokrassar.postssystem.core.utils.generatePostId import com.insanusmokrassar.postssystem.core.utils.pagination.* import com.soywiz.klock.* import kotlinx.coroutines.channels.BroadcastChannel +import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.asFlow import org.jetbrains.exposed.sql.* @@ -58,9 +59,9 @@ private class PostsAPIContentRelations( private val dateTimeFormat = DateFormat("EEE, dd MMM yyyy HH:mm:ss z") -private class PostsAPIDatabaseTable( +private class PostsRepoDatabaseTable( private val database: Database -) : PostsAPI, Table() { +) : PostsRepo, Table() { private val contentsTable = PostsAPIContentRelations(database) private val idColumn = text("postId") @@ -69,18 +70,18 @@ private class PostsAPIDatabaseTable( ) - private val postCreatedBroadcastChannel = BroadcastChannel(ChannelDefaultSize) + private val postCreatedBroadcastChannel = BroadcastChannel(Channel.BUFFERED) override val postCreatedFlow: Flow = postCreatedBroadcastChannel.asFlow() - private val postDeletedBroadcastChannel = BroadcastChannel(ChannelDefaultSize) + private val postDeletedBroadcastChannel = BroadcastChannel(Channel.BUFFERED) override val postDeletedFlow: Flow = postDeletedBroadcastChannel.asFlow() - private val postUpdatedBroadcastChannel = BroadcastChannel(ChannelDefaultSize) + private val postUpdatedBroadcastChannel = BroadcastChannel(Channel.BUFFERED) override val postUpdatedFlow: Flow = postUpdatedBroadcastChannel.asFlow() init { transaction(database) { - SchemaUtils.createMissingTablesAndColumns(this@PostsAPIDatabaseTable) + SchemaUtils.createMissingTablesAndColumns(this@PostsRepoDatabaseTable) } } @@ -170,6 +171,6 @@ private class PostsAPIDatabaseTable( } -class ExposedPostsAPI ( +class ExposedPostsRepo ( database: Database -) : PostsAPI by PostsAPIDatabaseTable(database) +) : PostsRepo by PostsRepoDatabaseTable(database) diff --git a/postssystem.core.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsAPICommonTests.kt b/postssystem.core.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepoCommonTests.kt similarity index 94% rename from postssystem.core.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsAPICommonTests.kt rename to postssystem.core.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepoCommonTests.kt index b9c884fb..4765e576 100644 --- a/postssystem.core.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsAPICommonTests.kt +++ b/postssystem.core.exposed/src/test/kotlin/com/insanusmokrassar/postssystem/core/exposed/ExposedPostsRepoCommonTests.kt @@ -8,12 +8,12 @@ import java.io.File import java.sql.Connection import kotlin.test.* -class ExposedPostsAPICommonTests { +class ExposedPostsRepoCommonTests { private val tempFolder = System.getProperty("java.io.tmpdir")!! private val numberOfDatabases = 8 private lateinit var databaseFiles: List - private lateinit var apis: List + private lateinit var apis: List @BeforeTest fun prepare() { @@ -24,7 +24,7 @@ class ExposedPostsAPICommonTests { val database = Database.connect("jdbc:sqlite:${it.absolutePath}").also { it.transactionManager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE } - ExposedPostsAPI( + ExposedPostsRepo( database ) } diff --git a/postssystem.core.publishing.exposed/build.gradle b/postssystem.core.publishing.exposed/build.gradle new file mode 100644 index 00000000..27294b27 --- /dev/null +++ b/postssystem.core.publishing.exposed/build.gradle @@ -0,0 +1,47 @@ +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" +apply from: "./publish.gradle" + +repositories { + mavenLocal() + jcenter() + mavenCentral() + maven { url "https://kotlin.bintray.com/kotlinx" } +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + + if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") { + api "com.insanusmokrassar:postssystem.core.publishing:$core_version" + api "com.insanusmokrassar:postssystem.exposed.commons:$core_version" + } else { + api project(":postssystem.core.publishing") + api project(":postssystem.exposed.commons") + } + + testImplementation "org.xerial:sqlite-jdbc:$test_sqlite_version" + testImplementation "org.jetbrains.kotlin:kotlin-test" + testImplementation "org.jetbrains.kotlin:kotlin-test-junit" +} diff --git a/postssystem.core.publishing.exposed/gradle.properties b/postssystem.core.publishing.exposed/gradle.properties new file mode 100644 index 00000000..1576438d --- /dev/null +++ b/postssystem.core.publishing.exposed/gradle.properties @@ -0,0 +1,2 @@ +exposed_version=0.23.1 +test_sqlite_version=3.28.0 diff --git a/postssystem.core.publishing.exposed/maven.publish.gradle b/postssystem.core.publishing.exposed/maven.publish.gradle new file mode 100644 index 00000000..09a3d849 --- /dev/null +++ b/postssystem.core.publishing.exposed/maven.publish.gradle @@ -0,0 +1,53 @@ +apply plugin: 'maven-publish' + +task javadocsJar(type: Jar) { + classifier = 'javadoc' +} + +afterEvaluate { + project.publishing.publications.all { + // rename artifacts + groupId "${project.group}" + if (it.name.contains('kotlinMultiplatform')) { + artifactId = "${project.name}" + } else { + artifactId = "${project.name}-$name" + } + } +} + +publishing { + publications.all { + artifact javadocsJar + + pom { + description = "Exposed realisation for PostsSystem Core Publishing subsystem" + name = "PostsSystem Core Publishing Exposed realization" + url = "https://git.insanusmokrassar.com/PostsSystem/Core/" + + scm { + developerConnection = "scm:git:[fetch=]https://git.insanusmokrassar.com/PostsSystem/Core/.git[push=]https://git.insanusmokrassar.com/PostsSystem/Core/.git" + url = "https://git.insanusmokrassar.com/PostsSystem/Core/.git" + } + + developers { + + developer { + id = "InsanusMokrassar" + name = "Ovsiannikov Aleksei" + email = "ovsyannikov.alexey95@gmail.com" + } + + } + + licenses { + + license { + name = "Apache Software License 2.0" + url = "https://git.insanusmokrassar.com/PostsSystem/Core/src/master/LICENSE" + } + + } + } + } +} \ No newline at end of file diff --git a/postssystem.core.publishing.exposed/publish.gradle b/postssystem.core.publishing.exposed/publish.gradle new file mode 100644 index 00000000..b8cf4528 --- /dev/null +++ b/postssystem.core.publishing.exposed/publish.gradle @@ -0,0 +1,55 @@ +apply plugin: 'com.jfrog.bintray' + +apply from: "maven.publish.gradle" + +bintray { + user = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER') + key = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY') + filesSpec { + from "${buildDir}/publications/" + eachFile { + String directorySubname = it.getFile().parentFile.name + if (it.getName() == "module.json") { + if (directorySubname == "kotlinMultiplatform") { + it.setPath("${project.name}/${project.version}/${project.name}-${project.version}.module") + } else { + it.setPath("${project.name}-${directorySubname}/${project.version}/${project.name}-${directorySubname}-${project.version}.module") + } + } else { + if (directorySubname == "kotlinMultiplatform" && it.getName() == "pom-default.xml") { + it.setPath("${project.name}/${project.version}/${project.name}-${project.version}.pom") + } else { + it.exclude() + } + } + } + into "${project.group}".replace(".", "/") + } + pkg { + repo = "InsanusMokrassar" + name = "${project.name}" + vcsUrl = "https://github.com/PostsSystem/PostsSystemCore" + licenses = ["Apache-2.0"] + version { + name = "${project.version}" + released = new Date() + vcsTag = "${project.version}" + gpg { + sign = true + passphrase = project.hasProperty('signing.gnupg.passphrase') ? project.property('signing.gnupg.passphrase') : System.getenv('signing.gnupg.passphrase') + } + } + } +} + +bintrayUpload.doFirst { + publications = publishing.publications.collect { + if (it.name.contains('kotlinMultiplatform')) { + null + } else { + it.name + } + } - null +} + +bintrayUpload.dependsOn publishToMavenLocal \ No newline at end of file diff --git a/postssystem.core.publishing.exposed/publish_config.kpsb b/postssystem.core.publishing.exposed/publish_config.kpsb new file mode 100644 index 00000000..5443906e --- /dev/null +++ b/postssystem.core.publishing.exposed/publish_config.kpsb @@ -0,0 +1 @@ +{"bintrayConfig":{"repo":"InsanusMokrassar","packageName":"${project.name}","packageVcs":"https://github.com/PostsSystem/PostsSystemCore"},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://git.insanusmokrassar.com/PostsSystem/Core/src/master/LICENSE"}],"mavenConfig":{"name":"PostsSystem Core Publishing Exposed realization","description":"Exposed realisation for PostsSystem Core Publishing subsystem","url":"https://git.insanusmokrassar.com/PostsSystem/Core/","vcsUrl":"https://git.insanusmokrassar.com/PostsSystem/Core/.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"Multiplatform"} \ No newline at end of file diff --git a/postssystem.core.publishing.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/exposed/ExposedPublishingKeysRepo.kt b/postssystem.core.publishing.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/exposed/ExposedPublishingKeysRepo.kt new file mode 100644 index 00000000..57de6726 --- /dev/null +++ b/postssystem.core.publishing.exposed/src/main/kotlin/com/insanusmokrassar/postssystem/core/publishing/exposed/ExposedPublishingKeysRepo.kt @@ -0,0 +1,56 @@ +package com.insanusmokrassar.postssystem.core.publishing.exposed + +import com.insanusmokrassar.postssystem.core.post.PostId +import com.insanusmokrassar.postssystem.core.publishing.TriggerControlKey +import com.insanusmokrassar.postssystem.core.publishing.repos.PublishingKeysRepo +import org.jetbrains.exposed.sql.* +import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction +import org.jetbrains.exposed.sql.transactions.transaction + +class ExposedPublishingKeysRepo( + private val database: Database +) : PublishingKeysRepo, Table() { + private val postIdColumn: Column = text("postId") + private val triggerControlKeyColumn: Column = text("triggerControlKey") + override val primaryKey: PrimaryKey = PrimaryKey(postIdColumn, triggerControlKeyColumn) + + init { + transaction(database) { + SchemaUtils.createMissingTablesAndColumns(this@ExposedPublishingKeysRepo) + } + } + + override suspend fun getPostIdByTriggerControlKey(key: TriggerControlKey): PostId? = newSuspendedTransaction( + db = database + ) { + select { triggerControlKeyColumn.eq(key) }.limit(1).firstOrNull() ?.getOrNull(postIdColumn) + } + + override suspend fun getTriggerControlKeyByPostId(postId: PostId): TriggerControlKey? = newSuspendedTransaction( + db = database + ) { + select { postIdColumn.eq(postId) }.limit(1).firstOrNull() ?.getOrNull(triggerControlKeyColumn) + } + + override suspend fun setPostTriggerControlKey(postId: PostId, key: TriggerControlKey): Boolean = newSuspendedTransaction( + db = database + ) { + unsetPostTriggerControlKey(postId) + insert { + it[postIdColumn] = postId + it[triggerControlKeyColumn] = triggerControlKeyColumn + }.getOrNull(postIdColumn) == postId + } + + override suspend fun unsetPostTriggerControlKey(postId: PostId): Boolean = newSuspendedTransaction( + db = database + ) { + deleteWhere { + postIdColumn.eq(postId) + } > 0 + } +} + +class DatabasePublishingKeysRepo( + database: Database +): PublishingKeysRepo by ExposedPublishingKeysRepo(database) diff --git a/postssystem.core.publishing/build.gradle b/postssystem.core.publishing/build.gradle index 2218c8be..803f9189 100644 --- a/postssystem.core.publishing/build.gradle +++ b/postssystem.core.publishing/build.gradle @@ -41,7 +41,7 @@ kotlin { if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") { api "com.insanusmokrassar:postssystem.core:$core_version" } else { - implementation project(":postssystem.core") + api project(":postssystem.core") } } } @@ -68,7 +68,8 @@ kotlin { } jsTest { dependencies { - implementation kotlin('test-junit-js') + implementation kotlin('test-js') + implementation kotlin('test-junit') } } } diff --git a/postssystem.core.publishing/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingTrigger.kt b/postssystem.core.publishing/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingTrigger.kt index 21e981a7..c5d04b8e 100644 --- a/postssystem.core.publishing/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingTrigger.kt +++ b/postssystem.core.publishing/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/PublishingTrigger.kt @@ -2,7 +2,7 @@ package com.insanusmokrassar.postssystem.core.publishing import com.insanusmokrassar.postssystem.core.post.PostId import com.insanusmokrassar.postssystem.core.post.RegisteredPost -import com.insanusmokrassar.postssystem.core.post.api.PostsAPI +import com.insanusmokrassar.postssystem.core.post.repo.PostsRepo import com.insanusmokrassar.postssystem.core.publishing.repos.PublishingKeysRepo import kotlinx.coroutines.channels.BroadcastChannel import kotlinx.coroutines.channels.Channel @@ -17,7 +17,7 @@ interface PublishingTrigger { } class BusinessPublishingTrigger( - private val postsAPI: PostsAPI, + private val postsRepo: PostsRepo, private val publishingKeysRepo: PublishingKeysRepo ) : PublishingTrigger { private val postingTriggeredChannel: BroadcastChannel = BroadcastChannel(Channel.BUFFERED) @@ -27,8 +27,8 @@ class BusinessPublishingTrigger( val postId = publishingKeysRepo.getPostIdByTriggerControlKey(triggerControlKey) ?: return null publishingKeysRepo.unsetPostTriggerControlKey(postId) - return postsAPI.getPostById(postId) ?.let { post -> - if (postsAPI.deletePost(postId)) { + return postsRepo.getPostById(postId) ?.let { post -> + if (postsRepo.deletePost(postId)) { postingTriggeredChannel.send(post) postId } else { diff --git a/postssystem.core.publishing/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/repos/PublishingKeysRepo.kt b/postssystem.core.publishing/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/repos/PublishingKeysRepo.kt index 02f340be..68d729de 100644 --- a/postssystem.core.publishing/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/repos/PublishingKeysRepo.kt +++ b/postssystem.core.publishing/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/publishing/repos/PublishingKeysRepo.kt @@ -19,7 +19,7 @@ interface WritePublishingKeysRepo { ): Boolean suspend fun unsetPostTriggerControlKey( postId: PostId - ) + ): Boolean } interface PublishingKeysRepo : ReadPublishingKeysRepo, WritePublishingKeysRepo diff --git a/postssystem.core/build.gradle b/postssystem.core/build.gradle index a0d67177..6f8071c1 100644 --- a/postssystem.core/build.gradle +++ b/postssystem.core/build.gradle @@ -71,7 +71,8 @@ kotlin { } jsTest { dependencies { - implementation kotlin('test-junit-js') + implementation kotlin('test-js') + implementation kotlin('test-junit') } } } diff --git a/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/content/Content.kt b/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/content/Content.kt index cdc12b04..e0dcde58 100644 --- a/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/content/Content.kt +++ b/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/content/Content.kt @@ -33,7 +33,7 @@ data class BinaryContent( /** * Content which is already registered in database. Using its [id] you can retrieve all known * [com.insanusmokrassar.postssystem.core.post.RegisteredPost]s by using - * [com.insanusmokrassar.postssystem.core.post.api.ReadPostsAPI.getPostsByContent] + * [com.insanusmokrassar.postssystem.core.post.repo.ReadPostsRepo.getPostsByContent] */ @Serializable data class RegisteredContent( diff --git a/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/BusinessPublishablePostsAPI.kt b/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/BusinessPublishablePostsRepo.kt similarity index 50% rename from postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/BusinessPublishablePostsAPI.kt rename to postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/BusinessPublishablePostsRepo.kt index 4876f2de..9d6d2073 100644 --- a/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/BusinessPublishablePostsAPI.kt +++ b/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/BusinessPublishablePostsRepo.kt @@ -1,21 +1,21 @@ package com.insanusmokrassar.postssystem.core.post -import com.insanusmokrassar.postssystem.core.post.api.PostsAPI +import com.insanusmokrassar.postssystem.core.post.repo.PostsRepo -class BusinessPublishablePostsAPI( +class BusinessPublishablePostsRepo( /** * Will be used for storing of unpublished data */ - private val repoPostsAPI: PostsAPI, + private val repoPostsRepo: PostsRepo, /** * Will be used to send information ab */ - private val publishedPostsAPI: PostsAPI -) : PostsAPI by repoPostsAPI { + private val publishedPostsRepo: PostsRepo +) : PostsRepo by repoPostsRepo { override suspend fun deletePost(id: PostId): Boolean { return getPostById(id) ?.let { post -> - publishedPostsAPI.createPost(post) - repoPostsAPI.deletePost(id) + publishedPostsRepo.createPost(post) + repoPostsRepo.deletePost(id) } ?: return false } } \ No newline at end of file diff --git a/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/Post.kt b/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/Post.kt index 227a1759..4b0c68d2 100644 --- a/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/Post.kt +++ b/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/Post.kt @@ -14,8 +14,8 @@ interface Post { } /** - * Root entity of whole system. Can be retrieved from [com.insanusmokrassar.postssystem.core.post.api.ReadPostsAPI] by - * getting and created in [com.insanusmokrassar.postssystem.core.post.api.WritePostsAPI] by inserting of [Post] instance + * Root entity of whole system. Can be retrieved from [com.insanusmokrassar.postssystem.core.post.repo.ReadPostsRepo] by + * getting and created in [com.insanusmokrassar.postssystem.core.post.repo.WritePostsRepo] by inserting of [Post] instance */ interface RegisteredPost : Post { val id: PostId diff --git a/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/api/PostsAPI.kt b/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/api/PostsAPI.kt deleted file mode 100644 index a3fdceea..00000000 --- a/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/api/PostsAPI.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.insanusmokrassar.postssystem.core.post.api - -interface PostsAPI : ReadPostsAPI, WritePostsAPI diff --git a/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/repo/PostsRepo.kt b/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/repo/PostsRepo.kt new file mode 100644 index 00000000..9d663574 --- /dev/null +++ b/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/repo/PostsRepo.kt @@ -0,0 +1,3 @@ +package com.insanusmokrassar.postssystem.core.post.repo + +interface PostsRepo : ReadPostsRepo, WritePostsRepo diff --git a/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/api/ReadPostsAPI.kt b/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/repo/ReadPostsRepo.kt similarity index 92% rename from postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/api/ReadPostsAPI.kt rename to postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/repo/ReadPostsRepo.kt index 9e566c83..b9989cd3 100644 --- a/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/api/ReadPostsAPI.kt +++ b/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/repo/ReadPostsRepo.kt @@ -1,4 +1,4 @@ -package com.insanusmokrassar.postssystem.core.post.api +package com.insanusmokrassar.postssystem.core.post.repo import com.insanusmokrassar.postssystem.core.content.ContentId import com.insanusmokrassar.postssystem.core.post.PostId @@ -12,7 +12,7 @@ import com.soywiz.klock.DateTime /** * Simple read API by different properties */ -interface ReadPostsAPI { +interface ReadPostsRepo { /** * @return [Set] of [PostId]s which can be used to get data using [getPostById] */ @@ -39,7 +39,7 @@ interface ReadPostsAPI { suspend fun getPostsByPagination(pagination: Pagination): PaginationResult } -suspend fun ReadPostsAPI.getPostsByCreatingDates( +suspend fun ReadPostsRepo.getPostsByCreatingDates( from: DateTime? = null, to: DateTime? = null ) = getPostsByCreatingDates( diff --git a/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/api/WritePostsAPI.kt b/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/repo/WritePostsRepo.kt similarity index 88% rename from postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/api/WritePostsAPI.kt rename to postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/repo/WritePostsRepo.kt index 4d8c0b87..bf24cb64 100644 --- a/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/api/WritePostsAPI.kt +++ b/postssystem.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/post/repo/WritePostsRepo.kt @@ -1,9 +1,9 @@ -package com.insanusmokrassar.postssystem.core.post.api +package com.insanusmokrassar.postssystem.core.post.repo import com.insanusmokrassar.postssystem.core.post.* import kotlinx.coroutines.flow.Flow -interface WritePostsAPI { +interface WritePostsRepo { val postCreatedFlow: Flow val postDeletedFlow: Flow val postUpdatedFlow: Flow diff --git a/postssystem.exposed.commons/build.gradle b/postssystem.exposed.commons/build.gradle new file mode 100644 index 00000000..1985ad13 --- /dev/null +++ b/postssystem.exposed.commons/build.gradle @@ -0,0 +1,47 @@ +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" +apply from: "./publish.gradle" + +repositories { + mavenLocal() + jcenter() + mavenCentral() + maven { url "https://kotlin.bintray.com/kotlinx" } +} + +dependencies { + api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + api "org.jetbrains.exposed:exposed-core:$exposed_version" + api "org.jetbrains.exposed:exposed-jdbc:$exposed_version" + + if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") { + api "com.insanusmokrassar:postssystem.core:$core_version" + } else { + api project(":postssystem.core") + } + + testImplementation "org.xerial:sqlite-jdbc:$test_sqlite_version" + testImplementation "org.jetbrains.kotlin:kotlin-test" + testImplementation "org.jetbrains.kotlin:kotlin-test-junit" +} diff --git a/postssystem.exposed.commons/gradle.properties b/postssystem.exposed.commons/gradle.properties new file mode 100644 index 00000000..1576438d --- /dev/null +++ b/postssystem.exposed.commons/gradle.properties @@ -0,0 +1,2 @@ +exposed_version=0.23.1 +test_sqlite_version=3.28.0 diff --git a/postssystem.exposed.commons/maven.publish.gradle b/postssystem.exposed.commons/maven.publish.gradle new file mode 100644 index 00000000..50ee129b --- /dev/null +++ b/postssystem.exposed.commons/maven.publish.gradle @@ -0,0 +1,53 @@ +apply plugin: 'maven-publish' + +task javadocsJar(type: Jar) { + classifier = 'javadoc' +} + +afterEvaluate { + project.publishing.publications.all { + // rename artifacts + groupId "${project.group}" + if (it.name.contains('kotlinMultiplatform')) { + artifactId = "${project.name}" + } else { + artifactId = "${project.name}-$name" + } + } +} + +publishing { + publications.all { + artifact javadocsJar + + pom { + description = "Common utils for all exposed modules" + name = "PostsSystem Exposed commons" + url = "https://git.insanusmokrassar.com/PostsSystem/Core/" + + scm { + developerConnection = "scm:git:[fetch=]https://git.insanusmokrassar.com/PostsSystem/Core/.git[push=]https://git.insanusmokrassar.com/PostsSystem/Core/.git" + url = "https://git.insanusmokrassar.com/PostsSystem/Core/.git" + } + + developers { + + developer { + id = "InsanusMokrassar" + name = "Ovsiannikov Aleksei" + email = "ovsyannikov.alexey95@gmail.com" + } + + } + + licenses { + + license { + name = "Apache Software License 2.0" + url = "https://git.insanusmokrassar.com/PostsSystem/Core/src/master/LICENSE" + } + + } + } + } +} \ No newline at end of file diff --git a/postssystem.exposed.commons/publish.gradle b/postssystem.exposed.commons/publish.gradle new file mode 100644 index 00000000..b8cf4528 --- /dev/null +++ b/postssystem.exposed.commons/publish.gradle @@ -0,0 +1,55 @@ +apply plugin: 'com.jfrog.bintray' + +apply from: "maven.publish.gradle" + +bintray { + user = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER') + key = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY') + filesSpec { + from "${buildDir}/publications/" + eachFile { + String directorySubname = it.getFile().parentFile.name + if (it.getName() == "module.json") { + if (directorySubname == "kotlinMultiplatform") { + it.setPath("${project.name}/${project.version}/${project.name}-${project.version}.module") + } else { + it.setPath("${project.name}-${directorySubname}/${project.version}/${project.name}-${directorySubname}-${project.version}.module") + } + } else { + if (directorySubname == "kotlinMultiplatform" && it.getName() == "pom-default.xml") { + it.setPath("${project.name}/${project.version}/${project.name}-${project.version}.pom") + } else { + it.exclude() + } + } + } + into "${project.group}".replace(".", "/") + } + pkg { + repo = "InsanusMokrassar" + name = "${project.name}" + vcsUrl = "https://github.com/PostsSystem/PostsSystemCore" + licenses = ["Apache-2.0"] + version { + name = "${project.version}" + released = new Date() + vcsTag = "${project.version}" + gpg { + sign = true + passphrase = project.hasProperty('signing.gnupg.passphrase') ? project.property('signing.gnupg.passphrase') : System.getenv('signing.gnupg.passphrase') + } + } + } +} + +bintrayUpload.doFirst { + publications = publishing.publications.collect { + if (it.name.contains('kotlinMultiplatform')) { + null + } else { + it.name + } + } - null +} + +bintrayUpload.dependsOn publishToMavenLocal \ No newline at end of file diff --git a/postssystem.exposed.commons/publish_config.kpsb b/postssystem.exposed.commons/publish_config.kpsb new file mode 100644 index 00000000..2bd43e2b --- /dev/null +++ b/postssystem.exposed.commons/publish_config.kpsb @@ -0,0 +1 @@ +{"bintrayConfig":{"repo":"InsanusMokrassar","packageName":"${project.name}","packageVcs":"https://github.com/PostsSystem/PostsSystemCore"},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://git.insanusmokrassar.com/PostsSystem/Core/src/master/LICENSE"}],"mavenConfig":{"name":"PostsSystem Exposed commons","description":"Common utils for all exposed modules","url":"https://git.insanusmokrassar.com/PostsSystem/Core/","vcsUrl":"https://git.insanusmokrassar.com/PostsSystem/Core/.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"Multiplatform"} \ No newline at end of file diff --git a/postssystem.exposed.commons/src/main/kotlin/com/insanusmokrassar/postssystem/exposed/commons/QueryExtensions.kt b/postssystem.exposed.commons/src/main/kotlin/com/insanusmokrassar/postssystem/exposed/commons/QueryExtensions.kt new file mode 100644 index 00000000..2524305e --- /dev/null +++ b/postssystem.exposed.commons/src/main/kotlin/com/insanusmokrassar/postssystem/exposed/commons/QueryExtensions.kt @@ -0,0 +1,7 @@ +package com.insanusmokrassar.postssystem.exposed.commons + +import com.insanusmokrassar.postssystem.core.utils.pagination.Pagination +import com.insanusmokrassar.postssystem.core.utils.pagination.firstIndex +import org.jetbrains.exposed.sql.Query + +fun Query.paginate(pagination: Pagination) = limit(pagination.size, pagination.firstIndex.toLong()) diff --git a/settings.gradle b/settings.gradle index 94a1f2c0..4725db6e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,6 @@ rootProject.name='postssystem' +include ':postssystem.exposed.commons' include ':postssystem.core' include ':postssystem.core.exposed' include ':postssystem.core.publishing' +include ':postssystem.core.publishing.exposed'