start add standard repo utils
This commit is contained in:
parent
f31631c08f
commit
3baf6cc3c6
@ -3,8 +3,8 @@ package com.insanusmokrassar.postssystem.core.exposed
|
||||
import com.insanusmokrassar.postssystem.core.content.*
|
||||
import com.insanusmokrassar.postssystem.core.content.api.ContentRepo
|
||||
import com.insanusmokrassar.postssystem.core.exposed.content.*
|
||||
import com.insanusmokrassar.postssystem.core.utils.generateContentId
|
||||
import com.insanusmokrassar.postssystem.core.utils.pagination.*
|
||||
import com.insanusmokrassar.postssystem.core.generateContentId
|
||||
import com.insanusmokrassar.postssystem.utils.repos.pagination.*
|
||||
import com.insanusmokrassar.postssystem.exposed.commons.paginate
|
||||
import kotlinx.coroutines.channels.BroadcastChannel
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.insanusmokrassar.postssystem.core.exposed
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.content.ContentId
|
||||
import com.insanusmokrassar.postssystem.core.generatePostId
|
||||
import com.insanusmokrassar.postssystem.core.post.*
|
||||
import com.insanusmokrassar.postssystem.core.post.repo.PostsRepo
|
||||
import com.insanusmokrassar.postssystem.core.utils.generatePostId
|
||||
import com.insanusmokrassar.postssystem.core.utils.pagination.*
|
||||
import com.insanusmokrassar.postssystem.utils.repos.pagination.*
|
||||
import com.insanusmokrassar.postssystem.exposed.commons.paginate
|
||||
import com.soywiz.klock.*
|
||||
import kotlinx.coroutines.channels.BroadcastChannel
|
||||
|
@ -5,6 +5,7 @@ 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
|
||||
@ -14,7 +15,7 @@ class ExposedPublishingKeysRepo(
|
||||
override val primaryKey: PrimaryKey = PrimaryKey(postIdColumn, triggerControlKeyColumn)
|
||||
|
||||
init {
|
||||
newSuspendedTransaction(
|
||||
transaction(
|
||||
db = database
|
||||
) {
|
||||
SchemaUtils.createMissingTablesAndColumns(this@ExposedPublishingKeysRepo)
|
||||
|
@ -42,6 +42,12 @@ kotlin {
|
||||
|
||||
api "com.soywiz.korlibs.klock:klock:$klockVersion"
|
||||
api "com.benasher44:uuid:$uuidVersion"
|
||||
|
||||
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 project(":postssystem.utils.repos")
|
||||
}
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
|
@ -1,10 +1,8 @@
|
||||
package com.insanusmokrassar.postssystem.core.utils
|
||||
package com.insanusmokrassar.postssystem.core
|
||||
|
||||
import com.benasher44.uuid.uuid4
|
||||
import com.insanusmokrassar.postssystem.core.content.ContentId
|
||||
import com.insanusmokrassar.postssystem.core.post.PostId
|
||||
|
||||
fun generateId() = uuid4().toString()
|
||||
import com.insanusmokrassar.postssystem.utils.repos.generateId
|
||||
|
||||
fun generatePostId(): PostId = generateId()
|
||||
fun generateContentId(): ContentId = generateId()
|
@ -2,8 +2,8 @@ package com.insanusmokrassar.postssystem.core.content.api
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.content.ContentId
|
||||
import com.insanusmokrassar.postssystem.core.content.RegisteredContent
|
||||
import com.insanusmokrassar.postssystem.core.utils.pagination.Pagination
|
||||
import com.insanusmokrassar.postssystem.core.utils.pagination.PaginationResult
|
||||
import com.insanusmokrassar.postssystem.utils.repos.pagination.Pagination
|
||||
import com.insanusmokrassar.postssystem.utils.repos.pagination.PaginationResult
|
||||
|
||||
/**
|
||||
* Simple read API by different properties of [com.insanusmokrassar.postssystem.core.content.Content].
|
||||
|
@ -5,8 +5,8 @@ import com.insanusmokrassar.postssystem.core.post.PostId
|
||||
import com.insanusmokrassar.postssystem.core.post.RegisteredPost
|
||||
import com.insanusmokrassar.postssystem.core.utils.MAX_DATE
|
||||
import com.insanusmokrassar.postssystem.core.utils.MIN_DATE
|
||||
import com.insanusmokrassar.postssystem.core.utils.pagination.Pagination
|
||||
import com.insanusmokrassar.postssystem.core.utils.pagination.PaginationResult
|
||||
import com.insanusmokrassar.postssystem.utils.repos.pagination.Pagination
|
||||
import com.insanusmokrassar.postssystem.utils.repos.pagination.PaginationResult
|
||||
import com.soywiz.klock.DateTime
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.insanusmokrassar.postssystem.core.api
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.content.*
|
||||
import com.insanusmokrassar.postssystem.core.utils.generateContentId
|
||||
import com.insanusmokrassar.postssystem.core.generateContentId
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
@ -1,7 +1,22 @@
|
||||
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
|
||||
import com.insanusmokrassar.postssystem.utils.repos.pagination.*
|
||||
import org.jetbrains.exposed.sql.*
|
||||
|
||||
fun Query.paginate(pagination: Pagination) = limit(pagination.size, pagination.firstIndex.toLong())
|
||||
fun Query.paginate(with: Pagination, orderBy: Pair<Expression<*>, SortOrder>? = null) = limit(
|
||||
with.size,
|
||||
(if (orderBy ?.second == SortOrder.DESC) {
|
||||
with.lastIndex
|
||||
} else {
|
||||
with.firstIndex
|
||||
}).toLong()
|
||||
).let {
|
||||
if (orderBy != null) {
|
||||
it.orderBy(
|
||||
orderBy.first,
|
||||
orderBy.second
|
||||
)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
|
49
postssystem.utils.repos.exposed/build.gradle
Normal file
49
postssystem.utils.repos.exposed/build.gradle
Normal file
@ -0,0 +1,49 @@
|
||||
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.utils.repos:$core_version"
|
||||
api "com.insanusmokrassar:postssystem.exposed.commons:$core_version"
|
||||
} else {
|
||||
api project(":postssystem.utils.repos")
|
||||
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"
|
||||
}
|
2
postssystem.utils.repos.exposed/gradle.properties
Normal file
2
postssystem.utils.repos.exposed/gradle.properties
Normal file
@ -0,0 +1,2 @@
|
||||
exposed_version=0.23.1
|
||||
test_sqlite_version=3.28.0
|
53
postssystem.utils.repos.exposed/maven.publish.gradle
Normal file
53
postssystem.utils.repos.exposed/maven.publish.gradle
Normal file
@ -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"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
55
postssystem.utils.repos.exposed/publish.gradle
Normal file
55
postssystem.utils.repos.exposed/publish.gradle
Normal file
@ -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
|
1
postssystem.utils.repos.exposed/publish_config.kpsb
Normal file
1
postssystem.utils.repos.exposed/publish_config.kpsb
Normal file
@ -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"}
|
@ -0,0 +1,48 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos.exposed.keyvalue
|
||||
|
||||
import com.insanusmokrassar.postssystem.utils.repos.StandardKeyValueRepo
|
||||
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.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
abstract class AbstractExposedKeyValueRepo<Key, Value>(
|
||||
database: Database,
|
||||
keyColumn: Column<Key>,
|
||||
valueColumn: Column<Value>
|
||||
) : StandardKeyValueRepo<Key, Value>, AbstractExposedReadKeyValueRepo<Key, Value>(
|
||||
database,
|
||||
keyColumn,
|
||||
valueColumn
|
||||
) {
|
||||
private val onNewValueChannel = BroadcastChannel<Pair<Key, Value>>(Channel.BUFFERED)
|
||||
private val onValueRemovedChannel = BroadcastChannel<Key>(Channel.BUFFERED)
|
||||
|
||||
override val onNewValue: Flow<Pair<Key, Value>> = onNewValueChannel.asFlow()
|
||||
override val onValueRemoved: Flow<Key> = onValueRemovedChannel.asFlow()
|
||||
|
||||
override suspend fun set(k: Key, v: Value) {
|
||||
transaction(database) {
|
||||
if (select { keyColumn.eq(k) }.limit(1).any()) {
|
||||
update({ keyColumn.eq(k) }) {
|
||||
it[valueColumn] = v
|
||||
}
|
||||
} else {
|
||||
insert {
|
||||
it[keyColumn] = k
|
||||
it[valueColumn] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
onNewValueChannel.send(k to v)
|
||||
}
|
||||
|
||||
override suspend fun unset(k: Key) {
|
||||
transaction(database) {
|
||||
deleteWhere { keyColumn.eq(k) }
|
||||
}
|
||||
onValueRemovedChannel.send(k)
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos.exposed.keyvalue
|
||||
|
||||
import com.insanusmokrassar.postssystem.exposed.commons.paginate
|
||||
import com.insanusmokrassar.postssystem.utils.repos.StandardReadKeyValueRepo
|
||||
import com.insanusmokrassar.postssystem.utils.repos.pagination.*
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
abstract class AbstractExposedReadKeyValueRepo<Key, Value>(
|
||||
protected val database: Database,
|
||||
protected val keyColumn: Column<Key>,
|
||||
protected val valueColumn: Column<Value>
|
||||
) : StandardReadKeyValueRepo<Key, Value>, Table() {
|
||||
override val primaryKey: PrimaryKey = PrimaryKey(keyColumn, valueColumn)
|
||||
|
||||
override suspend fun get(k: Key): Value? = transaction(database) {
|
||||
select { keyColumn.eq(k) }.limit(1).firstOrNull() ?.getOrNull(valueColumn)
|
||||
}
|
||||
|
||||
override suspend fun contains(key: Key): Boolean = transaction(database) {
|
||||
select { keyColumn.eq(key) }.limit(1).any()
|
||||
}
|
||||
|
||||
override suspend fun count(): Long = transaction(database) { selectAll().count() }
|
||||
|
||||
override suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult<Key> = transaction(database) {
|
||||
selectAll().paginate(pagination, keyColumn to if (reversed) SortOrder.DESC else SortOrder.ASC).map {
|
||||
it[keyColumn]
|
||||
}
|
||||
}.createPaginationResult(pagination, count())
|
||||
|
||||
override suspend fun values(pagination: Pagination, reversed: Boolean): PaginationResult<Value> = transaction(database) {
|
||||
selectAll().paginate(pagination, keyColumn to if (reversed) SortOrder.DESC else SortOrder.ASC).map {
|
||||
it[valueColumn]
|
||||
}
|
||||
}.createPaginationResult(pagination, count())
|
||||
}
|
79
postssystem.utils.repos/build.gradle
Normal file
79
postssystem.utils.repos/build.gradle
Normal file
@ -0,0 +1,79 @@
|
||||
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')
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlin_coroutines_version"
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version"
|
||||
|
||||
api "com.soywiz.korlibs.klock:klock:$klockVersion"
|
||||
api "com.benasher44:uuid:$uuidVersion"
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-common')
|
||||
implementation kotlin('test-annotations-common')
|
||||
}
|
||||
}
|
||||
jvmMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib-jdk8')
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version"
|
||||
}
|
||||
}
|
||||
jvmTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
jsMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib-js')
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$kotlin_coroutines_version"
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$kotlin_serialisation_runtime_version"
|
||||
}
|
||||
}
|
||||
jsTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-js')
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
postssystem.utils.repos/maven.publish.gradle
Normal file
60
postssystem.utils.repos/maven.publish.gradle
Normal file
@ -0,0 +1,60 @@
|
||||
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 = "PostsSystem Core Repos utility subproject"
|
||||
name = "PostsSystem Core Repos"
|
||||
url = "https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore"
|
||||
|
||||
scm {
|
||||
developerConnection = "scm:git:[fetch=]https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore.git[push=]https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore.git"
|
||||
url = "https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore.git"
|
||||
}
|
||||
|
||||
developers {
|
||||
|
||||
developer {
|
||||
id = "InsanusMokrassar"
|
||||
name = "Ovsiannikov Aleksei"
|
||||
email = "ovsyannikov.alexey95@gmail.com"
|
||||
}
|
||||
|
||||
|
||||
developer {
|
||||
id = "mi-ast"
|
||||
name = "Michail Astafiev"
|
||||
email = "astaf65@gmail.com"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
licenses {
|
||||
|
||||
license {
|
||||
name = "Apache Software License 2.0"
|
||||
url = "https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore/src/master/LICENSE"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
55
postssystem.utils.repos/publish.gradle
Normal file
55
postssystem.utils.repos/publish.gradle
Normal file
@ -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
|
1
postssystem.utils.repos/publish_config.kpsb
Normal file
1
postssystem.utils.repos/publish_config.kpsb
Normal file
@ -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/PostsSystemCore/src/master/LICENSE"}],"mavenConfig":{"name":"PostsSystem Core Repos","description":"PostsSystem Core Repos utility subproject","url":"https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore","vcsUrl":"https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"},{"id":"mi-ast","name":"Michail Astafiev","eMail":"astaf65@gmail.com"}]},"type":"Multiplatform"}
|
@ -0,0 +1,5 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos
|
||||
|
||||
import com.benasher44.uuid.uuid4
|
||||
|
||||
fun generateId() = uuid4().toString()
|
@ -0,0 +1,23 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos
|
||||
|
||||
import com.insanusmokrassar.postssystem.utils.repos.pagination.Pagination
|
||||
import com.insanusmokrassar.postssystem.utils.repos.pagination.PaginationResult
|
||||
|
||||
interface OneToManyReadKeyValueRepo<Key, Value> : Repo {
|
||||
suspend fun get(k: Key, pagination: Pagination, reversed: Boolean = false): PaginationResult<Value>
|
||||
suspend fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
|
||||
suspend fun contains(k: Key): Boolean
|
||||
suspend fun contains(k: Key, v: Value): Boolean
|
||||
suspend fun count(k: Key): Long
|
||||
suspend fun count(): Long
|
||||
}
|
||||
|
||||
interface OneToManyWriteKeyValueRepo<Key, Value> :
|
||||
Repo {
|
||||
suspend fun add(k: Key, v: Value)
|
||||
suspend fun remove(k: Key, v: Value)
|
||||
suspend fun clear(k: Key)
|
||||
}
|
||||
|
||||
interface OneToManyKeyValueRepo<Key, Value> : OneToManyReadKeyValueRepo<Key, Value>,
|
||||
OneToManyWriteKeyValueRepo<Key, Value>
|
@ -0,0 +1,4 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos
|
||||
|
||||
interface Repo {
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos
|
||||
|
||||
import com.insanusmokrassar.postssystem.utils.repos.pagination.Pagination
|
||||
import com.insanusmokrassar.postssystem.utils.repos.pagination.PaginationResult
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface ReadStandardCRUDRepo<ObjectType, IdType> :
|
||||
Repo {
|
||||
suspend fun getByPagination(pagination: Pagination): PaginationResult<ObjectType>
|
||||
suspend fun getById(id: IdType): ObjectType?
|
||||
suspend fun contains(id: IdType): Boolean
|
||||
}
|
||||
|
||||
typealias UpdatedValuePair<IdType, ValueType> = Pair<IdType, ValueType>
|
||||
val <IdType> UpdatedValuePair<IdType, *>.id
|
||||
get() = first
|
||||
val <ValueType> UpdatedValuePair<*, ValueType>.value
|
||||
get() = second
|
||||
|
||||
interface WriteStandardCRUDRepo<ObjectType, IdType, InputValueType> :
|
||||
Repo {
|
||||
val newObjectsFlow: Flow<ObjectType>
|
||||
val updatedObjectsFlow: Flow<ObjectType>
|
||||
val deletedObjectsIdsFlow: Flow<IdType>
|
||||
|
||||
suspend fun create(vararg values: InputValueType): List<ObjectType>
|
||||
suspend fun update(id: IdType, value: InputValueType): ObjectType?
|
||||
suspend fun update(vararg values: UpdatedValuePair<IdType, InputValueType>): List<ObjectType>
|
||||
suspend fun deleteById(vararg ids: IdType)
|
||||
}
|
||||
|
||||
interface StandardCRUDRepo<ObjectType, IdType, InputValueType>
|
||||
: ReadStandardCRUDRepo<ObjectType, IdType>,
|
||||
WriteStandardCRUDRepo<ObjectType, IdType, InputValueType>
|
@ -0,0 +1,24 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos
|
||||
|
||||
import com.insanusmokrassar.postssystem.utils.repos.pagination.Pagination
|
||||
import com.insanusmokrassar.postssystem.utils.repos.pagination.PaginationResult
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface StandardReadKeyValueRepo<Key, Value> : Repo {
|
||||
suspend fun get(k: Key): Value?
|
||||
suspend fun values(pagination: Pagination, reversed: Boolean): PaginationResult<Value>
|
||||
suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult<Key>
|
||||
suspend fun contains(key: Key): Boolean
|
||||
suspend fun count(): Long
|
||||
}
|
||||
|
||||
interface StandardWriteKeyValueRepo<Key, Value> : Repo {
|
||||
val onNewValue: Flow<Pair<Key, Value>>
|
||||
val onValueRemoved: Flow<Key>
|
||||
|
||||
suspend fun set(k: Key, v: Value)
|
||||
suspend fun unset(k: Key)
|
||||
}
|
||||
|
||||
interface StandardKeyValueRepo<Key, Value> : StandardReadKeyValueRepo<Key, Value>,
|
||||
StandardWriteKeyValueRepo<Key, Value>
|
@ -1,4 +1,4 @@
|
||||
package com.insanusmokrassar.postssystem.core.utils.pagination
|
||||
package com.insanusmokrassar.postssystem.utils.repos.pagination
|
||||
|
||||
import kotlin.math.ceil
|
||||
|
||||
@ -45,4 +45,8 @@ fun calculatePagesNumber(datasetSize: Long, pageSize: Int): Int {
|
||||
/**
|
||||
* Calculates pages count for given [datasetSize]
|
||||
*/
|
||||
fun calculatePagesNumber(datasetSize: Int, pageSize: Int): Int = calculatePagesNumber(datasetSize.toLong(), pageSize)
|
||||
fun calculatePagesNumber(datasetSize: Int, pageSize: Int): Int =
|
||||
calculatePagesNumber(
|
||||
datasetSize.toLong(),
|
||||
pageSize
|
||||
)
|
@ -1,4 +1,4 @@
|
||||
package com.insanusmokrassar.postssystem.core.utils.pagination
|
||||
package com.insanusmokrassar.postssystem.utils.repos.pagination
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.insanusmokrassar.postssystem.core.utils.pagination
|
||||
package com.insanusmokrassar.postssystem.utils.repos.pagination
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@ -8,16 +8,18 @@ const val defaultLargePageSize = 10
|
||||
const val defaultExtraLargePageSize = 15
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE", "FunctionName")
|
||||
inline fun FirstPagePagination(size: Int = defaultMediumPageSize) = SimplePagination(
|
||||
inline fun FirstPagePagination(size: Int = defaultMediumPageSize) =
|
||||
SimplePagination(
|
||||
page = 0,
|
||||
size = size
|
||||
)
|
||||
)
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun Pagination.nextPage() = SimplePagination(
|
||||
inline fun Pagination.nextPage() =
|
||||
SimplePagination(
|
||||
page + 1,
|
||||
size
|
||||
)
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class SimplePagination(
|
@ -1,5 +1,7 @@
|
||||
rootProject.name='postssystem'
|
||||
include ':postssystem.utils.repos'
|
||||
include ':postssystem.exposed.commons'
|
||||
include ':postssystem.utils.repos.exposed'
|
||||
include ':postssystem.core'
|
||||
include ':postssystem.core.exposed'
|
||||
include ':postssystem.core.publishing'
|
||||
|
Loading…
Reference in New Issue
Block a user