From f46386d465572143ebe87bc432062c4218842420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Tue, 17 Aug 2021 16:09:10 +0200 Subject: [PATCH] get count from db layer as well --- src/api/route/OutputServiceRDBServer.kt | 2 +- src/database/service/IResultObjectService.kt | 1 + src/database/service/ResultObjectService.kt | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/api/route/OutputServiceRDBServer.kt b/src/api/route/OutputServiceRDBServer.kt index 26080d7..fae21a9 100644 --- a/src/api/route/OutputServiceRDBServer.kt +++ b/src/api/route/OutputServiceRDBServer.kt @@ -29,7 +29,7 @@ class OutputServiceRDBServer { } get("/output/count") { - call.respond(resultObjectService.getAllResultObjects().size) + call.respond(resultObjectService.getCount()) } get("/output/page/{page}") { diff --git a/src/database/service/IResultObjectService.kt b/src/database/service/IResultObjectService.kt index 5e05578..535ac09 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 getCount(): Long suspend fun getPage(page: Long): List suspend fun getResultObjectbyTag(tag: String): ApiObject? suspend fun getResultObjectbyDate(date: LocalDate): List? diff --git a/src/database/service/ResultObjectService.kt b/src/database/service/ResultObjectService.kt index 01c824c..97ede98 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 getCount(): Long = dbQuery { + ResultObjects.selectAll().count() + } + override suspend fun getPage(page: Long): List = dbQuery { ResultObjects.selectAll().limit(10,page*10).map { toResultObject(it) } }