This commit is contained in:
parent
9c432ae60d
commit
5f2d88d3d2
@ -9,6 +9,8 @@ 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 kotlin.math.ceil
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output Service - RDB
|
* Output Service - RDB
|
||||||
@ -19,26 +21,50 @@ class OutputServiceRDBServer {
|
|||||||
/**
|
/**
|
||||||
* output
|
* output
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fun Routing.registerOutput() {
|
fun Routing.registerOutput() {
|
||||||
val resultObjectService:IResultObjectService by inject()
|
val resultObjectService: IResultObjectService by inject()
|
||||||
get("/output"){
|
get("/output") {
|
||||||
call.respond(resultObjectService.getAllResultObjects())
|
call.respond(resultObjectService.getAllResultObjects())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get("/output/count") {
|
||||||
|
call.respond(resultObjectService.getAllResultObjects().size)
|
||||||
|
}
|
||||||
|
|
||||||
|
get("/output/page/{page}") {
|
||||||
|
val page = call.parameters["page"] ?: error(HttpStatusCode.NotAcceptable)
|
||||||
|
val pageNum = page.toInt()
|
||||||
|
val results = resultObjectService.getAllResultObjects()
|
||||||
|
val maxPageNum = ceil(results.size / 10.0).roundToInt() - 1
|
||||||
|
if (pageNum == 0) {
|
||||||
|
call.respond(results.subList(0, 10))
|
||||||
|
} else {
|
||||||
|
if (pageNum == maxPageNum) {
|
||||||
|
call.respond(results.subList((pageNum * 10) + 1, results.size))
|
||||||
|
} else {
|
||||||
|
call.respond(results.subList((pageNum * 10) + 1, (pageNum * 10) + 10))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get("/output/filter/negative") {
|
get("/output/filter/negative") {
|
||||||
val resultList = resultObjectService.getResultObjecLessthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
|
val resultList =
|
||||||
|
resultObjectService.getResultObjecLessthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/output/filter/positive") {
|
get("/output/filter/positive") {
|
||||||
val resultList = resultObjectService.getResultObjecGreaterthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
|
val resultList =
|
||||||
|
resultObjectService.getResultObjecGreaterthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/output/filter/undecided") {
|
get("/output/filter/undecided") {
|
||||||
val resultList = resultObjectService.getResultObjecEqualsProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
|
val resultList =
|
||||||
|
resultObjectService.getResultObjecEqualsProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
@ -46,8 +72,9 @@ class OutputServiceRDBServer {
|
|||||||
get("/output/after/{dateAfter}") {
|
get("/output/after/{dateAfter}") {
|
||||||
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
|
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
|
||||||
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
||||||
val localDateAfter : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
|
val localDateAfter: LocalDate = LocalDate.parse(dateAfter, dateTimeFormatter)
|
||||||
val resultList = resultObjectService.getResultObjectafterDate(localDateAfter) ?: call.respond(HttpStatusCode.NotFound)
|
val resultList =
|
||||||
|
resultObjectService.getResultObjectafterDate(localDateAfter) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
@ -55,8 +82,9 @@ class OutputServiceRDBServer {
|
|||||||
get("/output/before/{dateBefore}") {
|
get("/output/before/{dateBefore}") {
|
||||||
val dateAfter = call.parameters["dateBefore"] ?: error(HttpStatusCode.NotAcceptable)
|
val dateAfter = call.parameters["dateBefore"] ?: error(HttpStatusCode.NotAcceptable)
|
||||||
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
||||||
val localDateBefore : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
|
val localDateBefore: LocalDate = LocalDate.parse(dateAfter, dateTimeFormatter)
|
||||||
val resultList = resultObjectService.getResultObjectbeforeDate(localDateBefore) ?: call.respond(HttpStatusCode.NotFound)
|
val resultList =
|
||||||
|
resultObjectService.getResultObjectbeforeDate(localDateBefore) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user