add pagination and device id query
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:
@@ -7,6 +7,9 @@ import java.util.*
|
||||
interface ISampleObjectService{
|
||||
fun addOne(apiObject: 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 getSampleObjectbyDate(date: LocalDate): List<ApiObject>
|
||||
suspend fun getSampleObjectbeforeDate(date: LocalDate): List<ApiObject>
|
||||
|
||||
@@ -29,6 +29,20 @@ class SampleObjectService : ISampleObjectService {
|
||||
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 {
|
||||
SampleObjects.select {
|
||||
(SampleObjects.tag eq tag)
|
||||
|
||||
Reference in New Issue
Block a user