Compare commits
16 Commits
0615d63610
...
master
Author | SHA1 | Date | |
---|---|---|---|
f7757d31fb | |||
d638b98d1a
|
|||
4fc8db6fa4
|
|||
1997df3da9 | |||
f46386d465
|
|||
4f67c48f7a
|
|||
5f2d88d3d2
|
|||
9c432ae60d
|
|||
ac4e01b1e9
|
|||
3c3beff2e4
|
|||
9793ccc593 | |||
204dfcabbc | |||
f27eec0f8f | |||
264545215b | |||
2b89400168
|
|||
8d7f05d122
|
28
.drone.yml
28
.drone.yml
@ -3,6 +3,14 @@ type: docker
|
|||||||
name: default
|
name: default
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: code-analysis
|
||||||
|
image: aosapps/drone-sonar-plugin
|
||||||
|
settings:
|
||||||
|
sonar_host:
|
||||||
|
from_secret: SONAR_HOST
|
||||||
|
sonar_token:
|
||||||
|
from_secret: SONAR_CODE
|
||||||
|
|
||||||
- name: build_application
|
- name: build_application
|
||||||
image: openjdk:11-jdk
|
image: openjdk:11-jdk
|
||||||
commands:
|
commands:
|
||||||
@ -20,3 +28,23 @@ steps:
|
|||||||
tags:
|
tags:
|
||||||
- latest
|
- latest
|
||||||
- ${DRONE_BUILD_NUMBER}
|
- ${DRONE_BUILD_NUMBER}
|
||||||
|
|
||||||
|
- name: dockerhub
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
repo: birbnetes/${DRONE_REPO_NAME}
|
||||||
|
username:
|
||||||
|
from_secret: DOCKERHUB_USER
|
||||||
|
password:
|
||||||
|
from_secret: DOCKERHUB_PASSWORD
|
||||||
|
tags:
|
||||||
|
- latest
|
||||||
|
- ${DRONE_BUILD_NUMBER}
|
||||||
|
|
||||||
|
- name: ms-teams
|
||||||
|
image: kuperiu/drone-teams
|
||||||
|
settings:
|
||||||
|
webhook:
|
||||||
|
from_secret: TEAMS_WEBHOOK
|
||||||
|
when:
|
||||||
|
status: [ failure ]
|
@ -11,4 +11,4 @@ USER $APPLICATION_USER
|
|||||||
COPY ./build/libs/output-service-rdb.jar /app/output-service-rdb.jar
|
COPY ./build/libs/output-service-rdb.jar /app/output-service-rdb.jar
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
CMD ["java", "-server", "-XX:+UnlockExperimentalVMOptions", "-XX:InitialRAMFraction=2", "-XX:MinRAMFraction=2", "-XX:MaxRAMFraction=2", "-XX:+UseG1GC", "-XX:MaxGCPauseMillis=100", "-XX:+UseStringDeduplication", "-jar", "output-service-rdb.jar"]
|
CMD ["java", "-server", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseG1GC", "-XX:MaxGCPauseMillis=100", "-XX:+UseStringDeduplication", "-jar", "output-service-rdb.jar"]
|
30
build.gradle
30
build.gradle
@ -7,19 +7,23 @@ buildscript {
|
|||||||
dependencies {
|
dependencies {
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
classpath "com.github.jengelman.gradle.plugins:shadow:5.2.0"
|
classpath "com.github.jengelman.gradle.plugins:shadow:5.2.0"
|
||||||
classpath "org.koin:koin-gradle-plugin:$koin_version"
|
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.21'
|
||||||
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
sourceCompatibility = JavaVersion.VERSION_11
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
targetCompatibility = JavaVersion.VERSION_11
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'kotlin'
|
apply plugin: 'kotlin'
|
||||||
|
apply plugin: 'kotlinx-serialization'
|
||||||
apply plugin: "com.github.johnrengelman.shadow"
|
apply plugin: "com.github.johnrengelman.shadow"
|
||||||
apply plugin: 'application'
|
apply plugin: 'application'
|
||||||
apply plugin: 'koin'
|
|
||||||
|
|
||||||
group 'com.kmalbz'
|
group 'com.kmalbz'
|
||||||
version '0.0.1'
|
version '0.0.1'
|
||||||
@ -39,26 +43,26 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'org.postgresql:postgresql:42.2.2'
|
compile 'org.postgresql:postgresql:42.2.23'
|
||||||
compile 'org.jetbrains.exposed:exposed-core:0.23.1'
|
compile 'org.jetbrains.exposed:exposed-core:0.33.1'
|
||||||
compile 'org.jetbrains.exposed:exposed-dao:0.23.1'
|
compile 'org.jetbrains.exposed:exposed-dao:0.33.1'
|
||||||
compile 'org.jetbrains.exposed:exposed-jdbc:0.23.1'
|
compile 'org.jetbrains.exposed:exposed-jdbc:0.33.1'
|
||||||
compile 'org.jetbrains.exposed:exposed-java-time:0.23.1'
|
compile 'org.jetbrains.exposed:exposed-java-time:0.33.1'
|
||||||
compile 'com.rabbitmq:amqp-client:2.7.1'
|
compile 'com.zaxxer:HikariCP:5.0.0'
|
||||||
compile 'com.zaxxer:HikariCP:2.7.8'
|
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"
|
||||||
compile 'com.viartemev:the-white-rabbit:0.0.5'
|
implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.2.1"
|
||||||
implementation "org.koin:koin-ktor:$koin_version"
|
implementation "io.insert-koin:koin-core:$koin_version"
|
||||||
|
implementation "io.insert-koin:koin-ktor:$koin_version"
|
||||||
|
implementation "io.ktor:ktor-serialization:$ktor_version"
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
implementation "io.ktor:ktor-server-netty:$ktor_version"
|
implementation "io.ktor:ktor-server-netty:$ktor_version"
|
||||||
implementation "ch.qos.logback:logback-classic:$logback_version"
|
implementation "ch.qos.logback:logback-classic:$logback_version"
|
||||||
implementation "io.ktor:ktor-server-core:$ktor_version"
|
implementation "io.ktor:ktor-server-core:$ktor_version"
|
||||||
implementation "io.ktor:ktor-gson:$ktor_version"
|
|
||||||
implementation "io.ktor:ktor-server-host-common:$ktor_version"
|
implementation "io.ktor:ktor-server-host-common:$ktor_version"
|
||||||
implementation "io.ktor:ktor-client-core:$ktor_version"
|
implementation "io.ktor:ktor-client-core:$ktor_version"
|
||||||
implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
|
implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
|
||||||
implementation "io.ktor:ktor-client-apache:$ktor_version"
|
implementation "io.ktor:ktor-client-apache:$ktor_version"
|
||||||
implementation "io.ktor:ktor-auth:$ktor_version"
|
implementation "io.ktor:ktor-auth:$ktor_version"
|
||||||
testImplementation "io.ktor:ktor-server-tests:$ktor_version"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin.experimental.coroutines = 'enable'
|
kotlin.experimental.coroutines = 'enable'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
ktor_version=1.3.2
|
ktor_version=1.6.2
|
||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
kotlin_version=1.3.72
|
kotlin_version=1.5.21
|
||||||
logback_version=1.2.1
|
logback_version=1.2.5
|
||||||
koin_version=2.1.5
|
koin_version=3.1.2
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
|
||||||
|
@ -12,4 +12,4 @@ data:
|
|||||||
DB_PASSWORD: output-service-supersecret
|
DB_PASSWORD: output-service-supersecret
|
||||||
MQ_HOST: birb-rabbitmq
|
MQ_HOST: birb-rabbitmq
|
||||||
MQ_USERNAME: user
|
MQ_USERNAME: user
|
||||||
MQ_PASSWORD: 1wZVQnP5vy
|
MQ_PASSWORD: F3ACadDRsT
|
||||||
|
@ -18,7 +18,8 @@ spec:
|
|||||||
app: output-service-rdb
|
app: output-service-rdb
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- image: registry.kmlabz.com/tormakris/output-service-rdb
|
- image: registry.kmlabz.com/birbnetes/output-service-rdb
|
||||||
|
imagePullPolicy: Always
|
||||||
name: output-service-rdb
|
name: output-service-rdb
|
||||||
envFrom:
|
envFrom:
|
||||||
- configMapRef:
|
- configMapRef:
|
||||||
@ -26,4 +27,4 @@ spec:
|
|||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
imagePullSecrets:
|
imagePullSecrets:
|
||||||
- name: regcred
|
- name: regcred
|
||||||
|
@ -1,20 +1,16 @@
|
|||||||
package com.kmalbz
|
package com.kmalbz
|
||||||
|
|
||||||
import com.kmalbz.api.route.OutputServiceRDBServer
|
import com.kmalbz.api.route.OutputServiceRDBServer
|
||||||
import com.kmalbz.consumer.DatabaseConsumer
|
|
||||||
import io.ktor.application.*
|
import io.ktor.application.*
|
||||||
import io.ktor.response.*
|
import io.ktor.response.*
|
||||||
import io.ktor.routing.*
|
import io.ktor.routing.*
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.gson.*
|
|
||||||
import io.ktor.features.*
|
import io.ktor.features.*
|
||||||
import org.apache.http.HttpException
|
import org.apache.http.HttpException
|
||||||
import com.kmalbz.database.DatabaseFactory
|
import com.kmalbz.database.DatabaseFactory
|
||||||
import com.kmalbz.database.dao.ResultObjects
|
import com.kmalbz.database.dao.ResultObjects
|
||||||
|
import io.ktor.serialization.*
|
||||||
import io.ktor.util.KtorExperimentalAPI
|
import io.ktor.util.KtorExperimentalAPI
|
||||||
import com.rabbitmq.client.*
|
|
||||||
import com.typesafe.config.ConfigFactory
|
|
||||||
import io.ktor.config.HoconApplicationConfig
|
|
||||||
import org.jetbrains.exposed.sql.SchemaUtils
|
import org.jetbrains.exposed.sql.SchemaUtils
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
import org.koin.ktor.ext.Koin
|
import org.koin.ktor.ext.Koin
|
||||||
@ -25,8 +21,7 @@ fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
|
|||||||
@Suppress("unused") // Referenced in application.conf
|
@Suppress("unused") // Referenced in application.conf
|
||||||
fun Application.module() {
|
fun Application.module() {
|
||||||
install(ContentNegotiation) {
|
install(ContentNegotiation) {
|
||||||
gson {
|
json()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
install(Koin) {
|
install(Koin) {
|
||||||
@ -39,23 +34,6 @@ fun Application.module() {
|
|||||||
SchemaUtils.create(ResultObjects)
|
SchemaUtils.create(ResultObjects)
|
||||||
}
|
}
|
||||||
|
|
||||||
val appConfig = HoconApplicationConfig(ConfigFactory.load())
|
|
||||||
val factory = ConnectionFactory()
|
|
||||||
factory.host = appConfig.property("ktor.mq.host").getString()
|
|
||||||
factory.username = appConfig.property("ktor.mq.username").getString()
|
|
||||||
factory.password = appConfig.property("ktor.mq.password").getString()
|
|
||||||
|
|
||||||
val connection = factory.newConnection()
|
|
||||||
val channel = connection.createChannel()
|
|
||||||
|
|
||||||
val rabbitExchangeName = appConfig.property("ktor.mq.exchange").getString()
|
|
||||||
|
|
||||||
channel.exchangeDeclare(rabbitExchangeName, BuiltinExchangeType.FANOUT)
|
|
||||||
val queueName = channel.queueDeclare().queue
|
|
||||||
channel.queueBind(queueName, rabbitExchangeName, "")
|
|
||||||
|
|
||||||
channel.basicConsume(queueName, true, DatabaseConsumer())
|
|
||||||
|
|
||||||
routing {
|
routing {
|
||||||
install(StatusPages) {
|
install(StatusPages) {
|
||||||
exception<HttpException> {
|
exception<HttpException> {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.kmalbz.api.model
|
package com.kmalbz.api.model
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
import kotlinx.serialization.Serializable
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class ApiObject(
|
data class ApiObject(
|
||||||
@SerializedName("tag") val tag: UUID,
|
val tag: String,
|
||||||
@SerializedName("probability") val probability: Double
|
val probability: Double
|
||||||
)
|
)
|
@ -6,65 +6,78 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Routing
|
import io.ktor.routing.Routing
|
||||||
import io.ktor.routing.get
|
import io.ktor.routing.get
|
||||||
|
import kotlinx.datetime.LocalDateTime
|
||||||
import org.koin.ktor.ext.inject
|
import org.koin.ktor.ext.inject
|
||||||
import java.time.LocalDate
|
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output Service - RDB
|
* Output Service - RDB
|
||||||
*
|
*
|
||||||
* This is the output interface of the Birbnetes system.
|
* This is the output interface of the Birbnetes system.
|
||||||
*/
|
*/
|
||||||
class OutputServiceRDBServer {
|
class OutputServiceRDBServer {
|
||||||
/**
|
/**
|
||||||
* output
|
* output
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fun Routing.registerOutput() {
|
fun Routing.registerOutput() {
|
||||||
val resultObjectService by inject<IResultObjectService>()
|
val resultObjectService: IResultObjectService by inject()
|
||||||
get("/output"){
|
get("/output") {
|
||||||
call.respond(resultObjectService.getAllResultObjects())
|
call.respond(resultObjectService.getAllResultObjects())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get("/output/count") {
|
||||||
|
call.respond(resultObjectService.getCount())
|
||||||
|
}
|
||||||
|
|
||||||
|
get("/output/page/{page}") {
|
||||||
|
val page = call.parameters["page"] ?: error(HttpStatusCode.NotAcceptable)
|
||||||
|
val pageNum = page.toLong()
|
||||||
|
call.respond(resultObjectService.getPage(pageNum))
|
||||||
|
}
|
||||||
|
|
||||||
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(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(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(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 localDateAfter: LocalDateTime = LocalDateTime.parse(dateAfter)
|
||||||
val localDateAfter : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
|
val resultList =
|
||||||
val resultList = resultObjectService.getResultObjectafterDate(localDateAfter) ?: call.respond(HttpStatusCode.NotFound)
|
resultObjectService.getResultObjectafterDate(localDateAfter)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 localDateBefore: LocalDateTime = LocalDateTime.parse(dateAfter)
|
||||||
val localDateBefore : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
|
val resultList =
|
||||||
val resultList = resultObjectService.getResultObjectbeforeDate(localDateBefore) ?: call.respond(HttpStatusCode.NotFound)
|
resultObjectService.getResultObjectbeforeDate(localDateBefore)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
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(UUID.fromString(tagID)) ?: call.respond(HttpStatusCode.NotFound)
|
val resultObject = resultObjectService.getResultObjectbyTag(tagID) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultObject)
|
call.respond(resultObject)
|
||||||
}
|
}
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
package com.kmalbz.consumer
|
|
||||||
|
|
||||||
import com.google.gson.Gson
|
|
||||||
import com.kmalbz.api.model.ApiObject
|
|
||||||
import com.kmalbz.database.service.ResultObjectService
|
|
||||||
import com.rabbitmq.client.AMQP.BasicProperties
|
|
||||||
import com.rabbitmq.client.Consumer
|
|
||||||
import com.rabbitmq.client.Envelope
|
|
||||||
import com.rabbitmq.client.ShutdownSignalException
|
|
||||||
|
|
||||||
class DatabaseConsumer : Consumer {
|
|
||||||
private val resultObjectService = ResultObjectService()
|
|
||||||
|
|
||||||
private val gson = Gson()
|
|
||||||
override fun handleConsumeOk(consumerTag : String?) {
|
|
||||||
}
|
|
||||||
override fun handleCancelOk(p0 : String?) {
|
|
||||||
throw UnsupportedOperationException()
|
|
||||||
}
|
|
||||||
override fun handleRecoverOk(p0 : String?) {
|
|
||||||
throw UnsupportedOperationException()
|
|
||||||
}
|
|
||||||
override fun handleCancel(p0 : String?) {
|
|
||||||
throw UnsupportedOperationException()
|
|
||||||
}
|
|
||||||
override fun handleDelivery(consumerTag : String?, envelope : Envelope?, basicProperties : BasicProperties?, body : ByteArray?) {
|
|
||||||
val rawJson = body!!.toString(Charsets.UTF_8)
|
|
||||||
val apiObject = gson.fromJson(rawJson, ApiObject::class.java)
|
|
||||||
|
|
||||||
resultObjectService.addOne(apiObject)
|
|
||||||
}
|
|
||||||
override fun handleShutdownSignal(p0 : String?, p1 : ShutdownSignalException?) {
|
|
||||||
println("got shutdown signal")
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,13 +2,12 @@ package com.kmalbz.database.dao
|
|||||||
|
|
||||||
import org.jetbrains.exposed.dao.id.IntIdTable
|
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`.datetime
|
||||||
import java.time.LocalDate
|
import java.time.LocalDateTime
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
object ResultObjects : IntIdTable() {
|
object ResultObjects : IntIdTable() {
|
||||||
val tag: Column<UUID> = uuid("tag")
|
val tag: Column<String> = varchar("tag", 32)
|
||||||
val date: Column<LocalDate> = date("date").default(LocalDate.now())
|
val date: Column<LocalDateTime> = datetime("date").default(LocalDateTime.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")
|
||||||
}
|
}
|
@ -1,17 +1,18 @@
|
|||||||
package com.kmalbz.database.service
|
package com.kmalbz.database.service
|
||||||
|
|
||||||
import com.kmalbz.api.model.ApiObject
|
import com.kmalbz.api.model.ApiObject
|
||||||
import java.time.LocalDate
|
import kotlinx.datetime.LocalDateTime
|
||||||
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: UUID): ApiObject?
|
suspend fun getCount(): Long
|
||||||
suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>?
|
suspend fun getPage(page: Long): List<ApiObject>
|
||||||
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>?
|
suspend fun getResultObjectbyTag(tag: String): ApiObject?
|
||||||
suspend fun getResultObjectafterDate(date: LocalDate): List<ApiObject>?
|
suspend fun getResultObjectbyDate(date: LocalDateTime): List<ApiObject>
|
||||||
suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject>?
|
suspend fun getResultObjectbeforeDate(date: LocalDateTime): List<ApiObject>
|
||||||
suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject>?
|
suspend fun getResultObjectafterDate(date: LocalDateTime): List<ApiObject>
|
||||||
suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject>?
|
suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject>
|
||||||
|
suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject>
|
||||||
|
suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject>
|
||||||
}
|
}
|
@ -4,12 +4,12 @@ import com.kmalbz.database.DatabaseFactory.dbQuery
|
|||||||
import com.kmalbz.database.model.ResultObject
|
import com.kmalbz.database.model.ResultObject
|
||||||
import com.kmalbz.database.dao.ResultObjects
|
import com.kmalbz.database.dao.ResultObjects
|
||||||
import com.kmalbz.api.model.ApiObject
|
import com.kmalbz.api.model.ApiObject
|
||||||
|
import kotlinx.datetime.LocalDateTime
|
||||||
|
import kotlinx.datetime.toJavaLocalDateTime
|
||||||
import org.jetbrains.exposed.sql.ResultRow
|
import org.jetbrains.exposed.sql.ResultRow
|
||||||
import org.jetbrains.exposed.sql.select
|
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.util.*
|
|
||||||
|
|
||||||
|
|
||||||
class ResultObjectService : IResultObjectService {
|
class ResultObjectService : IResultObjectService {
|
||||||
@ -27,44 +27,52 @@ class ResultObjectService : IResultObjectService {
|
|||||||
ResultObjects.selectAll().map { toResultObject(it) }
|
ResultObjects.selectAll().map { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getResultObjectbyTag(tag: UUID): ApiObject? = dbQuery {
|
override suspend fun getCount(): Long = dbQuery {
|
||||||
|
ResultObjects.selectAll().count()
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getPage(page: Long): List<ApiObject> = dbQuery {
|
||||||
|
ResultObjects.selectAll().limit(10,page*10).map { toResultObject(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getResultObjectbyTag(tag: String): ApiObject? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.tag eq tag)
|
(ResultObjects.tag eq tag)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
.singleOrNull()
|
.singleOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
override suspend fun getResultObjectbyDate(date: LocalDateTime): List<ApiObject> = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.date eq date)
|
(ResultObjects.date eq date.toJavaLocalDateTime())
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
override suspend fun getResultObjectbeforeDate(date: LocalDateTime): List<ApiObject> = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.date less date)
|
(ResultObjects.date less date.toJavaLocalDateTime())
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getResultObjectafterDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
override suspend fun getResultObjectafterDate(date: LocalDateTime): List<ApiObject> = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.date greater date)
|
(ResultObjects.date greater date.toJavaLocalDateTime())
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject>? = dbQuery {
|
override suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject> = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.probability greater probability)
|
(ResultObjects.probability greater probability)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject>? = dbQuery {
|
override suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject> = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.probability less probability)
|
(ResultObjects.probability less probability)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject>? = dbQuery {
|
override suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject> = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.probability eq probability)
|
(ResultObjects.probability eq probability)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
|
@ -3,8 +3,7 @@ package com.kmalbz.di
|
|||||||
import com.kmalbz.database.service.IResultObjectService
|
import com.kmalbz.database.service.IResultObjectService
|
||||||
import com.kmalbz.database.service.ResultObjectService
|
import com.kmalbz.database.service.ResultObjectService
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import org.koin.experimental.builder.singleBy
|
|
||||||
|
|
||||||
val injectionModule = module(createdAtStart = true) {
|
val injectionModule = module(createdAtStart = true) {
|
||||||
singleBy<IResultObjectService,ResultObjectService>()
|
single<IResultObjectService> {ResultObjectService()}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user