mirror of https://github.com/usbharu/Hideout.git
feat: RepositoryにID発行を追加
This commit is contained in:
parent
2a2b12a1d6
commit
b7dfc328eb
|
@ -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<IUserRepository> { UserRepository(get()) }
|
||||
single<IUserRepository> { UserRepository(get(),get()) }
|
||||
single<IUserAuthService> { UserAuthService(get()) }
|
||||
single<HttpSignatureVerifyService> { HttpSignatureVerifyServiceImpl(get()) }
|
||||
single<JobQueueParentService> {
|
||||
|
@ -82,7 +83,8 @@ fun Application.parent() {
|
|||
single<ActivityPubUserService> { ActivityPubUserServiceImpl(get(), get(), get()) }
|
||||
single<ActivityPubNoteService> { ActivityPubNoteServiceImpl(get(), get(), get()) }
|
||||
single<IPostService> { PostService(get(), get()) }
|
||||
single<IPostRepository> { PostRepositoryImpl(get(), TwitterSnowflakeIdGenerateService) }
|
||||
single<IPostRepository> { PostRepositoryImpl(get(), get()) }
|
||||
single<IdGenerateService> {TwitterSnowflakeIdGenerateService}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<User>
|
||||
|
||||
suspend fun nextId():Long
|
||||
}
|
||||
|
|
|
@ -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") {
|
||||
|
|
|
@ -81,6 +81,10 @@ class KtorKeyMapTest {
|
|||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun nextId(): Long {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
ktorKeyMap.getPrivateKey("test")
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue