From a63e26129adf614e49457bd4fa1b4a0ca987b52f Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 30 Sep 2023 13:26:27 +0900 Subject: [PATCH 1/8] =?UTF-8?q?refactor:=20=E4=B8=8D=E8=A6=81=E3=81=AA?= =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/config/SpringTransactionConfig.kt | 17 --- .../query/JwtRefreshTokenQueryServiceImpl.kt | 46 -------- .../repository/JwtRefreshTokenRepository.kt | 15 --- .../JwtRefreshTokenRepositoryImpl.kt | 71 ------------- .../hideout/service/user/UserAuthService.kt | 1 - .../service/user/UserAuthServiceImpl.kt | 9 +- .../JwtRefreshTokenRepositoryImplTest.kt | 100 ------------------ 7 files changed, 1 insertion(+), 258 deletions(-) delete mode 100644 src/main/kotlin/dev/usbharu/hideout/config/SpringTransactionConfig.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/query/JwtRefreshTokenQueryServiceImpl.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/repository/JwtRefreshTokenRepository.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/repository/JwtRefreshTokenRepositoryImpl.kt delete mode 100644 src/test/kotlin/dev/usbharu/hideout/repository/JwtRefreshTokenRepositoryImplTest.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/config/SpringTransactionConfig.kt b/src/main/kotlin/dev/usbharu/hideout/config/SpringTransactionConfig.kt deleted file mode 100644 index 3edcc581..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/config/SpringTransactionConfig.kt +++ /dev/null @@ -1,17 +0,0 @@ -package dev.usbharu.hideout.config - -import org.jetbrains.exposed.spring.SpringTransactionManager -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.transaction.PlatformTransactionManager -import org.springframework.transaction.annotation.EnableTransactionManagement -import org.springframework.transaction.annotation.TransactionManagementConfigurer -import javax.sql.DataSource - -@Configuration -@EnableTransactionManagement -class SpringTransactionConfig(val datasource: DataSource) : TransactionManagementConfigurer { - @Bean - override fun annotationDrivenTransactionManager(): PlatformTransactionManager = - SpringTransactionManager(datasource) -} diff --git a/src/main/kotlin/dev/usbharu/hideout/query/JwtRefreshTokenQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/query/JwtRefreshTokenQueryServiceImpl.kt deleted file mode 100644 index a3d890ce..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/query/JwtRefreshTokenQueryServiceImpl.kt +++ /dev/null @@ -1,46 +0,0 @@ -package dev.usbharu.hideout.query - -import dev.usbharu.hideout.domain.model.hideout.entity.JwtRefreshToken -import dev.usbharu.hideout.exception.FailedToGetResourcesException -import dev.usbharu.hideout.repository.JwtRefreshTokens -import dev.usbharu.hideout.repository.toJwtRefreshToken -import dev.usbharu.hideout.util.singleOr -import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq -import org.jetbrains.exposed.sql.deleteAll -import org.jetbrains.exposed.sql.deleteWhere -import org.jetbrains.exposed.sql.select -import org.springframework.stereotype.Repository - -@Repository -class JwtRefreshTokenQueryServiceImpl : JwtRefreshTokenQueryService { - override suspend fun findById(id: Long): JwtRefreshToken = - JwtRefreshTokens.select { JwtRefreshTokens.id.eq(id) } - .singleOr { FailedToGetResourcesException("id: $id is a duplicate or does not exist.", it) } - .toJwtRefreshToken() - - override suspend fun findByToken(token: String): JwtRefreshToken = - JwtRefreshTokens.select { JwtRefreshTokens.refreshToken.eq(token) } - .singleOr { FailedToGetResourcesException("token: $token is a duplicate or does not exist.", it) } - .toJwtRefreshToken() - - override suspend fun findByUserId(userId: Long): JwtRefreshToken = - JwtRefreshTokens.select { JwtRefreshTokens.userId.eq(userId) } - .singleOr { FailedToGetResourcesException("userId: $userId is a duplicate or does not exist.", it) } - .toJwtRefreshToken() - - override suspend fun deleteById(id: Long) { - JwtRefreshTokens.deleteWhere { JwtRefreshTokens.id eq id } - } - - override suspend fun deleteByToken(token: String) { - JwtRefreshTokens.deleteWhere { refreshToken eq token } - } - - override suspend fun deleteByUserId(userId: Long) { - JwtRefreshTokens.deleteWhere { JwtRefreshTokens.userId eq userId } - } - - override suspend fun deleteAll() { - JwtRefreshTokens.deleteAll() - } -} diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/JwtRefreshTokenRepository.kt b/src/main/kotlin/dev/usbharu/hideout/repository/JwtRefreshTokenRepository.kt deleted file mode 100644 index 81c6aa35..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/repository/JwtRefreshTokenRepository.kt +++ /dev/null @@ -1,15 +0,0 @@ -package dev.usbharu.hideout.repository - -import dev.usbharu.hideout.domain.model.hideout.entity.JwtRefreshToken -import org.springframework.stereotype.Repository - -@Repository -interface JwtRefreshTokenRepository { - suspend fun generateId(): Long - - suspend fun save(token: JwtRefreshToken) - - suspend fun findById(id: Long): JwtRefreshToken? - - suspend fun delete(token: JwtRefreshToken) -} diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/JwtRefreshTokenRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/JwtRefreshTokenRepositoryImpl.kt deleted file mode 100644 index 234703e9..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/repository/JwtRefreshTokenRepositoryImpl.kt +++ /dev/null @@ -1,71 +0,0 @@ -package dev.usbharu.hideout.repository - -import dev.usbharu.hideout.domain.model.hideout.entity.JwtRefreshToken -import dev.usbharu.hideout.service.core.IdGenerateService -import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq -import org.jetbrains.exposed.sql.transactions.transaction -import org.springframework.stereotype.Repository -import java.time.Instant - -@Repository -class JwtRefreshTokenRepositoryImpl( - private val database: Database, - private val idGenerateService: IdGenerateService -) : - JwtRefreshTokenRepository { - - init { - transaction(database) { - SchemaUtils.create(JwtRefreshTokens) - SchemaUtils.createMissingTablesAndColumns(JwtRefreshTokens) - } - } - - override suspend fun generateId(): Long = idGenerateService.generateId() - - override suspend fun save(token: JwtRefreshToken) { - if (JwtRefreshTokens.select { JwtRefreshTokens.id.eq(token.id) }.empty()) { - JwtRefreshTokens.insert { - it[id] = token.id - it[userId] = token.userId - it[refreshToken] = token.refreshToken - it[createdAt] = token.createdAt.toEpochMilli() - it[expiresAt] = token.expiresAt.toEpochMilli() - } - } else { - JwtRefreshTokens.update({ JwtRefreshTokens.id eq token.id }) { - it[userId] = token.userId - it[refreshToken] = token.refreshToken - it[createdAt] = token.createdAt.toEpochMilli() - it[expiresAt] = token.expiresAt.toEpochMilli() - } - } - } - - override suspend fun findById(id: Long): JwtRefreshToken? = - JwtRefreshTokens.select { JwtRefreshTokens.id.eq(id) }.singleOrNull()?.toJwtRefreshToken() - - override suspend fun delete(token: JwtRefreshToken) { - JwtRefreshTokens.deleteWhere { id eq token.id } - } -} - -fun ResultRow.toJwtRefreshToken(): JwtRefreshToken { - return JwtRefreshToken( - this[JwtRefreshTokens.id], - this[JwtRefreshTokens.userId], - this[JwtRefreshTokens.refreshToken], - Instant.ofEpochMilli(this[JwtRefreshTokens.createdAt]), - Instant.ofEpochMilli(this[JwtRefreshTokens.expiresAt]) - ) -} - -object JwtRefreshTokens : Table("jwt_refresh_tokens") { - val id = long("id") - val userId = long("user_id") - val refreshToken = varchar("refresh_token", 1000) - val createdAt = long("created_at") - val expiresAt = long("expires_at") - override val primaryKey = PrimaryKey(id) -} diff --git a/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthService.kt b/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthService.kt index 9630f8fa..556fb618 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthService.kt @@ -11,5 +11,4 @@ interface UserAuthService { suspend fun generateKeyPair(): KeyPair - suspend fun verifyAccount(username: String, password: String): Boolean } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthServiceImpl.kt index b817cb35..f059db4a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthServiceImpl.kt @@ -1,6 +1,5 @@ package dev.usbharu.hideout.service.user -import dev.usbharu.hideout.config.ApplicationConfig import dev.usbharu.hideout.query.UserQueryService import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder import org.springframework.stereotype.Service @@ -9,8 +8,7 @@ import java.util.* @Service class UserAuthServiceImpl( - val userQueryService: UserQueryService, - private val applicationConfig: ApplicationConfig + val userQueryService: UserQueryService ) : UserAuthService { override fun hash(password: String): String = BCryptPasswordEncoder().encode(password) @@ -20,11 +18,6 @@ class UserAuthServiceImpl( return true } - override suspend fun verifyAccount(username: String, password: String): Boolean { - val userEntity = userQueryService.findByNameAndDomain(username, applicationConfig.url.host) - return userEntity.password == hash(password) - } - override suspend fun generateKeyPair(): KeyPair { val keyPairGenerator = KeyPairGenerator.getInstance("RSA") keyPairGenerator.initialize(keySize) diff --git a/src/test/kotlin/dev/usbharu/hideout/repository/JwtRefreshTokenRepositoryImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/repository/JwtRefreshTokenRepositoryImplTest.kt deleted file mode 100644 index ca726753..00000000 --- a/src/test/kotlin/dev/usbharu/hideout/repository/JwtRefreshTokenRepositoryImplTest.kt +++ /dev/null @@ -1,100 +0,0 @@ -@file:OptIn(ExperimentalCoroutinesApi::class, ExperimentalCoroutinesApi::class) - -package dev.usbharu.hideout.repository - -import dev.usbharu.hideout.domain.model.hideout.entity.JwtRefreshToken -import dev.usbharu.hideout.service.core.IdGenerateService -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.runTest -import org.jetbrains.exposed.sql.Database -import org.jetbrains.exposed.sql.SchemaUtils -import org.jetbrains.exposed.sql.insert -import org.jetbrains.exposed.sql.select -import org.jetbrains.exposed.sql.transactions.TransactionManager -import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction -import org.jetbrains.exposed.sql.transactions.transaction -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import java.time.Clock -import java.time.Instant -import java.time.ZoneId -import java.time.temporal.ChronoUnit -import kotlin.test.assertEquals - -class JwtRefreshTokenRepositoryImplTest { - - lateinit var db: Database - - @BeforeEach - fun setUp() { - db = Database.connect("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1") - transaction(db) { - SchemaUtils.create(JwtRefreshTokens) - } - } - - @AfterEach - fun tearDown() { - transaction(db) { - SchemaUtils.drop(JwtRefreshTokens) - } - TransactionManager.closeAndUnregister(db) - } - - @Test - fun `save 存在しない場合はinsertする`() = runTest { - val repository = JwtRefreshTokenRepositoryImpl( - db, - object : IdGenerateService { - override suspend fun generateId(): Long { - TODO("Not yet implemented") - } - } - ) - val now = Instant.now(Clock.tickMillis(ZoneId.systemDefault())) - val expiresAt = now.plus(10, ChronoUnit.MINUTES) - - val expect = JwtRefreshToken(1L, 2L, "refreshToken", now, expiresAt) - newSuspendedTransaction { - repository.save(expect) - val actual = repository.findById(1L) - assertEquals(expect, actual) - } - } - - @Test - fun `save 存在する場合はupdateする`() = runTest { - val repository = JwtRefreshTokenRepositoryImpl( - db, - object : IdGenerateService { - override suspend fun generateId(): Long { - TODO("Not yet implemented") - } - } - ) - newSuspendedTransaction { - JwtRefreshTokens.insert { - it[id] = 1L - it[userId] = 2L - it[refreshToken] = "refreshToken1" - it[createdAt] = Instant.now().toEpochMilli() - it[expiresAt] = Instant.now().plus(10, ChronoUnit.MINUTES).toEpochMilli() - } - repository.save( - JwtRefreshToken( - id = 1L, - userId = 2L, - refreshToken = "refreshToken2", - createdAt = Instant.now(), - expiresAt = Instant.now().plus(10, ChronoUnit.MINUTES) - ) - ) - } - - transaction { - val toJwtRefreshToken = JwtRefreshTokens.select { JwtRefreshTokens.id.eq(1L) }.single().toJwtRefreshToken() - assertEquals("refreshToken2", toJwtRefreshToken.refreshToken) - } - } -} From 74b32252adf9358eeeb3d6aa7db9589e17d49583 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 30 Sep 2023 13:26:44 +0900 Subject: [PATCH 2/8] chore: update exposed --- build.gradle.kts | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 17396d06..10f7d877 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -111,6 +111,8 @@ dependencies { implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("org.springframework.security:spring-security-oauth2-jose") implementation("org.springframework.boot:spring-boot-starter-data-mongodb") + implementation("org.jetbrains.exposed:exposed-spring-boot-starter:0.44.0") + implementation("io.ktor:ktor-client-logging-jvm:$ktor_version") diff --git a/gradle.properties b/gradle.properties index 31697ea3..a7ffe13f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ ktor_version=2.3.0 kotlin_version=1.8.21 logback_version=1.4.6 kotlin.code.style=official -exposed_version=0.41.1 +exposed_version=0.44.0 h2_version=2.1.214 koin_version=3.4.3 org.gradle.parallel=true From 67a6b8c32187b3852dfdd58841120999b61969e3 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 30 Sep 2023 13:41:42 +0900 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20Exposed=E3=81=A7=E5=88=9D=E6=9C=9F?= =?UTF-8?q?=E5=8C=96=E3=82=92=E8=87=AA=E5=8B=95=E3=81=A7=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/usbharu/hideout/config/SpringConfig.kt | 12 ------------ .../hideout/repository/MetaRepositoryImpl.kt | 15 +++++---------- .../hideout/repository/PostRepositoryImpl.kt | 10 +--------- .../hideout/repository/ReactionRepositoryImpl.kt | 8 -------- .../repository/RegisteredClientRepositoryImpl.kt | 9 +-------- .../hideout/repository/UserRepositoryImpl.kt | 13 +------------ .../ExposedOAuth2AuthorizationConsentService.kt | 9 --------- .../auth/ExposedOAuth2AuthorizationService.kt | 8 -------- src/main/resources/application.yml | 3 ++- 9 files changed, 10 insertions(+), 77 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/config/SpringConfig.kt b/src/main/kotlin/dev/usbharu/hideout/config/SpringConfig.kt index 63825da0..50ae6f03 100644 --- a/src/main/kotlin/dev/usbharu/hideout/config/SpringConfig.kt +++ b/src/main/kotlin/dev/usbharu/hideout/config/SpringConfig.kt @@ -1,9 +1,7 @@ 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 import java.net.URL @@ -15,16 +13,6 @@ class SpringConfig { @Autowired lateinit var config: ApplicationConfig - - @Bean - fun database(): Database { - return Database.connect( - url = dbConfig.url, - driver = dbConfig.driver, - user = dbConfig.user, - password = dbConfig.password - ) - } } @ConfigurationProperties("hideout") diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/MetaRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/MetaRepositoryImpl.kt index 07200178..03864cfb 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/MetaRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/MetaRepositoryImpl.kt @@ -1,20 +1,15 @@ package dev.usbharu.hideout.repository import dev.usbharu.hideout.domain.model.hideout.entity.Jwt -import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.transaction +import org.jetbrains.exposed.sql.Table +import org.jetbrains.exposed.sql.insert +import org.jetbrains.exposed.sql.select +import org.jetbrains.exposed.sql.update import org.springframework.stereotype.Repository import java.util.* @Repository -class MetaRepositoryImpl(private val database: Database) : MetaRepository { - - init { - transaction(database) { - SchemaUtils.create(Meta) - SchemaUtils.createMissingTablesAndColumns(Meta) - } - } +class MetaRepositoryImpl : MetaRepository { override suspend fun save(meta: dev.usbharu.hideout.domain.model.hideout.entity.Meta) { if (Meta.select { Meta.id eq 1 }.empty()) { diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/PostRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/PostRepositoryImpl.kt index 08c7d279..e4aad089 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/PostRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/PostRepositoryImpl.kt @@ -6,18 +6,10 @@ import dev.usbharu.hideout.exception.FailedToGetResourcesException import dev.usbharu.hideout.service.core.IdGenerateService import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq -import org.jetbrains.exposed.sql.transactions.transaction import org.springframework.stereotype.Repository @Repository -class PostRepositoryImpl(database: Database, private val idGenerateService: IdGenerateService) : PostRepository { - - init { - transaction(database) { - SchemaUtils.create(Posts) - SchemaUtils.createMissingTablesAndColumns(Posts) - } - } +class PostRepositoryImpl(private val idGenerateService: IdGenerateService) : PostRepository { override suspend fun generateId(): Long = idGenerateService.generateId() diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt index 26fc3e52..866feaf3 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt @@ -5,21 +5,13 @@ import dev.usbharu.hideout.service.core.IdGenerateService import org.jetbrains.exposed.dao.id.LongIdTable import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq -import org.jetbrains.exposed.sql.transactions.transaction import org.springframework.stereotype.Repository @Repository class ReactionRepositoryImpl( - private val database: Database, private val idGenerateService: IdGenerateService ) : ReactionRepository { - init { - transaction(database) { - SchemaUtils.create(Reactions) - SchemaUtils.createMissingTablesAndColumns(Reactions) - } - } override suspend fun generateId(): Long = idGenerateService.generateId() diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt index 88aa66c2..5acfd3fc 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt @@ -10,7 +10,6 @@ import dev.usbharu.hideout.service.auth.ExposedOAuth2AuthorizationService import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.javatime.CurrentTimestamp import org.jetbrains.exposed.sql.javatime.timestamp -import org.jetbrains.exposed.sql.transactions.transaction import org.slf4j.LoggerFactory import org.springframework.security.jackson2.SecurityJackson2Modules import org.springframework.security.oauth2.core.AuthorizationGrantType @@ -27,14 +26,8 @@ import java.time.Instant import org.springframework.security.oauth2.server.authorization.client.RegisteredClient as SpringRegisteredClient @Repository -class RegisteredClientRepositoryImpl(private val database: Database) : RegisteredClientRepository { +class RegisteredClientRepositoryImpl : RegisteredClientRepository { - init { - transaction(database) { - SchemaUtils.create(RegisteredClient) - SchemaUtils.createMissingTablesAndColumns(RegisteredClient) - } - } override fun save(registeredClient: SpringRegisteredClient?) { requireNotNull(registeredClient) diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/UserRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/UserRepositoryImpl.kt index 8fdbebc1..a5cbb82c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/UserRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/UserRepositoryImpl.kt @@ -6,23 +6,12 @@ import dev.usbharu.hideout.service.core.IdGenerateService import org.jetbrains.exposed.dao.id.LongIdTable import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq -import org.jetbrains.exposed.sql.transactions.transaction import org.springframework.stereotype.Repository import java.time.Instant @Repository -class UserRepositoryImpl(private val database: Database, private val idGenerateService: IdGenerateService) : +class UserRepositoryImpl(private val idGenerateService: IdGenerateService) : UserRepository { - init { - transaction(database) { - SchemaUtils.create(Users) - SchemaUtils.create(UsersFollowers) - SchemaUtils.createMissingTablesAndColumns(Users) - SchemaUtils.createMissingTablesAndColumns(UsersFollowers) - SchemaUtils.create(FollowRequests) - SchemaUtils.createMissingTablesAndColumns(FollowRequests) - } - } override suspend fun save(user: User): User { val singleOrNull = Users.select { Users.id eq user.id }.singleOrNull() diff --git a/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationConsentService.kt b/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationConsentService.kt index b3b0d420..469de633 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationConsentService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationConsentService.kt @@ -4,7 +4,6 @@ import dev.usbharu.hideout.service.core.Transaction import kotlinx.coroutines.runBlocking import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq -import org.jetbrains.exposed.sql.transactions.transaction import org.springframework.security.core.authority.SimpleGrantedAuthority import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationConsentService import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository @@ -15,17 +14,9 @@ import org.springframework.security.oauth2.server.authorization.OAuth2Authorizat class ExposedOAuth2AuthorizationConsentService( private val registeredClientRepository: RegisteredClientRepository, private val transaction: Transaction, - private val database: Database ) : OAuth2AuthorizationConsentService { - init { - transaction(database) { - SchemaUtils.create(OAuth2AuthorizationConsent) - SchemaUtils.createMissingTablesAndColumns(OAuth2AuthorizationConsent) - } - } - override fun save(authorizationConsent: AuthorizationConsent?) = runBlocking { requireNotNull(authorizationConsent) transaction.transaction { diff --git a/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt b/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt index 13ea2820..61e8d41d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt @@ -10,7 +10,6 @@ import kotlinx.coroutines.runBlocking import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.javatime.timestamp -import org.jetbrains.exposed.sql.transactions.transaction import org.springframework.security.jackson2.CoreJackson2Module import org.springframework.security.jackson2.SecurityJackson2Modules import org.springframework.security.oauth2.core.* @@ -29,16 +28,9 @@ import org.springframework.stereotype.Service class ExposedOAuth2AuthorizationService( private val registeredClientRepository: RegisteredClientRepository, private val transaction: Transaction, - private val database: Database ) : OAuth2AuthorizationService { - init { - transaction(database) { - SchemaUtils.create(Authorization) - SchemaUtils.createMissingTablesAndColumns(Authorization) - } - } @Suppress("LongMethod", "CyclomaticComplexMethod") override fun save(authorization: OAuth2Authorization?): Unit = runBlocking { diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 889d71f4..1e16cf88 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -33,8 +33,9 @@ spring: h2: console: enabled: true + exposed: + generate-ddl: true server: - tomcat: basedir: tomcat accesslog: From d2245c8d012bf11422d77527b8b568cc025d59ac Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 30 Sep 2023 13:44:10 +0900 Subject: [PATCH 4/8] =?UTF-8?q?feat:=20=E4=B8=8D=E8=A6=81=E3=81=AA?= =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 1e16cf88..bcf7e661 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,10 +1,5 @@ hideout: url: "https://test-hideout.usbharu.dev" - database: - url: "jdbc:h2:./test-dev2;MODE=POSTGRESQL" - driver: "org.h2.Driver" - user: "" - password: "" job-queue: type: "nosql" security: From 4be4603f7abb24c20732dbe4b8584bdc9c366f6f Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 30 Sep 2023 13:48:24 +0900 Subject: [PATCH 5/8] =?UTF-8?q?refactor:=20ID=E7=94=9F=E6=88=90=E3=82=92?= =?UTF-8?q?=E5=85=A8=E3=81=A6IdGenerateService=E3=81=A7=E8=A1=8C=E3=81=86?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/repository/MongoTimelineRepositoryWrapper.kt | 1 - .../dev/usbharu/hideout/repository/PostRepository.kt | 1 - .../dev/usbharu/hideout/repository/PostRepositoryImpl.kt | 2 -- .../dev/usbharu/hideout/repository/ReactionRepository.kt | 1 - .../usbharu/hideout/repository/ReactionRepositoryImpl.kt | 2 -- .../dev/usbharu/hideout/repository/TimelineRepository.kt | 1 - .../dev/usbharu/hideout/service/ap/APNoteService.kt | 6 ++++-- .../dev/usbharu/hideout/service/post/PostServiceImpl.kt | 6 ++++-- .../dev/usbharu/hideout/service/post/TimelineService.kt | 8 +++++--- .../hideout/service/reaction/ReactionServiceImpl.kt | 8 +++++--- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/MongoTimelineRepositoryWrapper.kt b/src/main/kotlin/dev/usbharu/hideout/repository/MongoTimelineRepositoryWrapper.kt index a3e31b6f..b103dda0 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/MongoTimelineRepositoryWrapper.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/MongoTimelineRepositoryWrapper.kt @@ -13,7 +13,6 @@ class MongoTimelineRepositoryWrapper( private val idGenerateService: IdGenerateService ) : TimelineRepository { - override suspend fun generateId(): Long = idGenerateService.generateId() override suspend fun save(timeline: Timeline): Timeline { return withContext(Dispatchers.IO) { diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/PostRepository.kt b/src/main/kotlin/dev/usbharu/hideout/repository/PostRepository.kt index 8011f282..dc8c2dc8 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/PostRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/PostRepository.kt @@ -6,7 +6,6 @@ import org.springframework.stereotype.Repository @Suppress("LongParameterList") @Repository interface PostRepository { - suspend fun generateId(): Long suspend fun save(post: Post): Post suspend fun delete(id: Long) suspend fun findById(id: Long): Post diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/PostRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/PostRepositoryImpl.kt index e4aad089..2b72cec8 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/PostRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/PostRepositoryImpl.kt @@ -11,8 +11,6 @@ import org.springframework.stereotype.Repository @Repository class PostRepositoryImpl(private val idGenerateService: IdGenerateService) : PostRepository { - override suspend fun generateId(): Long = idGenerateService.generateId() - override suspend fun save(post: Post): Post { val singleOrNull = Posts.select { Posts.id eq post.id }.singleOrNull() if (singleOrNull == null) { diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepository.kt b/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepository.kt index d98a0c84..1e1ef389 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepository.kt @@ -5,7 +5,6 @@ import org.springframework.stereotype.Repository @Repository interface ReactionRepository { - suspend fun generateId(): Long suspend fun save(reaction: Reaction): Reaction suspend fun delete(reaction: Reaction): Reaction } diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt index 866feaf3..03a65549 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt @@ -13,8 +13,6 @@ class ReactionRepositoryImpl( ) : ReactionRepository { - override suspend fun generateId(): Long = idGenerateService.generateId() - override suspend fun save(reaction: Reaction): Reaction { if (Reactions.select { Reactions.id eq reaction.id }.empty()) { Reactions.insert { diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/TimelineRepository.kt b/src/main/kotlin/dev/usbharu/hideout/repository/TimelineRepository.kt index 76e9755c..54f2c68e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/TimelineRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/TimelineRepository.kt @@ -3,7 +3,6 @@ package dev.usbharu.hideout.repository import dev.usbharu.hideout.domain.model.hideout.entity.Timeline interface TimelineRepository { - suspend fun generateId(): Long suspend fun save(timeline: Timeline): Timeline suspend fun saveAll(timelines: List): List suspend fun findByUserId(id: Long): List diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt index 2b6ce229..6eaf154b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt @@ -16,6 +16,7 @@ import dev.usbharu.hideout.query.FollowerQueryService import dev.usbharu.hideout.query.PostQueryService import dev.usbharu.hideout.query.UserQueryService import dev.usbharu.hideout.repository.PostRepository +import dev.usbharu.hideout.service.core.IdGenerateService import dev.usbharu.hideout.service.job.JobQueueParentService import dev.usbharu.hideout.service.post.PostCreateInterceptor import dev.usbharu.hideout.service.post.PostService @@ -49,7 +50,8 @@ class APNoteServiceImpl( private val postQueryService: PostQueryService, @Qualifier("activitypub") private val objectMapper: ObjectMapper, private val applicationConfig: ApplicationConfig, - private val postService: PostService + private val postService: PostService, + private val idGenerateService: IdGenerateService ) : APNoteService, PostCreateInterceptor { @@ -171,7 +173,7 @@ class APNoteServiceImpl( postService.createRemote( Post.of( - id = postRepository.generateId(), + id = idGenerateService.generateId(), userId = person.second.id, overview = null, text = note.content.orEmpty(), diff --git a/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt index a86c2227..99f9e784 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt @@ -5,6 +5,7 @@ import dev.usbharu.hideout.domain.model.hideout.entity.Post import dev.usbharu.hideout.exception.UserNotFoundException import dev.usbharu.hideout.repository.PostRepository import dev.usbharu.hideout.repository.UserRepository +import dev.usbharu.hideout.service.core.IdGenerateService import org.springframework.stereotype.Service import java.time.Instant import java.util.* @@ -13,7 +14,8 @@ import java.util.* class PostServiceImpl( private val postRepository: PostRepository, private val userRepository: UserRepository, - private val timelineService: TimelineService + private val timelineService: TimelineService, + private val idGenerateService: IdGenerateService ) : PostService { private val interceptors = Collections.synchronizedList(mutableListOf()) @@ -36,7 +38,7 @@ class PostServiceImpl( private suspend fun internalCreate(post: PostCreateDto, isLocal: Boolean): Post { val user = userRepository.findById(post.userId) ?: throw UserNotFoundException("${post.userId} was not found") - val id = postRepository.generateId() + val id = idGenerateService.generateId() val createPost = Post.of( id = id, userId = post.userId, diff --git a/src/main/kotlin/dev/usbharu/hideout/service/post/TimelineService.kt b/src/main/kotlin/dev/usbharu/hideout/service/post/TimelineService.kt index 97f83a08..08ee2dc4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/post/TimelineService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/post/TimelineService.kt @@ -6,13 +6,15 @@ import dev.usbharu.hideout.domain.model.hideout.entity.Visibility import dev.usbharu.hideout.query.FollowerQueryService import dev.usbharu.hideout.query.UserQueryService import dev.usbharu.hideout.repository.TimelineRepository +import dev.usbharu.hideout.service.core.IdGenerateService import org.springframework.stereotype.Service @Service class TimelineService( private val followerQueryService: FollowerQueryService, private val userQueryService: UserQueryService, - private val timelineRepository: TimelineRepository + private val timelineRepository: TimelineRepository, + private val idGenerateService: IdGenerateService ) { suspend fun publishTimeline(post: Post, isLocal: Boolean) { val findFollowersById = followerQueryService.findFollowersById(post.userId).toMutableList() @@ -23,7 +25,7 @@ class TimelineService( } val timelines = findFollowersById.map { Timeline( - id = timelineRepository.generateId(), + id = idGenerateService.generateId(), userId = it.id, timelineId = 0, postId = post.id, @@ -39,7 +41,7 @@ class TimelineService( if (post.visibility == Visibility.PUBLIC) { timelines.add( Timeline( - id = timelineRepository.generateId(), + id = idGenerateService.generateId(), userId = 0, timelineId = 0, postId = post.id, diff --git a/src/main/kotlin/dev/usbharu/hideout/service/reaction/ReactionServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/reaction/ReactionServiceImpl.kt index 312c182b..ce3fece1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/reaction/ReactionServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/reaction/ReactionServiceImpl.kt @@ -4,18 +4,20 @@ import dev.usbharu.hideout.domain.model.hideout.entity.Reaction import dev.usbharu.hideout.query.ReactionQueryService import dev.usbharu.hideout.repository.ReactionRepository import dev.usbharu.hideout.service.ap.APReactionService +import dev.usbharu.hideout.service.core.IdGenerateService import org.springframework.stereotype.Service @Service class ReactionServiceImpl( private val reactionRepository: ReactionRepository, private val apReactionService: APReactionService, - private val reactionQueryService: ReactionQueryService + private val reactionQueryService: ReactionQueryService, + private val idGenerateService: IdGenerateService ) : ReactionService { override suspend fun receiveReaction(name: String, domain: String, userId: Long, postId: Long) { if (reactionQueryService.reactionAlreadyExist(postId, userId, 0).not()) { reactionRepository.save( - Reaction(reactionRepository.generateId(), 0, postId, userId) + Reaction(idGenerateService.generateId(), 0, postId, userId) ) } } @@ -25,7 +27,7 @@ class ReactionServiceImpl( // delete reactionQueryService.deleteByPostIdAndUserId(postId, userId) } else { - val reaction = Reaction(reactionRepository.generateId(), 0, postId, userId) + val reaction = Reaction(idGenerateService.generateId(), 0, postId, userId) reactionRepository.save(reaction) apReactionService.reaction(reaction) } From 26abc2759fa00f8ff347c5c9f0ba30a9332ee973 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 30 Sep 2023 13:50:29 +0900 Subject: [PATCH 6/8] =?UTF-8?q?test:=20=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt index 4c40d000..69605b35 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt @@ -89,7 +89,8 @@ class APNoteServiceImplTest { postQueryService = mock(), objectMapper = objectMapper, applicationConfig = testApplicationConfig, - postService = mock() + postService = mock(), + idGenerateService = mock() ) val postEntity = Post.of( 1L, @@ -123,7 +124,8 @@ class APNoteServiceImplTest { postQueryService = mock(), objectMapper = objectMapper, applicationConfig = testApplicationConfig, - postService = mock() + postService = mock(), + idGenerateService = mock() ) activityPubNoteService.createNoteJob( JobProps( From ae8f867ad482812fd3029033f13d37dca5a9638b Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 30 Sep 2023 13:51:55 +0900 Subject: [PATCH 7/8] =?UTF-8?q?style:=20=E3=82=B9=E3=82=BF=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=82=92=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt | 1 - .../usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt | 1 - .../hideout/service/auth/ExposedOAuth2AuthorizationService.kt | 1 - .../kotlin/dev/usbharu/hideout/service/user/UserAuthService.kt | 1 - 4 files changed, 4 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt index 03a65549..34c25d82 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt @@ -12,7 +12,6 @@ class ReactionRepositoryImpl( private val idGenerateService: IdGenerateService ) : ReactionRepository { - override suspend fun save(reaction: Reaction): Reaction { if (Reactions.select { Reactions.id eq reaction.id }.empty()) { Reactions.insert { diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt index 5acfd3fc..81632609 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt @@ -28,7 +28,6 @@ import org.springframework.security.oauth2.server.authorization.client.Registere @Repository class RegisteredClientRepositoryImpl : RegisteredClientRepository { - override fun save(registeredClient: SpringRegisteredClient?) { requireNotNull(registeredClient) val singleOrNull = RegisteredClient.select { RegisteredClient.id eq registeredClient.id }.singleOrNull() diff --git a/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt b/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt index 61e8d41d..b3c3a2a2 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt @@ -31,7 +31,6 @@ class ExposedOAuth2AuthorizationService( ) : OAuth2AuthorizationService { - @Suppress("LongMethod", "CyclomaticComplexMethod") override fun save(authorization: OAuth2Authorization?): Unit = runBlocking { requireNotNull(authorization) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthService.kt b/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthService.kt index 556fb618..0028cdfb 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthService.kt @@ -10,5 +10,4 @@ interface UserAuthService { suspend fun usernameAlreadyUse(username: String): Boolean suspend fun generateKeyPair(): KeyPair - } From b37afe46ca6742500140d06eac04ee82b3e85366 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 30 Sep 2023 13:59:45 +0900 Subject: [PATCH 8/8] =?UTF-8?q?=E3=81=8F=E3=81=9D=E3=81=A3=E3=81=9F?= =?UTF-8?q?=E3=82=8CLint=E3=82=92=E9=BB=99=E3=82=89=E3=81=9B=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detekt.yml | 3 +++ .../hideout/service/job/KjobMongoJobQueueParentService.kt | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/detekt.yml b/detekt.yml index 21fab9ff..26af6de1 100644 --- a/detekt.yml +++ b/detekt.yml @@ -157,3 +157,6 @@ potential-bugs: ElseCaseInsteadOfExhaustiveWhen: active: true + + HasPlatformType: + active: false diff --git a/src/main/kotlin/dev/usbharu/hideout/service/job/KjobMongoJobQueueParentService.kt b/src/main/kotlin/dev/usbharu/hideout/service/job/KjobMongoJobQueueParentService.kt index f76e7e18..c532d2e2 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/job/KjobMongoJobQueueParentService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/job/KjobMongoJobQueueParentService.kt @@ -10,8 +10,6 @@ import org.springframework.stereotype.Service @Service @ConditionalOnProperty(name = ["hideout.job-queue.type"], havingValue = "nosql") class KjobMongoJobQueueParentService : JobQueueParentService { - override fun init(jobDefines: List) = Unit - private val kjob = kjob(Mongo) { connectionString = "mongodb://localhost" databaseName = "kjob" @@ -21,6 +19,8 @@ class KjobMongoJobQueueParentService : JobQueueParentService { isWorker = false }.start() + override fun init(jobDefines: List) = Unit + override suspend fun schedule(job: J, block: ScheduleContext.(J) -> Unit) { kjob.schedule(job, block) }