pagination in db layer
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5f2d88d3d2
commit
4f67c48f7a
@ -34,18 +34,8 @@ class OutputServiceRDBServer {
|
|||||||
|
|
||||||
get("/output/page/{page}") {
|
get("/output/page/{page}") {
|
||||||
val page = call.parameters["page"] ?: error(HttpStatusCode.NotAcceptable)
|
val page = call.parameters["page"] ?: error(HttpStatusCode.NotAcceptable)
|
||||||
val pageNum = page.toInt()
|
val pageNum = page.toLong()
|
||||||
val results = resultObjectService.getAllResultObjects()
|
call.respond(resultObjectService.getPage(pageNum))
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/output/filter/negative") {
|
get("/output/filter/negative") {
|
||||||
|
@ -7,6 +7,7 @@ import java.util.*
|
|||||||
interface IResultObjectService{
|
interface IResultObjectService{
|
||||||
fun addOne(apiObject: ApiObject)
|
fun addOne(apiObject: ApiObject)
|
||||||
suspend fun getAllResultObjects(): List<ApiObject>
|
suspend fun getAllResultObjects(): List<ApiObject>
|
||||||
|
suspend fun getPage(page: Long): List<ApiObject>
|
||||||
suspend fun getResultObjectbyTag(tag: String): ApiObject?
|
suspend fun getResultObjectbyTag(tag: String): ApiObject?
|
||||||
suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>?
|
suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>?
|
||||||
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>?
|
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>?
|
||||||
|
@ -27,6 +27,10 @@ class ResultObjectService : IResultObjectService {
|
|||||||
ResultObjects.selectAll().map { toResultObject(it) }
|
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 {
|
override suspend fun getResultObjectbyTag(tag: String): ApiObject? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.tag eq tag)
|
(ResultObjects.tag eq tag)
|
||||||
|
Loading…
Reference in New Issue
Block a user