api done
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2021-08-11 15:06:09 +02:00
parent 26acf2085c
commit b04ddf66c6
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
5 changed files with 19 additions and 59 deletions

View File

@ -14,6 +14,7 @@ steps:
- name: build_application
image: openjdk:11-jdk
commands:
- chmod +x gradlew
- ./gradlew build -x test
- name: kaniko

View File

@ -4,7 +4,6 @@ import com.google.gson.annotations.SerializedName
import java.time.LocalDate
data class ApiObject(
@SerializedName("id") val id: Int,
@SerializedName("tag") val tag: String,
@SerializedName("device_id") val device_id: Int,
@SerializedName("device_date") val device_date: LocalDate

View File

@ -11,39 +11,21 @@ import java.time.LocalDate
import java.time.format.DateTimeFormatter
/**
* Output Service - RDB
* Sample Service
*
* This is the output interface of the Birbnetes system.
* This is the sample interface of the Birbnetes system.
*/
class OutputServiceRDBServer {
/**
* output
* sample
*/
fun Routing.registerOutput() {
val resultObjectService by inject<ISampleObjectService>()
get("/output"){
get("/sample"){
call.respond(resultObjectService.getAllSampleObjects())
}
get("/output/filter/negative") {
val resultList = resultObjectService.getSampleObjecLessthanId(0.5) ?: call.respond(HttpStatusCode.NotFound)
call.respond(resultList)
}
get("/output/filter/positive") {
val resultList = resultObjectService.getSampleObjecGreaterthanId(0.5) ?: call.respond(HttpStatusCode.NotFound)
call.respond(resultList)
}
get("/output/filter/undecided") {
val resultList = resultObjectService.getSampleObjecEqualsId(0.5) ?: call.respond(HttpStatusCode.NotFound)
call.respond(resultList)
}
get("/output/after/{dateAfter}") {
get("/sample/after/{dateAfter}") {
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
val localDateAfter : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
@ -52,7 +34,7 @@ class OutputServiceRDBServer {
call.respond(resultList)
}
get("/output/before/{dateBefore}") {
get("/sample/before/{dateBefore}") {
val dateAfter = call.parameters["dateBefore"] ?: error(HttpStatusCode.NotAcceptable)
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
val localDateBefore : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
@ -61,7 +43,7 @@ class OutputServiceRDBServer {
call.respond(resultList)
}
get("/output/{tagID}") {
get("/sample/{tagID}") {
val tagID = call.parameters["tagID"] ?: error(HttpStatusCode.NotAcceptable)
val resultObject = resultObjectService.getSampleObjectbyTag(tagID) ?: call.respond(HttpStatusCode.NotFound)

View File

@ -8,10 +8,7 @@ interface ISampleObjectService{
fun addOne(apiObject: ApiObject)
suspend fun getAllSampleObjects(): List<ApiObject>
suspend fun getSampleObjectbyTag(tag: String): ApiObject?
suspend fun getSampleObjectbyDate(date: LocalDate): List<ApiObject>?
suspend fun getSampleObjectbeforeDate(date: LocalDate): List<ApiObject>?
suspend fun getSampleObjectafterDate(date: LocalDate): List<ApiObject>?
suspend fun getSampleObjecGreaterthanId(id: Int): List<ApiObject>?
suspend fun getSampleObjecLessthanId(id: Int): List<ApiObject>?
suspend fun getSampleObjecEqualsId(id: Int): List<ApiObject>?
suspend fun getSampleObjectbyDate(date: LocalDate): List<ApiObject>
suspend fun getSampleObjectbeforeDate(date: LocalDate): List<ApiObject>
suspend fun getSampleObjectafterDate(date: LocalDate): List<ApiObject>
}

View File

@ -5,11 +5,11 @@ import com.kmalbz.database.model.SampleObject
import com.kmalbz.database.dao.SampleObjects
import com.kmalbz.api.model.ApiObject
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.castTo
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import java.time.LocalDate
import java.util.*
class SampleObjectService : ISampleObjectService {
@ -35,39 +35,21 @@ class SampleObjectService : ISampleObjectService {
.singleOrNull()
}
override suspend fun getSampleObjectbyDate(date: LocalDate): List<ApiObject>? = dbQuery {
override suspend fun getSampleObjectbyDate(date: LocalDate): List<ApiObject> = dbQuery {
SampleObjects.select {
(SampleObjects.date eq date)
(SampleObjects.timestamp eq date)
}.mapNotNull { toResultObject(it) }
}
override suspend fun getSampleObjectbeforeDate(date: LocalDate): List<ApiObject>? = dbQuery {
override suspend fun getSampleObjectbeforeDate(date: LocalDate): List<ApiObject> = dbQuery {
SampleObjects.select {
(SampleObjects.date less date)
(SampleObjects.timestamp less date)
}.mapNotNull { toResultObject(it) }
}
override suspend fun getSampleObjectafterDate(date: LocalDate): List<ApiObject>? = dbQuery {
override suspend fun getSampleObjectafterDate(date: LocalDate): List<ApiObject> = dbQuery {
SampleObjects.select {
(SampleObjects.date greater date)
}.mapNotNull { toResultObject(it) }
}
override suspend fun getSampleObjecGreaterthanId(probability: Double): List<ApiObject>? = dbQuery {
SampleObjects.select {
(SampleObjects.probability greater probability)
}.mapNotNull { toResultObject(it) }
}
override suspend fun getSampleObjecLessthanId(probability: Double): List<ApiObject>? = dbQuery {
SampleObjects.select {
(SampleObjects.probability less probability)
}.mapNotNull { toResultObject(it) }
}
override suspend fun getSampleObjecEqualsId(probability: Double): List<ApiObject>? = dbQuery {
SampleObjects.select {
(SampleObjects.probability eq probability)
(SampleObjects.timestamp greater date)
}.mapNotNull { toResultObject(it) }
}
@ -75,7 +57,6 @@ class SampleObjectService : ISampleObjectService {
ApiObject(
tag = row[SampleObjects.tag],
device_date = row[SampleObjects.device_date],
device_id = row[SampleObjects.device_id],
id = row[SampleObjects.id.]
device_id = row[SampleObjects.device_id]
)
}