mirror of
https://github.com/Redume/Kekkai.git
synced 2025-02-23 20:51:25 +03:00
init
This commit is contained in:
commit
ff828ff9e1
19 changed files with 1250 additions and 0 deletions
12
src/main/kotlin/su/redume/Application.kt
Normal file
12
src/main/kotlin/su/redume/Application.kt
Normal file
|
@ -0,0 +1,12 @@
|
|||
package su.redume
|
||||
|
||||
import io.ktor.server.application.*
|
||||
import su.redume.database.DatabaseFactory
|
||||
import su.redume.plugins.*
|
||||
|
||||
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
|
||||
|
||||
fun Application.module() {
|
||||
DatabaseFactory.init(environment.config)
|
||||
configureRouting(environment.config)
|
||||
}
|
14
src/main/kotlin/su/redume/dao/Currency.kt
Normal file
14
src/main/kotlin/su/redume/dao/Currency.kt
Normal file
|
@ -0,0 +1,14 @@
|
|||
package su.redume.dao
|
||||
|
||||
|
||||
class Currency(table: String,
|
||||
fromCurrency: String,
|
||||
convCurrency: String,
|
||||
periodStart: Int,
|
||||
periodEnd: Int) {
|
||||
|
||||
|
||||
fun getData() {
|
||||
|
||||
}
|
||||
}
|
53
src/main/kotlin/su/redume/database/DatabaseFactory.kt
Normal file
53
src/main/kotlin/su/redume/database/DatabaseFactory.kt
Normal file
|
@ -0,0 +1,53 @@
|
|||
package su.redume.database
|
||||
|
||||
import io.ktor.server.config.*
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import com.zaxxer.hikari.HikariConfig
|
||||
import com.zaxxer.hikari.HikariDataSource
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import org.jetbrains.exposed.sql.SchemaUtils
|
||||
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import su.redume.models.Crypto
|
||||
import su.redume.models.Fiat
|
||||
|
||||
object DatabaseFactory {
|
||||
fun init(config: ApplicationConfig) {
|
||||
val jdbcURL = config.property("ktor.database.jdbcURL").getString()
|
||||
val maxPoolSize = config.property("ktor.database.maxPoolSize").getString()
|
||||
val autoCommit = config.property("ktor.database.autoCommit").getString()
|
||||
val username = config.property("ktor.database.user").getString()
|
||||
val password = config.property("ktor.database.password").getString()
|
||||
val defaultDatabase = config.property("ktor.database.database").getString()
|
||||
|
||||
val connectPool = createHikariDataSource(
|
||||
url = "$jdbcURL/$defaultDatabase?user=$username&password=$password",
|
||||
maxPoolSize.toInt(),
|
||||
autoCommit.toBoolean()
|
||||
)
|
||||
|
||||
val database = Database.connect(connectPool)
|
||||
transaction(database) {
|
||||
SchemaUtils.create(Fiat)
|
||||
SchemaUtils.create(Crypto)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun createHikariDataSource(
|
||||
url: String,
|
||||
maxPoolSize: Int,
|
||||
autoCommit: Boolean
|
||||
) = HikariDataSource(HikariConfig().apply {
|
||||
driverClassName = "org.postgresql.Driver"
|
||||
jdbcUrl = url
|
||||
maximumPoolSize = maxPoolSize
|
||||
isAutoCommit = autoCommit
|
||||
transactionIsolation = "TRANSACTION_REPEATABLE_READ"
|
||||
validate()
|
||||
})
|
||||
|
||||
suspend fun <T> dbQuery(block: suspend () -> T): T =
|
||||
newSuspendedTransaction(Dispatchers.IO) { block() }
|
||||
|
||||
}
|
11
src/main/kotlin/su/redume/models/Crypto.kt
Normal file
11
src/main/kotlin/su/redume/models/Crypto.kt
Normal file
|
@ -0,0 +1,11 @@
|
|||
package su.redume.models
|
||||
|
||||
import org.jetbrains.exposed.sql.Table
|
||||
import org.jetbrains.exposed.sql.stringParam
|
||||
|
||||
object Crypto : Table() {
|
||||
val fromCurrecny = stringParam("fromCurrecny")
|
||||
val convCurrency = stringParam("convCurrency")
|
||||
val rate = integer("rate")
|
||||
val date = long("date")
|
||||
}
|
11
src/main/kotlin/su/redume/models/Fiat.kt
Normal file
11
src/main/kotlin/su/redume/models/Fiat.kt
Normal file
|
@ -0,0 +1,11 @@
|
|||
package su.redume.models
|
||||
|
||||
import org.jetbrains.exposed.sql.Table
|
||||
import org.jetbrains.exposed.sql.stringParam
|
||||
|
||||
object Fiat : Table() {
|
||||
val fromCurrecny = stringParam("fromCurrecny")
|
||||
val convCurrency = stringParam("convCurrency")
|
||||
val rate = integer("rate")
|
||||
val date = long("date")
|
||||
}
|
14
src/main/kotlin/su/redume/plugins/Routing.kt
Normal file
14
src/main/kotlin/su/redume/plugins/Routing.kt
Normal file
|
@ -0,0 +1,14 @@
|
|||
package su.redume.plugins
|
||||
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.config.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
|
||||
fun Application.configureRouting(config: ApplicationConfig) {
|
||||
routing {
|
||||
get("/") {
|
||||
call.respondText("Hello World!")
|
||||
}
|
||||
}
|
||||
}
|
10
src/main/resources/application.yaml
Normal file
10
src/main/resources/application.yaml
Normal file
|
@ -0,0 +1,10 @@
|
|||
ktor:
|
||||
port: 3000
|
||||
host: localhost
|
||||
database:
|
||||
jdbcURL: "jdbc:postgresql://localhost:5432"
|
||||
database: "DATABASE_NAME"
|
||||
user: "DATABASE_USER"
|
||||
password: "DATABASE_PASSWORD"
|
||||
maxPoolSize: 50
|
||||
autoCommit: false
|
12
src/main/resources/logback.xml
Normal file
12
src/main/resources/logback.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="trace">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
<logger name="org.eclipse.jetty" level="INFO"/>
|
||||
<logger name="io.netty" level="INFO"/>
|
||||
</configuration>
|
Loading…
Add table
Reference in a new issue