add pagination and device id query
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2021-08-17 16:16:37 +02:00
parent 430b4b756e
commit f2ab81e0f4
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
3 changed files with 33 additions and 0 deletions

View File

@ -25,6 +25,22 @@ class SampleServiceServer {
call.respond(sampleObjectService.getAllSampleObjects()) call.respond(sampleObjectService.getAllSampleObjects())
} }
get("/sample/count") {
call.respond(sampleObjectService.getCount())
}
get("/sample/page/{page}") {
val page = call.parameters["page"] ?: error(HttpStatusCode.NotAcceptable)
val pageNum = page.toLong()
call.respond(sampleObjectService.getPage(pageNum))
}
get("/sample/device/{device_id}") {
val deviceId = call.parameters["device_id"] ?: error(HttpStatusCode.NotAcceptable)
val deviceIdNum = deviceId.toInt()
call.respond(sampleObjectService.getSampleObjectbyDeviceID(deviceIdNum))
}
get("/sample/after/{dateAfter}") { get("/sample/after/{dateAfter}") {
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable) val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE

View File

@ -7,6 +7,9 @@ import java.util.*
interface ISampleObjectService{ interface ISampleObjectService{
fun addOne(apiObject: ApiObject) fun addOne(apiObject: ApiObject)
suspend fun getAllSampleObjects(): List<ApiObject> suspend fun getAllSampleObjects(): List<ApiObject>
suspend fun getCount(): Long
suspend fun getPage(page: Long): List<ApiObject>
suspend fun getSampleObjectbyDeviceID(device_id: Int): List<ApiObject>
suspend fun getSampleObjectbyTag(tag: String): ApiObject? suspend fun getSampleObjectbyTag(tag: String): ApiObject?
suspend fun getSampleObjectbyDate(date: LocalDate): List<ApiObject> suspend fun getSampleObjectbyDate(date: LocalDate): List<ApiObject>
suspend fun getSampleObjectbeforeDate(date: LocalDate): List<ApiObject> suspend fun getSampleObjectbeforeDate(date: LocalDate): List<ApiObject>

View File

@ -29,6 +29,20 @@ class SampleObjectService : ISampleObjectService {
SampleObjects.selectAll().map { toSampleObject(it) } SampleObjects.selectAll().map { toSampleObject(it) }
} }
override suspend fun getCount(): Long = dbQuery {
SampleObjects.selectAll().count()
}
override suspend fun getPage(page: Long): List<ApiObject> = dbQuery {
SampleObjects.selectAll().limit(10, page * 10).map { toSampleObject(it) }
}
override suspend fun getSampleObjectbyDeviceID(device_id: Int): List<ApiObject> = dbQuery {
SampleObjects.select {
(SampleObjects.device_id eq device_id)
}.mapNotNull { toSampleObject(it) }
}
override suspend fun getSampleObjectbyTag(tag: String): ApiObject? = dbQuery { override suspend fun getSampleObjectbyTag(tag: String): ApiObject? = dbQuery {
SampleObjects.select { SampleObjects.select {
(SampleObjects.tag eq tag) (SampleObjects.tag eq tag)