This commit is contained in:
parent
1f0f831742
commit
b16a5702b4
@ -6,7 +6,6 @@ import com.kmalbz.database.dao.SampleObjects
|
||||
import com.kmalbz.api.model.ApiObject
|
||||
import io.ktor.util.*
|
||||
import org.jetbrains.exposed.sql.ResultRow
|
||||
import org.jetbrains.exposed.sql.castTo
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
@ -27,35 +26,35 @@ class SampleObjectService : ISampleObjectService {
|
||||
}
|
||||
|
||||
override suspend fun getAllSampleObjects(): List<ApiObject> = dbQuery {
|
||||
SampleObjects.selectAll().map { toResultObject(it) }
|
||||
SampleObjects.selectAll().map { toSampleObject(it) }
|
||||
}
|
||||
|
||||
override suspend fun getSampleObjectbyTag(tag: String): ApiObject? = dbQuery {
|
||||
SampleObjects.select {
|
||||
(SampleObjects.tag eq tag)
|
||||
}.mapNotNull { toResultObject(it) }
|
||||
}.mapNotNull { toSampleObject(it) }
|
||||
.singleOrNull()
|
||||
}
|
||||
|
||||
override suspend fun getSampleObjectbyDate(date: LocalDate): List<ApiObject> = dbQuery {
|
||||
SampleObjects.select {
|
||||
(SampleObjects.timestamp eq date)
|
||||
}.mapNotNull { toResultObject(it) }
|
||||
}.mapNotNull { toSampleObject(it) }
|
||||
}
|
||||
|
||||
override suspend fun getSampleObjectbeforeDate(date: LocalDate): List<ApiObject> = dbQuery {
|
||||
SampleObjects.select {
|
||||
(SampleObjects.timestamp less date)
|
||||
}.mapNotNull { toResultObject(it) }
|
||||
}.mapNotNull { toSampleObject(it) }
|
||||
}
|
||||
|
||||
override suspend fun getSampleObjectafterDate(date: LocalDate): List<ApiObject> = dbQuery {
|
||||
SampleObjects.select {
|
||||
(SampleObjects.timestamp greater date)
|
||||
}.mapNotNull { toResultObject(it) }
|
||||
}.mapNotNull { toSampleObject(it) }
|
||||
}
|
||||
|
||||
private fun toResultObject(row: ResultRow): ApiObject =
|
||||
private fun toSampleObject(row: ResultRow): ApiObject =
|
||||
ApiObject(
|
||||
tag = row[SampleObjects.tag],
|
||||
device_date = row[SampleObjects.device_date],
|
||||
|
Loading…
Reference in New Issue
Block a user