This commit is contained in:
parent
9cfaf5857b
commit
7edc69ec2e
@ -1,5 +1,5 @@
|
|||||||
ktor_version=1.6.2
|
ktor_version=1.6.2
|
||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
kotlin_version=1.4.10
|
kotlin_version=1.5.21
|
||||||
logback_version=1.2.1
|
logback_version=1.2.5
|
||||||
koin_version=2.2.0
|
koin_version=2.2.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.1.1-all.zip
|
||||||
|
@ -11,10 +11,10 @@ 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.SampleObjects
|
import com.kmalbz.database.dao.SampleObjects
|
||||||
import io.ktor.util.KtorExperimentalAPI
|
|
||||||
import com.rabbitmq.client.*
|
import com.rabbitmq.client.*
|
||||||
import com.typesafe.config.ConfigFactory
|
import com.typesafe.config.ConfigFactory
|
||||||
import io.ktor.config.HoconApplicationConfig
|
import io.ktor.config.HoconApplicationConfig
|
||||||
|
import io.ktor.util.*
|
||||||
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
|
||||||
|
@ -7,7 +7,9 @@ import com.rabbitmq.client.AMQP.BasicProperties
|
|||||||
import com.rabbitmq.client.Consumer
|
import com.rabbitmq.client.Consumer
|
||||||
import com.rabbitmq.client.Envelope
|
import com.rabbitmq.client.Envelope
|
||||||
import com.rabbitmq.client.ShutdownSignalException
|
import com.rabbitmq.client.ShutdownSignalException
|
||||||
|
import io.ktor.util.*
|
||||||
|
|
||||||
|
@KtorExperimentalAPI
|
||||||
class DatabaseConsumer : Consumer {
|
class DatabaseConsumer : Consumer {
|
||||||
private val sampleObjectService = SampleObjectService()
|
private val sampleObjectService = SampleObjectService()
|
||||||
|
|
||||||
|
@ -3,29 +3,24 @@ package com.kmalbz.database
|
|||||||
import com.typesafe.config.ConfigFactory
|
import com.typesafe.config.ConfigFactory
|
||||||
import com.zaxxer.hikari.*
|
import com.zaxxer.hikari.*
|
||||||
import io.ktor.config.HoconApplicationConfig
|
import io.ktor.config.HoconApplicationConfig
|
||||||
import io.ktor.util.KtorExperimentalAPI
|
import io.ktor.util.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
|
||||||
|
@KtorExperimentalAPI
|
||||||
object DatabaseFactory {
|
object DatabaseFactory {
|
||||||
|
|
||||||
@KtorExperimentalAPI
|
|
||||||
private val appConfig = HoconApplicationConfig(ConfigFactory.load())
|
private val appConfig = HoconApplicationConfig(ConfigFactory.load())
|
||||||
@KtorExperimentalAPI
|
|
||||||
private val dbUrl = appConfig.property("ktor.db.jdbc").getString()
|
private val dbUrl = appConfig.property("ktor.db.jdbc").getString()
|
||||||
@KtorExperimentalAPI
|
|
||||||
private val dbUser = appConfig.property("ktor.db.user").getString()
|
private val dbUser = appConfig.property("ktor.db.user").getString()
|
||||||
@KtorExperimentalAPI
|
|
||||||
private val dbPassword = appConfig.property("ktor.db.password").getString()
|
private val dbPassword = appConfig.property("ktor.db.password").getString()
|
||||||
|
|
||||||
@KtorExperimentalAPI
|
|
||||||
fun init() {
|
fun init() {
|
||||||
Database.connect(hikari())
|
Database.connect(hikari())
|
||||||
}
|
}
|
||||||
|
|
||||||
@KtorExperimentalAPI
|
|
||||||
private fun hikari(): HikariDataSource {
|
private fun hikari(): HikariDataSource {
|
||||||
val config = HikariConfig()
|
val config = HikariConfig()
|
||||||
config.driverClassName = "org.postgresql.Driver"
|
config.driverClassName = "org.postgresql.Driver"
|
||||||
|
@ -4,6 +4,7 @@ import com.kmalbz.database.DatabaseFactory.dbQuery
|
|||||||
import com.kmalbz.database.model.SampleObject
|
import com.kmalbz.database.model.SampleObject
|
||||||
import com.kmalbz.database.dao.SampleObjects
|
import com.kmalbz.database.dao.SampleObjects
|
||||||
import com.kmalbz.api.model.ApiObject
|
import com.kmalbz.api.model.ApiObject
|
||||||
|
import io.ktor.util.*
|
||||||
import org.jetbrains.exposed.sql.ResultRow
|
import org.jetbrains.exposed.sql.ResultRow
|
||||||
import org.jetbrains.exposed.sql.castTo
|
import org.jetbrains.exposed.sql.castTo
|
||||||
import org.jetbrains.exposed.sql.select
|
import org.jetbrains.exposed.sql.select
|
||||||
@ -12,6 +13,7 @@ import org.jetbrains.exposed.sql.transactions.transaction
|
|||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
|
|
||||||
|
|
||||||
|
@KtorExperimentalAPI
|
||||||
class SampleObjectService : ISampleObjectService {
|
class SampleObjectService : ISampleObjectService {
|
||||||
|
|
||||||
override fun addOne(apiObject: ApiObject) {
|
override fun addOne(apiObject: ApiObject) {
|
||||||
|
@ -2,9 +2,11 @@ package com.kmalbz.di
|
|||||||
|
|
||||||
import com.kmalbz.database.service.ISampleObjectService
|
import com.kmalbz.database.service.ISampleObjectService
|
||||||
import com.kmalbz.database.service.SampleObjectService
|
import com.kmalbz.database.service.SampleObjectService
|
||||||
|
import io.ktor.util.*
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import org.koin.experimental.builder.singleBy
|
import org.koin.experimental.builder.singleBy
|
||||||
|
|
||||||
|
@KtorExperimentalAPI
|
||||||
val injectionModule = module(createdAtStart = true) {
|
val injectionModule = module(createdAtStart = true) {
|
||||||
singleBy<ISampleObjectService,SampleObjectService>()
|
singleBy<ISampleObjectService,SampleObjectService>()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user