diff --git a/src/main/kotlin/dev/usbharu/hideout/SpringApplication.kt b/src/main/kotlin/dev/usbharu/hideout/SpringApplication.kt index 5d30de45..8385ee79 100644 --- a/src/main/kotlin/dev/usbharu/hideout/SpringApplication.kt +++ b/src/main/kotlin/dev/usbharu/hideout/SpringApplication.kt @@ -1,10 +1,12 @@ package dev.usbharu.hideout import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.context.properties.ConfigurationPropertiesScan import org.springframework.boot.runApplication @SpringBootApplication +@ConfigurationPropertiesScan class SpringApplication fun main(args: Array) { diff --git a/src/main/kotlin/dev/usbharu/hideout/config/DatabaseConfig.kt b/src/main/kotlin/dev/usbharu/hideout/config/DatabaseConfig.kt new file mode 100644 index 00000000..b597249a --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/config/DatabaseConfig.kt @@ -0,0 +1,35 @@ +package dev.usbharu.hideout.config + +import org.jetbrains.exposed.sql.Database +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.context.properties.ConfigurationProperties +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + + +@Configuration +class DatabaseConfig { + + @Autowired + lateinit var dbConfig: DatabaseConnectConfig + + @Bean + fun database(): Database { + return Database.connect( + url = dbConfig.url, + driver = dbConfig.driver, + user = dbConfig.user ?: "", + password = dbConfig.password ?: "" + ) + } + +} + + +@ConfigurationProperties("hideout.database") +data class DatabaseConnectConfig( + val url: String, + val driver: String, + val user: String?, + val password: String? +) diff --git a/src/main/kotlin/dev/usbharu/hideout/config/HttpClientConfig.kt b/src/main/kotlin/dev/usbharu/hideout/config/HttpClientConfig.kt new file mode 100644 index 00000000..85483577 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/config/HttpClientConfig.kt @@ -0,0 +1,12 @@ +package dev.usbharu.hideout.config + +import io.ktor.client.* +import io.ktor.client.engine.cio.* +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +class HttpClientConfig { + @Bean + fun httpClient(): HttpClient = HttpClient(CIO) +} diff --git a/src/main/kotlin/dev/usbharu/hideout/service/core/SnowflakeIdGenerateService.kt b/src/main/kotlin/dev/usbharu/hideout/service/core/SnowflakeIdGenerateService.kt index a4fbbf15..e90ea2d6 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/core/SnowflakeIdGenerateService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/core/SnowflakeIdGenerateService.kt @@ -3,11 +3,9 @@ package dev.usbharu.hideout.service.core import kotlinx.coroutines.delay import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock -import org.springframework.stereotype.Service import java.time.Instant @Suppress("MagicNumber") -@Service open class SnowflakeIdGenerateService(private val baseTime: Long) : IdGenerateService { var lastTimeStamp: Long = -1 var sequenceId: Int = 0 diff --git a/src/main/kotlin/dev/usbharu/hideout/service/core/TwitterSnowflakeIdGenerateService.kt b/src/main/kotlin/dev/usbharu/hideout/service/core/TwitterSnowflakeIdGenerateService.kt index 17459f2b..e3e46739 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/core/TwitterSnowflakeIdGenerateService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/core/TwitterSnowflakeIdGenerateService.kt @@ -1,8 +1,10 @@ package dev.usbharu.hideout.service.core +import org.springframework.context.annotation.Primary import org.springframework.stereotype.Service // 2010-11-04T01:42:54.657 @Suppress("MagicNumber") @Service +@Primary object TwitterSnowflakeIdGenerateService : SnowflakeIdGenerateService(1288834974657L) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 00000000..f792e465 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,6 @@ +hideout: + database: + url: "jdbc:h2:./test;MODE=POSTGRESQL" + driver: "org.h2.Driver" + username: "" + password: ""