This commit is contained in:
parent
d8e0819f00
commit
d4a2d9925c
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@
|
|||||||
*.iml
|
*.iml
|
||||||
*.ipr
|
*.ipr
|
||||||
*.iws
|
*.iws
|
||||||
|
*.log
|
@ -7,6 +7,7 @@ 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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ tasks.withType(JavaCompile) {
|
|||||||
apply plugin: 'kotlin'
|
apply plugin: 'kotlin'
|
||||||
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'
|
||||||
@ -45,6 +47,7 @@ dependencies {
|
|||||||
compile 'com.rabbitmq:amqp-client:2.7.1'
|
compile 'com.rabbitmq:amqp-client:2.7.1'
|
||||||
compile 'com.zaxxer:HikariCP:2.7.8'
|
compile 'com.zaxxer:HikariCP:2.7.8'
|
||||||
compile 'com.viartemev:the-white-rabbit:0.0.5'
|
compile 'com.viartemev:the-white-rabbit:0.0.5'
|
||||||
|
implementation "org.koin:koin-ktor:$koin_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"
|
||||||
|
@ -2,3 +2,4 @@ ktor_version=1.3.2
|
|||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
kotlin_version=1.3.72
|
kotlin_version=1.3.72
|
||||||
logback_version=1.2.1
|
logback_version=1.2.1
|
||||||
|
koin_version=2.1.5
|
@ -23,6 +23,7 @@ import kotlinx.coroutines.GlobalScope
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
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
|
||||||
|
|
||||||
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
|
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
|
||||||
|
|
||||||
@ -33,13 +34,16 @@ fun Application.module() {
|
|||||||
gson {
|
gson {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
install(Koin) {
|
||||||
|
printLogger()
|
||||||
|
modules(com.kmalbz.di.injectionModule)
|
||||||
|
}
|
||||||
|
|
||||||
DatabaseFactory.init()
|
DatabaseFactory.init()
|
||||||
transaction{
|
transaction{
|
||||||
SchemaUtils.create(ResultObjects)
|
SchemaUtils.create(ResultObjects)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val appConfig = HoconApplicationConfig(ConfigFactory.load())
|
val appConfig = HoconApplicationConfig(ConfigFactory.load())
|
||||||
val factory = ConnectionFactory()
|
val factory = ConnectionFactory()
|
||||||
factory.host = appConfig.property("ktor.mq.host").getString()
|
factory.host = appConfig.property("ktor.mq.host").getString()
|
||||||
@ -72,14 +76,6 @@ fun Application.module() {
|
|||||||
|
|
||||||
routing {
|
routing {
|
||||||
install(StatusPages) {
|
install(StatusPages) {
|
||||||
exception<AuthenticationException> {
|
|
||||||
call.respond(HttpStatusCode.Unauthorized)
|
|
||||||
}
|
|
||||||
|
|
||||||
exception<AuthorizationException> {
|
|
||||||
call.respond(HttpStatusCode.Forbidden)
|
|
||||||
}
|
|
||||||
|
|
||||||
exception<HttpException> {
|
exception<HttpException> {
|
||||||
call.respond(HttpStatusCode.BadRequest)
|
call.respond(HttpStatusCode.BadRequest)
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package com.kmalbz.api.route
|
package com.kmalbz.api.route
|
||||||
|
|
||||||
import io.ktor.application.*
|
import com.kmalbz.database.service.IResultObjectService
|
||||||
import io.ktor.response.*
|
import io.ktor.application.call
|
||||||
import io.ktor.routing.*
|
import io.ktor.http.HttpStatusCode
|
||||||
import io.ktor.http.*
|
import io.ktor.response.respond
|
||||||
import com.kmalbz.database.service.ResultObjectService
|
import io.ktor.routing.Routing
|
||||||
|
import io.ktor.routing.get
|
||||||
|
import org.koin.ktor.ext.inject
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
@ -17,8 +19,8 @@ class OutputServiceRDBServer {
|
|||||||
/**
|
/**
|
||||||
* output
|
* output
|
||||||
*/
|
*/
|
||||||
private val resultObjectService = ResultObjectService()
|
|
||||||
fun Routing.registerOutput() {
|
fun Routing.registerOutput() {
|
||||||
|
val resultObjectService by inject<IResultObjectService>()
|
||||||
get("/output"){
|
get("/output"){
|
||||||
call.respond(resultObjectService.getAllResultObjects())
|
call.respond(resultObjectService.getAllResultObjects())
|
||||||
}
|
}
|
||||||
|
16
src/database/service/IResultObjectService.kt
Normal file
16
src/database/service/IResultObjectService.kt
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package com.kmalbz.database.service
|
||||||
|
|
||||||
|
import com.kmalbz.api.model.ApiObject
|
||||||
|
import java.time.LocalDate
|
||||||
|
|
||||||
|
interface IResultObjectService{
|
||||||
|
fun addOne(apiObject: ApiObject)
|
||||||
|
suspend fun getAllResultObjects(): List<ApiObject>
|
||||||
|
suspend fun getResultObjectbyTag(tag: String): ApiObject?
|
||||||
|
suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>?
|
||||||
|
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>?
|
||||||
|
suspend fun getResultObjectafterDate(date: LocalDate): List<ApiObject>?
|
||||||
|
suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject>?
|
||||||
|
suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject>?
|
||||||
|
suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject>?
|
||||||
|
}
|
@ -11,9 +11,9 @@ import org.jetbrains.exposed.sql.transactions.transaction
|
|||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
|
|
||||||
|
|
||||||
class ResultObjectService {
|
class ResultObjectService : IResultObjectService {
|
||||||
|
|
||||||
fun addOne(apiObject: ApiObject) {
|
override fun addOne(apiObject: ApiObject) {
|
||||||
transaction {
|
transaction {
|
||||||
ResultObject.new {
|
ResultObject.new {
|
||||||
tag = apiObject.tag
|
tag = apiObject.tag
|
||||||
@ -22,48 +22,48 @@ class ResultObjectService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getAllResultObjects(): List<ApiObject> = dbQuery {
|
override suspend fun getAllResultObjects(): List<ApiObject> = dbQuery {
|
||||||
ResultObjects.selectAll().map { toResultObject(it) }
|
ResultObjects.selectAll().map { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjectbyTag(tag: String): ApiObject? = dbQuery {
|
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
override suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.date eq date)
|
(ResultObjects.date eq date)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
override suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.date less date)
|
(ResultObjects.date less date)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjectafterDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
override suspend fun getResultObjectafterDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.date greater date)
|
(ResultObjects.date greater date)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
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) }
|
||||||
}
|
}
|
||||||
|
|
||||||
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) }
|
||||||
}
|
}
|
||||||
|
|
||||||
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) }
|
||||||
|
10
src/di/InjectionModule.kt
Normal file
10
src/di/InjectionModule.kt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package com.kmalbz.di
|
||||||
|
|
||||||
|
import com.kmalbz.database.service.IResultObjectService
|
||||||
|
import com.kmalbz.database.service.ResultObjectService
|
||||||
|
import org.koin.dsl.module
|
||||||
|
import org.koin.experimental.builder.singleBy
|
||||||
|
|
||||||
|
val injectionModule = module(createdAtStart = true) {
|
||||||
|
singleBy<IResultObjectService,ResultObjectService>()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user