diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/IUserRepository.kt b/src/main/kotlin/dev/usbharu/hideout/repository/IUserRepository.kt index 73ac26a4..c8a0b1a3 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/IUserRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/IUserRepository.kt @@ -3,7 +3,7 @@ package dev.usbharu.hideout.repository import dev.usbharu.hideout.domain.model.User interface IUserRepository { - suspend fun create(user: User): User + suspend fun save(user: User): User suspend fun findById(id: Long): User? @@ -17,7 +17,8 @@ interface IUserRepository { suspend fun findByUrls(urls: List): List - suspend fun update(userEntity: User) + @Deprecated("", ReplaceWith("save(userEntity)")) + suspend fun update(userEntity: User) = save(userEntity) suspend fun delete(id: Long) diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/UserRepository.kt b/src/main/kotlin/dev/usbharu/hideout/repository/UserRepository.kt index 7e0487b1..a416ff5d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/UserRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/UserRepository.kt @@ -1,15 +1,13 @@ package dev.usbharu.hideout.repository -import dev.usbharu.hideout.domain.model.* +import dev.usbharu.hideout.domain.model.User +import dev.usbharu.hideout.domain.model.UsersFollowers import kotlinx.coroutines.Dispatchers import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction import org.jetbrains.exposed.sql.transactions.transaction import java.time.Instant -import java.time.LocalDateTime -import java.time.ZoneId -import java.time.ZoneOffset class UserRepository(private val database: Database) : IUserRepository { init { @@ -21,12 +19,13 @@ class UserRepository(private val database: Database) : IUserRepository { } } + @Deprecated("", ReplaceWith("toUser()")) private fun ResultRow.toUserEntity(): User = toUser() suspend fun query(block: suspend () -> T): T = newSuspendedTransaction(Dispatchers.IO) { block() } - override suspend fun create(user: User): User { + override suspend fun save(user: User): User { return query { Users.insert { it[id] = user.id diff --git a/src/main/kotlin/dev/usbharu/hideout/service/impl/UserAuthService.kt b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserAuthService.kt index 08235238..0d217de1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/impl/UserAuthService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserAuthService.kt @@ -10,7 +10,6 @@ import java.security.* import java.security.interfaces.RSAPrivateKey import java.security.interfaces.RSAPublicKey import java.time.Instant -import java.time.LocalDateTime import java.util.* class UserAuthService( @@ -43,7 +42,7 @@ class UserAuthService( publicKey = "", createdAt = Instant.now(), ) - val createdUser = userRepository.create(registerUser) + val createdUser = userRepository.save(registerUser) val keyPair = generateKeyPair() val privateKey = keyPair.private as RSAPrivateKey diff --git a/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt index fcbc60cb..09af8fc4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt @@ -42,7 +42,7 @@ class UserService(private val userRepository: IUserRepository) { } suspend fun create(user: User): User { - return userRepository.create(user) + return userRepository.save(user) } suspend fun findFollowersById(id: Long): List { diff --git a/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt b/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt index 87d91ca0..df9265f0 100644 --- a/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt @@ -18,7 +18,7 @@ class ActivityPubKtTest { fun HttpSignTest(): Unit = runBlocking { val ktorKeyMap = KtorKeyMap(object : IUserRepository { - override suspend fun create(user: User): User { + override suspend fun save(user: User): User { TODO("Not yet implemented") } diff --git a/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt b/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt index 204f6c8c..fd3ee6dd 100644 --- a/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt @@ -13,7 +13,7 @@ class KtorKeyMapTest { @Test fun getPrivateKey() { val ktorKeyMap = KtorKeyMap(object : IUserRepository { - override suspend fun create(user: User): User { + override suspend fun save(user: User): User { TODO("Not yet implemented") } diff --git a/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt b/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt index 12f9162e..4ddc8e9c 100644 --- a/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt @@ -16,7 +16,6 @@ import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import java.time.Clock import java.time.Instant -import java.time.LocalDateTime import java.time.ZoneId @@ -45,7 +44,7 @@ class UserRepositoryTest { @Test fun `findFollowersById フォロワー一覧を取得`() = runTest { val userRepository = UserRepository(db) - val user = userRepository.create( + val user = userRepository.save( User( id = 0L, name = "test", @@ -60,7 +59,7 @@ class UserRepositoryTest { createdAt = Instant.now(Clock.tickMillis(ZoneId.systemDefault())) ) ) - val follower = userRepository.create( + val follower = userRepository.save( User( id = 1L, name = "follower", @@ -75,7 +74,7 @@ class UserRepositoryTest { createdAt = Instant.now(Clock.tickMillis(ZoneId.systemDefault())) ) ) - val follower2 = userRepository.create( + val follower2 = userRepository.save( User( id = 3L, name = "follower2", @@ -101,7 +100,7 @@ class UserRepositoryTest { @Test fun `createFollower フォロワー追加`() = runTest { val userRepository = UserRepository(db) - val user = userRepository.create( + val user = userRepository.save( User(0L, "test", "example.com", @@ -115,7 +114,7 @@ class UserRepositoryTest { createdAt = Instant.now() ) ) - val follower = userRepository.create( + val follower = userRepository.save( User(1L, "follower", "follower.example.com",