pagination in db layer
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2021-08-17 15:57:58 +02:00
parent 5f2d88d3d2
commit 4f67c48f7a
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
3 changed files with 7 additions and 12 deletions

View File

@ -34,18 +34,8 @@ class OutputServiceRDBServer {
get("/output/page/{page}") {
val page = call.parameters["page"] ?: error(HttpStatusCode.NotAcceptable)
val pageNum = page.toInt()
val results = resultObjectService.getAllResultObjects()
val maxPageNum = ceil(results.size / 10.0).roundToInt() - 1
if (pageNum == 0) {
call.respond(results.subList(0, 10))
} else {
if (pageNum == maxPageNum) {
call.respond(results.subList((pageNum * 10) + 1, results.size))
} else {
call.respond(results.subList((pageNum * 10) + 1, (pageNum * 10) + 10))
}
}
val pageNum = page.toLong()
call.respond(resultObjectService.getPage(pageNum))
}
get("/output/filter/negative") {

View File

@ -7,6 +7,7 @@ import java.util.*
interface IResultObjectService{
fun addOne(apiObject: ApiObject)
suspend fun getAllResultObjects(): List<ApiObject>
suspend fun getPage(page: Long): List<ApiObject>
suspend fun getResultObjectbyTag(tag: String): ApiObject?
suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>?
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>?

View File

@ -27,6 +27,10 @@ class ResultObjectService : IResultObjectService {
ResultObjects.selectAll().map { toResultObject(it) }
}
override suspend fun getPage(page: Long): List<ApiObject> = dbQuery {
ResultObjects.selectAll().limit(10,page*10).map { toResultObject(it) }
}
override suspend fun getResultObjectbyTag(tag: String): ApiObject? = dbQuery {
ResultObjects.select {
(ResultObjects.tag eq tag)