mirror of https://github.com/usbharu/Hideout.git
refactor: updateを非推奨にしてcreateをsaveに変更
This commit is contained in:
parent
cabecd4fce
commit
48f455d4bc
|
@ -3,7 +3,7 @@ package dev.usbharu.hideout.repository
|
||||||
import dev.usbharu.hideout.domain.model.User
|
import dev.usbharu.hideout.domain.model.User
|
||||||
|
|
||||||
interface IUserRepository {
|
interface IUserRepository {
|
||||||
suspend fun create(user: User): User
|
suspend fun save(user: User): User
|
||||||
|
|
||||||
suspend fun findById(id: Long): User?
|
suspend fun findById(id: Long): User?
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ interface IUserRepository {
|
||||||
|
|
||||||
suspend fun findByUrls(urls: List<String>): List<User>
|
suspend fun findByUrls(urls: List<String>): List<User>
|
||||||
|
|
||||||
suspend fun update(userEntity: User)
|
@Deprecated("", ReplaceWith("save(userEntity)"))
|
||||||
|
suspend fun update(userEntity: User) = save(userEntity)
|
||||||
|
|
||||||
suspend fun delete(id: Long)
|
suspend fun delete(id: Long)
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
package dev.usbharu.hideout.repository
|
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 kotlinx.coroutines.Dispatchers
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.LocalDateTime
|
|
||||||
import java.time.ZoneId
|
|
||||||
import java.time.ZoneOffset
|
|
||||||
|
|
||||||
class UserRepository(private val database: Database) : IUserRepository {
|
class UserRepository(private val database: Database) : IUserRepository {
|
||||||
init {
|
init {
|
||||||
|
@ -21,12 +19,13 @@ class UserRepository(private val database: Database) : IUserRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("", ReplaceWith("toUser()"))
|
||||||
private fun ResultRow.toUserEntity(): User = toUser()
|
private fun ResultRow.toUserEntity(): User = toUser()
|
||||||
|
|
||||||
suspend fun <T> query(block: suspend () -> T): T =
|
suspend fun <T> query(block: suspend () -> T): T =
|
||||||
newSuspendedTransaction(Dispatchers.IO) { block() }
|
newSuspendedTransaction(Dispatchers.IO) { block() }
|
||||||
|
|
||||||
override suspend fun create(user: User): User {
|
override suspend fun save(user: User): User {
|
||||||
return query {
|
return query {
|
||||||
Users.insert {
|
Users.insert {
|
||||||
it[id] = user.id
|
it[id] = user.id
|
||||||
|
|
|
@ -10,7 +10,6 @@ import java.security.*
|
||||||
import java.security.interfaces.RSAPrivateKey
|
import java.security.interfaces.RSAPrivateKey
|
||||||
import java.security.interfaces.RSAPublicKey
|
import java.security.interfaces.RSAPublicKey
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.LocalDateTime
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class UserAuthService(
|
class UserAuthService(
|
||||||
|
@ -43,7 +42,7 @@ class UserAuthService(
|
||||||
publicKey = "",
|
publicKey = "",
|
||||||
createdAt = Instant.now(),
|
createdAt = Instant.now(),
|
||||||
)
|
)
|
||||||
val createdUser = userRepository.create(registerUser)
|
val createdUser = userRepository.save(registerUser)
|
||||||
|
|
||||||
val keyPair = generateKeyPair()
|
val keyPair = generateKeyPair()
|
||||||
val privateKey = keyPair.private as RSAPrivateKey
|
val privateKey = keyPair.private as RSAPrivateKey
|
||||||
|
|
|
@ -42,7 +42,7 @@ class UserService(private val userRepository: IUserRepository) {
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun create(user: User): User {
|
suspend fun create(user: User): User {
|
||||||
return userRepository.create(user)
|
return userRepository.save(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun findFollowersById(id: Long): List<User> {
|
suspend fun findFollowersById(id: Long): List<User> {
|
||||||
|
|
|
@ -18,7 +18,7 @@ class ActivityPubKtTest {
|
||||||
fun HttpSignTest(): Unit = runBlocking {
|
fun HttpSignTest(): Unit = runBlocking {
|
||||||
|
|
||||||
val ktorKeyMap = KtorKeyMap(object : IUserRepository {
|
val ktorKeyMap = KtorKeyMap(object : IUserRepository {
|
||||||
override suspend fun create(user: User): User {
|
override suspend fun save(user: User): User {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ class KtorKeyMapTest {
|
||||||
@Test
|
@Test
|
||||||
fun getPrivateKey() {
|
fun getPrivateKey() {
|
||||||
val ktorKeyMap = KtorKeyMap(object : IUserRepository {
|
val ktorKeyMap = KtorKeyMap(object : IUserRepository {
|
||||||
override suspend fun create(user: User): User {
|
override suspend fun save(user: User): User {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import java.time.Clock
|
import java.time.Clock
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.LocalDateTime
|
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,7 +44,7 @@ class UserRepositoryTest {
|
||||||
@Test
|
@Test
|
||||||
fun `findFollowersById フォロワー一覧を取得`() = runTest {
|
fun `findFollowersById フォロワー一覧を取得`() = runTest {
|
||||||
val userRepository = UserRepository(db)
|
val userRepository = UserRepository(db)
|
||||||
val user = userRepository.create(
|
val user = userRepository.save(
|
||||||
User(
|
User(
|
||||||
id = 0L,
|
id = 0L,
|
||||||
name = "test",
|
name = "test",
|
||||||
|
@ -60,7 +59,7 @@ class UserRepositoryTest {
|
||||||
createdAt = Instant.now(Clock.tickMillis(ZoneId.systemDefault()))
|
createdAt = Instant.now(Clock.tickMillis(ZoneId.systemDefault()))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val follower = userRepository.create(
|
val follower = userRepository.save(
|
||||||
User(
|
User(
|
||||||
id = 1L,
|
id = 1L,
|
||||||
name = "follower",
|
name = "follower",
|
||||||
|
@ -75,7 +74,7 @@ class UserRepositoryTest {
|
||||||
createdAt = Instant.now(Clock.tickMillis(ZoneId.systemDefault()))
|
createdAt = Instant.now(Clock.tickMillis(ZoneId.systemDefault()))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val follower2 = userRepository.create(
|
val follower2 = userRepository.save(
|
||||||
User(
|
User(
|
||||||
id = 3L,
|
id = 3L,
|
||||||
name = "follower2",
|
name = "follower2",
|
||||||
|
@ -101,7 +100,7 @@ class UserRepositoryTest {
|
||||||
@Test
|
@Test
|
||||||
fun `createFollower フォロワー追加`() = runTest {
|
fun `createFollower フォロワー追加`() = runTest {
|
||||||
val userRepository = UserRepository(db)
|
val userRepository = UserRepository(db)
|
||||||
val user = userRepository.create(
|
val user = userRepository.save(
|
||||||
User(0L,
|
User(0L,
|
||||||
"test",
|
"test",
|
||||||
"example.com",
|
"example.com",
|
||||||
|
@ -115,7 +114,7 @@ class UserRepositoryTest {
|
||||||
createdAt = Instant.now()
|
createdAt = Instant.now()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val follower = userRepository.create(
|
val follower = userRepository.save(
|
||||||
User(1L,
|
User(1L,
|
||||||
"follower",
|
"follower",
|
||||||
"follower.example.com",
|
"follower.example.com",
|
||||||
|
|
Loading…
Reference in New Issue