all routes wired together
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2020-04-05 11:14:02 +02:00
parent af4307c6a4
commit b5be06848e
9 changed files with 69 additions and 53 deletions

View File

@ -13,9 +13,12 @@ import io.ktor.auth.*
import kotlin.reflect.*
import java.util.*
import org.apache.http.HttpException
import com.kmalbz.database.DatabaseFactory
import io.ktor.util.KtorExperimentalAPI
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
@KtorExperimentalAPI
@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
@ -30,6 +33,8 @@ fun Application.module(testing: Boolean = false) {
install(Authentication) {
}
DatabaseFactory.init()
routing {
get("/") {
call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain)
@ -40,15 +45,15 @@ fun Application.module(testing: Boolean = false) {
}
install(StatusPages) {
exception<AuthenticationException> { cause ->
exception<AuthenticationException> { _ ->
call.respond(HttpStatusCode.Unauthorized)
}
exception<AuthorizationException> { cause ->
exception<AuthorizationException> { _ ->
call.respond(HttpStatusCode.Forbidden)
}
exception<HttpException> { cause ->
exception<HttpException> { _ ->
call.respond(HttpStatusCode.BadRequest)
}
}

View File

@ -1,14 +1,5 @@
package com.kmalbz
import java.util.*
data class OutputObject(
val tag: String,
val decison: Boolean,
val date: Date,
val confidence: Double
)
data class ApiResponse(
val status: String,
val message: String

View File

@ -3,6 +3,7 @@ package com.kmalbz
import io.ktor.client.*
import io.ktor.client.request.*
import java.util.*
import com.kmalbz.database.model.ResultObject
/**
* Output Service - RDB Client
@ -16,8 +17,8 @@ open class OutputServiceRDBClient(val endpoint: String, val client: HttpClient =
* @return Array of decision objects
*/
suspend fun getallnegative(
): List<OutputObject> {
return client.get<List<OutputObject>>("$endpoint/output/filter/negative") {
): List<ResultObject> {
return client.get<List<ResultObject>>("$endpoint/output/filter/negative") {
}
}
@ -27,8 +28,8 @@ open class OutputServiceRDBClient(val endpoint: String, val client: HttpClient =
* @return Array of decision objects
*/
suspend fun getallpositive(
): List<OutputObject> {
return client.get<List<OutputObject>>("$endpoint/output/filter/positive") {
): List<ResultObject> {
return client.get<List<ResultObject>>("$endpoint/output/filter/positive") {
}
}
@ -41,8 +42,8 @@ open class OutputServiceRDBClient(val endpoint: String, val client: HttpClient =
*/
suspend fun getallafter(
dateAfter: Date // PATH
): List<OutputObject> {
return client.get<List<OutputObject>>("$endpoint/output/after/$dateAfter") {
): List<ResultObject> {
return client.get<List<ResultObject>>("$endpoint/output/after/$dateAfter") {
}
}
@ -55,8 +56,8 @@ open class OutputServiceRDBClient(val endpoint: String, val client: HttpClient =
*/
suspend fun getallbefore(
dateBefore: Date // PATH
): List<OutputObject> {
return client.get<List<OutputObject>>("$endpoint/output/before/$dateBefore") {
): List<ResultObject> {
return client.get<List<ResultObject>>("$endpoint/output/before/$dateBefore") {
}
}
@ -69,8 +70,8 @@ open class OutputServiceRDBClient(val endpoint: String, val client: HttpClient =
*/
suspend fun getDecision(
tagID: Int // PATH
): OutputObject {
return client.get<OutputObject>("$endpoint/output/$tagID") {
): ResultObject {
return client.get<ResultObject>("$endpoint/output/$tagID") {
}
}
}

View File

@ -3,8 +3,10 @@ package com.kmalbz
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.routing.*
import java.util.*
import io.ktor.http.*
import com.kmalbz.database.service.ResultObjectService
import java.time.LocalDate
import java.time.format.DateTimeFormatter
/**
* Output Service - RDB
@ -15,46 +17,47 @@ class OutputServiceRDBServer() {
/**
* output
*/
private val resultObjectService = ResultObjectService()
fun Routing.registerOutput() {
get("/output/filter/negative") {
if (false) error(HttpStatusCode.NotFound)
get("/output"){
call.respond(resultObjectService.getAllResultObjects())
}
call.respond(listOf())
get("/output/filter/negative") {
val resultList = resultObjectService.getResultObjectbyDecision(false) ?: error(HttpStatusCode.NotFound)
call.respond(resultList)
}
get("/output/filter/positive") {
if (false) error(HttpStatusCode.NotFound)
val resultList = resultObjectService.getResultObjectbyDecision(true) ?: error(HttpStatusCode.NotFound)
call.respond(listOf())
call.respond(resultList)
}
get("/output/after/{dateAfter}") {
val dateAfter = call.parameters["dateAfter"]
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
val localDateAfter : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
val resultList = resultObjectService.getResultObjectbeforeDate(localDateAfter) ?: error(HttpStatusCode.NotFound)
if (false) error(HttpStatusCode.NotFound)
call.respond(listOf())
call.respond(resultList)
}
get("/output/before/{dateBefore}") {
val dateBefore = call.parameters["dateBefore"]
val dateAfter = call.parameters["dateBefore"] ?: error(HttpStatusCode.NotAcceptable)
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
val localDateBefore : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
val resultList = resultObjectService.getResultObjectafterDate(localDateBefore) ?: error(HttpStatusCode.NotFound)
if (false) error(HttpStatusCode.NotFound)
call.respond(listOf())
call.respond(resultList)
}
get("/output/{tagID}") {
val tagID = call.parameters["tagID"]
val tagID = call.parameters["tagID"] ?: error(HttpStatusCode.NotAcceptable)
val resultObject = resultObjectService.getResultObjectbyTag(tagID) ?: error(HttpStatusCode.NotFound)
if (false) error(HttpStatusCode.NotFound)
call.respond(OutputObject(
tag = "tag",
decison = false,
date = Date(),
confidence = 0.0
))
call.respond(resultObject)
}
}
}