This commit is contained in:
57
src/database/service/ResultObjectService.kt
Normal file
57
src/database/service/ResultObjectService.kt
Normal file
@@ -0,0 +1,57 @@
|
||||
package com.kmalbz.database.service
|
||||
|
||||
import com.kmalbz.database.DatabaseFactory.dbQuery
|
||||
import com.kmalbz.database.model.ResultObject
|
||||
import com.kmalbz.database.dao.ResultObjects
|
||||
import org.jetbrains.exposed.sql.ResultRow
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import java.time.LocalDate
|
||||
|
||||
|
||||
class ResultObjectService {
|
||||
|
||||
suspend fun getAllResultObjects(): List<ResultObject> = dbQuery {
|
||||
ResultObjects.selectAll().map { toResultObject(it) }
|
||||
}
|
||||
|
||||
suspend fun getResultObjectbyTag(tag: String): ResultObject? = dbQuery {
|
||||
ResultObjects.select {
|
||||
(ResultObjects.tag eq tag)
|
||||
}.mapNotNull { toResultObject(it) }
|
||||
.singleOrNull()
|
||||
}
|
||||
|
||||
suspend fun getResultObjectbyDate(date: LocalDate): List<ResultObject>? = dbQuery {
|
||||
ResultObjects.select {
|
||||
(ResultObjects.date eq date)
|
||||
}.mapNotNull { toResultObject(it) }
|
||||
}
|
||||
|
||||
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ResultObject>? = dbQuery {
|
||||
ResultObjects.select {
|
||||
(ResultObjects.date less date)
|
||||
}.mapNotNull { toResultObject(it) }
|
||||
}
|
||||
|
||||
suspend fun getResultObjectafterDate(date: LocalDate): List<ResultObject>? = dbQuery {
|
||||
ResultObjects.select {
|
||||
(ResultObjects.date greater date)
|
||||
}.mapNotNull { toResultObject(it) }
|
||||
}
|
||||
|
||||
suspend fun getResultObjectbyDecision(decision: Boolean): List<ResultObject>? = dbQuery {
|
||||
ResultObjects.select {
|
||||
(ResultObjects.decision eq decision)
|
||||
}.mapNotNull { toResultObject(it) }
|
||||
}
|
||||
|
||||
private fun toResultObject(row: ResultRow): ResultObject =
|
||||
ResultObject(
|
||||
id = row[ResultObjects.id],
|
||||
tag = row[ResultObjects.tag],
|
||||
date = row[ResultObjects.date],
|
||||
decision = row[ResultObjects.decision],
|
||||
confidence = row[ResultObjects.confidence]
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user