mirror of https://github.com/usbharu/Hideout.git
refactor: 不要な関数を削除
This commit is contained in:
parent
4e39c05e6c
commit
e781d1467f
|
@ -9,9 +9,10 @@ import dev.usbharu.hideout.domain.model.job.DeliverReactionJob
|
||||||
import dev.usbharu.hideout.domain.model.job.DeliverRemoveReactionJob
|
import dev.usbharu.hideout.domain.model.job.DeliverRemoveReactionJob
|
||||||
import dev.usbharu.hideout.exception.PostNotFoundException
|
import dev.usbharu.hideout.exception.PostNotFoundException
|
||||||
import dev.usbharu.hideout.plugins.postAp
|
import dev.usbharu.hideout.plugins.postAp
|
||||||
|
import dev.usbharu.hideout.query.FollowerQueryService
|
||||||
|
import dev.usbharu.hideout.query.UserQueryService
|
||||||
import dev.usbharu.hideout.repository.IPostRepository
|
import dev.usbharu.hideout.repository.IPostRepository
|
||||||
import dev.usbharu.hideout.service.job.JobQueueParentService
|
import dev.usbharu.hideout.service.job.JobQueueParentService
|
||||||
import dev.usbharu.hideout.service.user.IUserService
|
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
import kjob.core.job.JobProps
|
import kjob.core.job.JobProps
|
||||||
import org.koin.core.annotation.Single
|
import org.koin.core.annotation.Single
|
||||||
|
@ -19,14 +20,15 @@ import java.time.Instant
|
||||||
|
|
||||||
@Single
|
@Single
|
||||||
class ActivityPubReactionServiceImpl(
|
class ActivityPubReactionServiceImpl(
|
||||||
private val userService: IUserService,
|
|
||||||
private val jobQueueParentService: JobQueueParentService,
|
private val jobQueueParentService: JobQueueParentService,
|
||||||
private val iPostRepository: IPostRepository,
|
private val iPostRepository: IPostRepository,
|
||||||
private val httpClient: HttpClient
|
private val httpClient: HttpClient,
|
||||||
|
private val userQueryService: UserQueryService,
|
||||||
|
private val followerQueryService: FollowerQueryService
|
||||||
) : ActivityPubReactionService {
|
) : ActivityPubReactionService {
|
||||||
override suspend fun reaction(like: Reaction) {
|
override suspend fun reaction(like: Reaction) {
|
||||||
val followers = userService.findFollowersById(like.userId)
|
val followers = followerQueryService.findFollowersById(like.userId)
|
||||||
val user = userService.findById(like.userId)
|
val user = userQueryService.findById(like.userId)
|
||||||
val post =
|
val post =
|
||||||
iPostRepository.findOneById(like.postId) ?: throw PostNotFoundException("${like.postId} was not found.")
|
iPostRepository.findOneById(like.postId) ?: throw PostNotFoundException("${like.postId} was not found.")
|
||||||
followers.forEach { follower ->
|
followers.forEach { follower ->
|
||||||
|
@ -41,8 +43,8 @@ class ActivityPubReactionServiceImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun removeReaction(like: Reaction) {
|
override suspend fun removeReaction(like: Reaction) {
|
||||||
val followers = userService.findFollowersById(like.userId)
|
val followers = followerQueryService.findFollowersById(like.userId)
|
||||||
val user = userService.findById(like.userId)
|
val user = userQueryService.findById(like.userId)
|
||||||
val post =
|
val post =
|
||||||
iPostRepository.findOneById(like.postId) ?: throw PostNotFoundException("${like.postId} was not found.")
|
iPostRepository.findOneById(like.postId) ?: throw PostNotFoundException("${like.postId} was not found.")
|
||||||
followers.forEach { follower ->
|
followers.forEach { follower ->
|
||||||
|
|
|
@ -8,9 +8,9 @@ import dev.usbharu.hideout.domain.model.hideout.entity.JwtRefreshToken
|
||||||
import dev.usbharu.hideout.domain.model.hideout.entity.User
|
import dev.usbharu.hideout.domain.model.hideout.entity.User
|
||||||
import dev.usbharu.hideout.domain.model.hideout.form.RefreshToken
|
import dev.usbharu.hideout.domain.model.hideout.form.RefreshToken
|
||||||
import dev.usbharu.hideout.exception.InvalidRefreshTokenException
|
import dev.usbharu.hideout.exception.InvalidRefreshTokenException
|
||||||
|
import dev.usbharu.hideout.query.UserQueryService
|
||||||
import dev.usbharu.hideout.repository.IJwtRefreshTokenRepository
|
import dev.usbharu.hideout.repository.IJwtRefreshTokenRepository
|
||||||
import dev.usbharu.hideout.service.core.IMetaService
|
import dev.usbharu.hideout.service.core.IMetaService
|
||||||
import dev.usbharu.hideout.service.user.IUserService
|
|
||||||
import dev.usbharu.hideout.util.RsaUtil
|
import dev.usbharu.hideout.util.RsaUtil
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -25,7 +25,7 @@ import java.util.*
|
||||||
class JwtServiceImpl(
|
class JwtServiceImpl(
|
||||||
private val metaService: IMetaService,
|
private val metaService: IMetaService,
|
||||||
private val refreshTokenRepository: IJwtRefreshTokenRepository,
|
private val refreshTokenRepository: IJwtRefreshTokenRepository,
|
||||||
private val userService: IUserService
|
private val userQueryService: UserQueryService
|
||||||
) : IJwtService {
|
) : IJwtService {
|
||||||
|
|
||||||
private val privateKey by lazy {
|
private val privateKey by lazy {
|
||||||
|
@ -72,7 +72,7 @@ class JwtServiceImpl(
|
||||||
val token = refreshTokenRepository.findByToken(refreshToken.refreshToken)
|
val token = refreshTokenRepository.findByToken(refreshToken.refreshToken)
|
||||||
?: throw InvalidRefreshTokenException("Invalid Refresh Token")
|
?: throw InvalidRefreshTokenException("Invalid Refresh Token")
|
||||||
|
|
||||||
val user = userService.findById(token.userId)
|
val user = userQueryService.findById(token.userId)
|
||||||
|
|
||||||
val now = Instant.now()
|
val now = Instant.now()
|
||||||
if (token.createdAt.isAfter(now)) {
|
if (token.createdAt.isAfter(now)) {
|
||||||
|
|
|
@ -7,8 +7,6 @@ import dev.usbharu.hideout.domain.model.hideout.entity.User
|
||||||
@Suppress("TooManyFunctions")
|
@Suppress("TooManyFunctions")
|
||||||
interface IUserService {
|
interface IUserService {
|
||||||
|
|
||||||
suspend fun findById(id: Long): User
|
|
||||||
|
|
||||||
suspend fun findByNameLocalUser(name: String): User
|
suspend fun findByNameLocalUser(name: String): User
|
||||||
|
|
||||||
suspend fun findByUrl(url: String): User
|
suspend fun findByUrl(url: String): User
|
||||||
|
|
|
@ -9,7 +9,6 @@ import dev.usbharu.hideout.exception.UserNotFoundException
|
||||||
import dev.usbharu.hideout.repository.IUserRepository
|
import dev.usbharu.hideout.repository.IUserRepository
|
||||||
import dev.usbharu.hideout.service.activitypub.ActivityPubSendFollowService
|
import dev.usbharu.hideout.service.activitypub.ActivityPubSendFollowService
|
||||||
import org.koin.core.annotation.Single
|
import org.koin.core.annotation.Single
|
||||||
import java.lang.Integer.min
|
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
@Single
|
@Single
|
||||||
|
@ -20,17 +19,6 @@ class UserService(
|
||||||
) :
|
) :
|
||||||
IUserService {
|
IUserService {
|
||||||
|
|
||||||
private val maxLimit = 100
|
|
||||||
override suspend fun findAll(limit: Int?, offset: Long?): List<User> {
|
|
||||||
return userRepository.findAllByLimitAndByOffset(
|
|
||||||
min(limit ?: maxLimit, maxLimit),
|
|
||||||
offset ?: 0
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun findById(id: Long): User =
|
|
||||||
userRepository.findById(id) ?: throw UserNotFoundException("$id was not found.")
|
|
||||||
|
|
||||||
override suspend fun findByNameLocalUser(name: String): User {
|
override suspend fun findByNameLocalUser(name: String): User {
|
||||||
return userRepository.findByNameAndDomain(name, Config.configData.domain)
|
return userRepository.findByNameAndDomain(name, Config.configData.domain)
|
||||||
?: throw UserNotFoundException("$name was not found.")
|
?: throw UserNotFoundException("$name was not found.")
|
||||||
|
|
|
@ -12,9 +12,9 @@ import dev.usbharu.hideout.domain.model.hideout.entity.JwtRefreshToken
|
||||||
import dev.usbharu.hideout.domain.model.hideout.entity.User
|
import dev.usbharu.hideout.domain.model.hideout.entity.User
|
||||||
import dev.usbharu.hideout.domain.model.hideout.form.RefreshToken
|
import dev.usbharu.hideout.domain.model.hideout.form.RefreshToken
|
||||||
import dev.usbharu.hideout.exception.InvalidRefreshTokenException
|
import dev.usbharu.hideout.exception.InvalidRefreshTokenException
|
||||||
|
import dev.usbharu.hideout.query.UserQueryService
|
||||||
import dev.usbharu.hideout.repository.IJwtRefreshTokenRepository
|
import dev.usbharu.hideout.repository.IJwtRefreshTokenRepository
|
||||||
import dev.usbharu.hideout.service.core.IMetaService
|
import dev.usbharu.hideout.service.core.IMetaService
|
||||||
import dev.usbharu.hideout.service.user.IUserService
|
|
||||||
import dev.usbharu.hideout.util.Base64Util
|
import dev.usbharu.hideout.util.Base64Util
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
|
@ -102,7 +102,7 @@ class JwtServiceImplTest {
|
||||||
)
|
)
|
||||||
onBlocking { generateId() } doReturn 2L
|
onBlocking { generateId() } doReturn 2L
|
||||||
}
|
}
|
||||||
val userService = mock<IUserService> {
|
val userService = mock<UserQueryService> {
|
||||||
onBlocking { findById(1L) } doReturn User(
|
onBlocking { findById(1L) } doReturn User(
|
||||||
id = 1L,
|
id = 1L,
|
||||||
name = "test",
|
name = "test",
|
||||||
|
|
Loading…
Reference in New Issue