updates
This commit is contained in:
@@ -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