Merge improvements #1

Merged
tormakris merged 5 commits from kotlin-hazi into master 2020-05-29 13:23:32 +02:00
5 changed files with 10 additions and 5 deletions
Showing only changes of commit 609a90adc2 - Show all commits

View File

@ -1,8 +1,9 @@
package com.kmalbz.api.model package com.kmalbz.api.model
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName
import java.util.*
data class ApiObject( data class ApiObject(
@SerializedName("tag") val tag: String, @SerializedName("tag") val tag: UUID,
@SerializedName("probability") val probability: Double @SerializedName("probability") val probability: Double
) )

View File

@ -9,6 +9,7 @@ import io.ktor.routing.get
import org.koin.ktor.ext.inject import org.koin.ktor.ext.inject
import java.time.LocalDate import java.time.LocalDate
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
import java.util.*
/** /**
* Output Service - RDB * Output Service - RDB
@ -63,7 +64,7 @@ class OutputServiceRDBServer {
get("/output/{tagID}") { get("/output/{tagID}") {
val tagID = call.parameters["tagID"] ?: error(HttpStatusCode.NotAcceptable) val tagID = call.parameters["tagID"] ?: error(HttpStatusCode.NotAcceptable)
val resultObject = resultObjectService.getResultObjectbyTag(tagID) ?: call.respond(HttpStatusCode.NotFound) val resultObject = resultObjectService.getResultObjectbyTag(UUID.fromString(tagID)) ?: call.respond(HttpStatusCode.NotFound)
call.respond(resultObject) call.respond(resultObject)
} }

View File

@ -4,9 +4,10 @@ import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.`java-time`.date import org.jetbrains.exposed.sql.`java-time`.date
import java.time.LocalDate import java.time.LocalDate
import java.util.*
object ResultObjects : IntIdTable() { object ResultObjects : IntIdTable() {
val tag: Column<String> = varchar("tag",32) val tag: Column<UUID> = uuid("tag")
val date: Column<LocalDate> = date("date").default(LocalDate.now()) val date: Column<LocalDate> = date("date").default(LocalDate.now())
val probability: Column<Double> = double("probability") val probability: Column<Double> = double("probability")
override val primaryKey = PrimaryKey(id, name = "PK_ResultObject_Id") override val primaryKey = PrimaryKey(id, name = "PK_ResultObject_Id")

View File

@ -2,11 +2,12 @@ package com.kmalbz.database.service
import com.kmalbz.api.model.ApiObject import com.kmalbz.api.model.ApiObject
import java.time.LocalDate import java.time.LocalDate
import java.util.*
interface IResultObjectService{ interface IResultObjectService{
fun addOne(apiObject: ApiObject) fun addOne(apiObject: ApiObject)
suspend fun getAllResultObjects(): List<ApiObject> suspend fun getAllResultObjects(): List<ApiObject>
suspend fun getResultObjectbyTag(tag: String): ApiObject? suspend fun getResultObjectbyTag(tag: UUID): ApiObject?
suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>? suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>?
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>? suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>?
suspend fun getResultObjectafterDate(date: LocalDate): List<ApiObject>? suspend fun getResultObjectafterDate(date: LocalDate): List<ApiObject>?

View File

@ -9,6 +9,7 @@ import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction
import java.time.LocalDate import java.time.LocalDate
import java.util.*
class ResultObjectService : IResultObjectService { class ResultObjectService : IResultObjectService {
@ -26,7 +27,7 @@ class ResultObjectService : IResultObjectService {
ResultObjects.selectAll().map { toResultObject(it) } ResultObjects.selectAll().map { toResultObject(it) }
} }
override suspend fun getResultObjectbyTag(tag: String): ApiObject? = dbQuery { override suspend fun getResultObjectbyTag(tag: UUID): ApiObject? = dbQuery {
ResultObjects.select { ResultObjects.select {
(ResultObjects.tag eq tag) (ResultObjects.tag eq tag)
}.mapNotNull { toResultObject(it) } }.mapNotNull { toResultObject(it) }