mq done, dao refactor, endpoints refactor
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
package com.kmalbz.database.dao
|
||||
|
||||
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.`java-time`.date
|
||||
import java.time.LocalDate
|
||||
|
||||
object ResultObjects : Table() {
|
||||
val id: Column<Int> = integer("id").autoIncrement()
|
||||
object ResultObjects : IntIdTable() {
|
||||
val tag: Column<String> = varchar("tag",32)
|
||||
val date: Column<LocalDate> = date("date")
|
||||
val decision: Column<Boolean> = bool("decision")
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.kmalbz.database.model
|
||||
|
||||
import java.time.LocalDate
|
||||
import com.kmalbz.database.dao.ResultObjects
|
||||
import org.jetbrains.exposed.dao.IntEntity
|
||||
import org.jetbrains.exposed.dao.IntEntityClass
|
||||
import org.jetbrains.exposed.dao.id.EntityID
|
||||
|
||||
data class ResultObject(
|
||||
val id: Int,
|
||||
val tag: String,
|
||||
val date: LocalDate,
|
||||
val decision: Boolean,
|
||||
val confidence: Double
|
||||
)
|
||||
class ResultObject(id: EntityID<Int>): IntEntity(id) {
|
||||
companion object : IntEntityClass<ResultObject>(ResultObjects)
|
||||
var tag by ResultObjects.tag
|
||||
var date by ResultObjects.tag
|
||||
var decision by ResultObjects.decision
|
||||
var confidence by ResultObjects.confidence
|
||||
}
|
||||
@@ -3,52 +3,64 @@ package com.kmalbz.database.service
|
||||
import com.kmalbz.database.DatabaseFactory.dbQuery
|
||||
import com.kmalbz.database.model.ResultObject
|
||||
import com.kmalbz.database.dao.ResultObjects
|
||||
import com.kmalbz.api.model.ApiObject
|
||||
import org.jetbrains.exposed.sql.ResultRow
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import java.time.LocalDate
|
||||
|
||||
|
||||
class ResultObjectService {
|
||||
|
||||
suspend fun getAllResultObjects(): List<ResultObject> = dbQuery {
|
||||
fun addOne(apiObject: ApiObject) {
|
||||
transaction {
|
||||
ResultObject.new {
|
||||
tag = apiObject.tag
|
||||
date = apiObject.date.toString()
|
||||
decision = apiObject.decision
|
||||
confidence = apiObject.confidence
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getAllResultObjects(): List<ApiObject> = dbQuery {
|
||||
ResultObjects.selectAll().map { toResultObject(it) }
|
||||
}
|
||||
|
||||
suspend fun getResultObjectbyTag(tag: String): ResultObject? = dbQuery {
|
||||
suspend fun getResultObjectbyTag(tag: String): ApiObject? = dbQuery {
|
||||
ResultObjects.select {
|
||||
(ResultObjects.tag eq tag)
|
||||
}.mapNotNull { toResultObject(it) }
|
||||
.singleOrNull()
|
||||
}
|
||||
|
||||
suspend fun getResultObjectbyDate(date: LocalDate): List<ResultObject>? = dbQuery {
|
||||
suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
||||
ResultObjects.select {
|
||||
(ResultObjects.date eq date)
|
||||
}.mapNotNull { toResultObject(it) }
|
||||
}
|
||||
|
||||
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ResultObject>? = dbQuery {
|
||||
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
||||
ResultObjects.select {
|
||||
(ResultObjects.date less date)
|
||||
}.mapNotNull { toResultObject(it) }
|
||||
}
|
||||
|
||||
suspend fun getResultObjectafterDate(date: LocalDate): List<ResultObject>? = dbQuery {
|
||||
suspend fun getResultObjectafterDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
||||
ResultObjects.select {
|
||||
(ResultObjects.date greater date)
|
||||
}.mapNotNull { toResultObject(it) }
|
||||
}
|
||||
|
||||
suspend fun getResultObjectbyDecision(decision: Boolean): List<ResultObject>? = dbQuery {
|
||||
suspend fun getResultObjectbyDecision(decision: Boolean): List<ApiObject>? = dbQuery {
|
||||
ResultObjects.select {
|
||||
(ResultObjects.decision eq decision)
|
||||
}.mapNotNull { toResultObject(it) }
|
||||
}
|
||||
|
||||
private fun toResultObject(row: ResultRow): ResultObject =
|
||||
ResultObject(
|
||||
id = row[ResultObjects.id],
|
||||
private fun toResultObject(row: ResultRow): ApiObject =
|
||||
ApiObject(
|
||||
tag = row[ResultObjects.tag],
|
||||
date = row[ResultObjects.date],
|
||||
decision = row[ResultObjects.decision],
|
||||
|
||||
Reference in New Issue
Block a user