diff --git a/src/api/route/OutputServiceRDBServer.kt b/src/api/route/OutputServiceRDBServer.kt index f444a27..26080d7 100644 --- a/src/api/route/OutputServiceRDBServer.kt +++ b/src/api/route/OutputServiceRDBServer.kt @@ -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") { diff --git a/src/database/service/IResultObjectService.kt b/src/database/service/IResultObjectService.kt index 6dbedc8..5e05578 100644 --- a/src/database/service/IResultObjectService.kt +++ b/src/database/service/IResultObjectService.kt @@ -7,6 +7,7 @@ import java.util.* interface IResultObjectService{ fun addOne(apiObject: ApiObject) suspend fun getAllResultObjects(): List + suspend fun getPage(page: Long): List suspend fun getResultObjectbyTag(tag: String): ApiObject? suspend fun getResultObjectbyDate(date: LocalDate): List? suspend fun getResultObjectbeforeDate(date: LocalDate): List? diff --git a/src/database/service/ResultObjectService.kt b/src/database/service/ResultObjectService.kt index 06a1309..01c824c 100644 --- a/src/database/service/ResultObjectService.kt +++ b/src/database/service/ResultObjectService.kt @@ -27,6 +27,10 @@ class ResultObjectService : IResultObjectService { ResultObjects.selectAll().map { toResultObject(it) } } + override suspend fun getPage(page: Long): List = dbQuery { + ResultObjects.selectAll().limit(10,page*10).map { toResultObject(it) } + } + override suspend fun getResultObjectbyTag(tag: String): ApiObject? = dbQuery { ResultObjects.select { (ResultObjects.tag eq tag)