use kotlin serialize

This commit is contained in:
2021-08-18 16:44:29 +02:00
parent f46386d465
commit 4fc8db6fa4
7 changed files with 45 additions and 43 deletions

View File

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

View File

@@ -6,11 +6,9 @@ import io.ktor.http.HttpStatusCode
import io.ktor.response.respond
import io.ktor.routing.Routing
import io.ktor.routing.get
import kotlinx.datetime.LocalDateTime
import org.koin.ktor.ext.inject
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import kotlin.math.ceil
import kotlin.math.roundToInt
/**
* Output Service - RDB
@@ -40,41 +38,39 @@ class OutputServiceRDBServer {
get("/output/filter/negative") {
val resultList =
resultObjectService.getResultObjecLessthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
resultObjectService.getResultObjecLessthanProbability(0.5)
call.respond(resultList)
}
get("/output/filter/positive") {
val resultList =
resultObjectService.getResultObjecGreaterthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
resultObjectService.getResultObjecGreaterthanProbability(0.5)
call.respond(resultList)
}
get("/output/filter/undecided") {
val resultList =
resultObjectService.getResultObjecEqualsProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
resultObjectService.getResultObjecEqualsProbability(0.5)
call.respond(resultList)
}
get("/output/after/{dateAfter}") {
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
val localDateAfter: LocalDate = LocalDate.parse(dateAfter, dateTimeFormatter)
val localDateAfter: LocalDateTime = LocalDateTime.parse(dateAfter)
val resultList =
resultObjectService.getResultObjectafterDate(localDateAfter) ?: call.respond(HttpStatusCode.NotFound)
resultObjectService.getResultObjectafterDate(localDateAfter)
call.respond(resultList)
}
get("/output/before/{dateBefore}") {
val dateAfter = call.parameters["dateBefore"] ?: error(HttpStatusCode.NotAcceptable)
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
val localDateBefore: LocalDate = LocalDate.parse(dateAfter, dateTimeFormatter)
val localDateBefore: LocalDateTime = LocalDateTime.parse(dateAfter)
val resultList =
resultObjectService.getResultObjectbeforeDate(localDateBefore) ?: call.respond(HttpStatusCode.NotFound)
resultObjectService.getResultObjectbeforeDate(localDateBefore)
call.respond(resultList)
}