diff --git a/src/main/kotlin/dev/usbharu/hideout/Application.kt b/src/main/kotlin/dev/usbharu/hideout/Application.kt index 149a839e..d5ecffdc 100644 --- a/src/main/kotlin/dev/usbharu/hideout/Application.kt +++ b/src/main/kotlin/dev/usbharu/hideout/Application.kt @@ -12,6 +12,7 @@ import dev.usbharu.hideout.repository.* import dev.usbharu.hideout.routing.register import dev.usbharu.hideout.service.IPostService import dev.usbharu.hideout.service.IUserAuthService +import dev.usbharu.hideout.service.IdGenerateService import dev.usbharu.hideout.service.TwitterSnowflakeIdGenerateService import dev.usbharu.hideout.service.activitypub.* import dev.usbharu.hideout.service.impl.PostService @@ -57,7 +58,7 @@ fun Application.parent() { ) } - single { UserRepository(get()) } + single { UserRepository(get(),get()) } single { UserAuthService(get()) } single { HttpSignatureVerifyServiceImpl(get()) } single { @@ -82,7 +83,8 @@ fun Application.parent() { single { ActivityPubUserServiceImpl(get(), get(), get()) } single { ActivityPubNoteServiceImpl(get(), get(), get()) } single { PostService(get(), get()) } - single { PostRepositoryImpl(get(), TwitterSnowflakeIdGenerateService) } + single { PostRepositoryImpl(get(), get()) } + single {TwitterSnowflakeIdGenerateService} } diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/IUserRepository.kt b/src/main/kotlin/dev/usbharu/hideout/repository/IUserRepository.kt index c8a0b1a3..58d56ba9 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/IUserRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/IUserRepository.kt @@ -29,4 +29,6 @@ interface IUserRepository { suspend fun createFollower(id: Long, follower: Long) suspend fun deleteFollower(id: Long, follower: Long) suspend fun findFollowersById(id: Long): List + + suspend fun nextId():Long } diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/UserRepository.kt b/src/main/kotlin/dev/usbharu/hideout/repository/UserRepository.kt index f77c17ef..ceb6db1b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/UserRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/UserRepository.kt @@ -2,6 +2,7 @@ package dev.usbharu.hideout.repository import dev.usbharu.hideout.domain.model.User import dev.usbharu.hideout.domain.model.UsersFollowers +import dev.usbharu.hideout.service.IdGenerateService import kotlinx.coroutines.Dispatchers import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq @@ -9,7 +10,7 @@ import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransacti import org.jetbrains.exposed.sql.transactions.transaction import java.time.Instant -class UserRepository(private val database: Database) : IUserRepository { +class UserRepository(private val database: Database,private val idGenerateService: IdGenerateService) : IUserRepository { init { transaction(database) { SchemaUtils.create(Users) @@ -185,6 +186,10 @@ class UserRepository(private val database: Database) : IUserRepository { Users.selectAll().limit(limit, offset).map { it.toUser() } } } + + override suspend fun nextId(): Long { + return idGenerateService.generateId() + } } object Users : Table("users") { diff --git a/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt b/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt index 419a0ae4..08a1bdac 100644 --- a/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt @@ -81,6 +81,10 @@ class KtorKeyMapTest { TODO("Not yet implemented") } + override suspend fun nextId(): Long { + TODO("Not yet implemented") + } + }) ktorKeyMap.getPrivateKey("test") diff --git a/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt b/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt index 4ddc8e9c..43dc236e 100644 --- a/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt @@ -4,6 +4,7 @@ package dev.usbharu.hideout.repository import dev.usbharu.hideout.domain.model.User import dev.usbharu.hideout.domain.model.UsersFollowers +import dev.usbharu.hideout.service.IdGenerateService import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import org.jetbrains.exposed.sql.Database @@ -43,7 +44,11 @@ class UserRepositoryTest { @Test fun `findFollowersById フォロワー一覧を取得`() = runTest { - val userRepository = UserRepository(db) + val userRepository = UserRepository(db, object : IdGenerateService { + override suspend fun generateId(): Long { + TODO("Not yet implemented") + } + }) val user = userRepository.save( User( id = 0L, @@ -99,7 +104,11 @@ class UserRepositoryTest { @Test fun `createFollower フォロワー追加`() = runTest { - val userRepository = UserRepository(db) + val userRepository = UserRepository(db, object : IdGenerateService { + override suspend fun generateId(): Long { + TODO("Not yet implemented") + } + }) val user = userRepository.save( User(0L, "test",