updates
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
project.version = "0.2.0"
|
||||
project.version = "$core_version"
|
||||
project.group = "com.insanusmokrassar"
|
||||
|
||||
buildscript {
|
||||
@@ -30,10 +30,16 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
api "com.insanusmokrassar:postssystem.core:$core_version"
|
||||
api "org.jetbrains.exposed:exposed-core:$exposed_version"
|
||||
api "com.soywiz.korlibs.klock:klock:$klockVersion"
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
|
||||
testImplementation "org.xerial:sqlite-jdbc:$test_sqlite_version"
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:$test_junit_version"
|
||||
}
|
||||
|
@@ -1,5 +1,3 @@
|
||||
exposed_version=0.20.3
|
||||
exposed_version=0.23.1
|
||||
test_sqlite_version=3.30.1
|
||||
test_junit_version=5.5.2
|
||||
|
||||
core_version=0.2.0
|
||||
|
@@ -32,7 +32,7 @@ private class ContentAPIDatabaseTable(
|
||||
return transaction(database) {
|
||||
insert {
|
||||
it[idColumn] = generateContentId()
|
||||
it[dataColumn] = Json.plain.stringify(Content.serializer(), content)
|
||||
it[dataColumn] = Json.stringify(Content.serializer(), content)
|
||||
}.getOrNull(idColumn) ?.let { id ->
|
||||
RegisteredContent(
|
||||
id,
|
||||
@@ -58,7 +58,7 @@ private class ContentAPIDatabaseTable(
|
||||
|
||||
private fun ResultRow.asRegisteredContent(): RegisteredContent = RegisteredContent(
|
||||
get(idColumn),
|
||||
Json.plain.parse(Content.serializer(), get(dataColumn))
|
||||
Json.parse(Content.serializer(), get(dataColumn))
|
||||
)
|
||||
|
||||
override suspend fun getContentsIds(): Set<ContentId> {
|
||||
@@ -73,9 +73,12 @@ private class ContentAPIDatabaseTable(
|
||||
}
|
||||
override suspend fun getContentByPagination(pagination: Pagination): PaginationResult<out RegisteredContent> {
|
||||
return transaction(database) {
|
||||
selectAll().count() to selectAll().limit(n = pagination.size, offset = pagination.firstIndex).map { it.asRegisteredContent() }
|
||||
selectAll().count() to selectAll().paginate(pagination).map { it.asRegisteredContent() }
|
||||
}.let { (count, results) ->
|
||||
pagination.createResult(count, results)
|
||||
results.createPaginationResult(
|
||||
pagination,
|
||||
count
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -160,11 +160,11 @@ private class PostsAPIDatabaseTable(
|
||||
|
||||
override suspend fun getPostsByPagination(pagination: Pagination): PaginationResult<RegisteredPost> {
|
||||
return transaction(database) {
|
||||
val posts = selectAll().limit(pagination.size, pagination.firstIndex).orderBy(creationDateColumn).map {
|
||||
val posts = selectAll().paginate(pagination).orderBy(creationDateColumn).map {
|
||||
it.toRegisteredPost()
|
||||
}
|
||||
val postsNumber = selectAll().count()
|
||||
pagination.createResult(postsNumber, posts)
|
||||
posts.createPaginationResult(pagination, postsNumber)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,7 @@
|
||||
package com.insanusmokrassar.postssystem.core.exposed
|
||||
|
||||
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())
|
Reference in New Issue
Block a user