All checks were successful
continuous-integration/drone/push Build is passing
42 lines
1.3 KiB
Kotlin
42 lines
1.3 KiB
Kotlin
package com.kmalbz.database.service
|
|
|
|
import com.kmalbz.database.DatabaseFactory.dbQuery
|
|
import com.kmalbz.database.model.InputObject
|
|
import com.kmalbz.database.dao.InputObjects
|
|
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 InputObjectService : IInputObjectService {
|
|
|
|
override fun addOne(apiObject: ApiObject) {
|
|
transaction {
|
|
InputObject.new {
|
|
tag = apiObject.tag
|
|
device_id = apiObject.device_id
|
|
}
|
|
}
|
|
}
|
|
|
|
override suspend fun getAllInputObjects(): List<ApiObject> = dbQuery {
|
|
InputObjects.selectAll().map { toInputObject(it) }
|
|
}
|
|
|
|
override suspend fun getInputObjectbyTag(tag: String): ApiObject? = dbQuery {
|
|
InputObjects.select {
|
|
(InputObjects.tag eq tag)
|
|
}.mapNotNull { toInputObject(it) }
|
|
.singleOrNull()
|
|
}
|
|
|
|
private fun toInputObject(row: ResultRow): ApiObject =
|
|
ApiObject(
|
|
tag = row[InputObjects.tag],
|
|
date = row[InputObjects.date],
|
|
device_id = row[InputObjects.device_id]
|
|
)
|
|
} |