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.exception.PostNotFoundException
|
||||
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.service.job.JobQueueParentService
|
||||
import dev.usbharu.hideout.service.user.IUserService
|
||||
import io.ktor.client.*
|
||||
import kjob.core.job.JobProps
|
||||
import org.koin.core.annotation.Single
|
||||
|
@ -19,14 +20,15 @@ import java.time.Instant
|
|||
|
||||
@Single
|
||||
class ActivityPubReactionServiceImpl(
|
||||
private val userService: IUserService,
|
||||
private val jobQueueParentService: JobQueueParentService,
|
||||
private val iPostRepository: IPostRepository,
|
||||
private val httpClient: HttpClient
|
||||
private val httpClient: HttpClient,
|
||||
private val userQueryService: UserQueryService,
|
||||
private val followerQueryService: FollowerQueryService
|
||||
) : ActivityPubReactionService {
|
||||
override suspend fun reaction(like: Reaction) {
|
||||
val followers = userService.findFollowersById(like.userId)
|
||||
val user = userService.findById(like.userId)
|
||||
val followers = followerQueryService.findFollowersById(like.userId)
|
||||
val user = userQueryService.findById(like.userId)
|
||||
val post =
|
||||
iPostRepository.findOneById(like.postId) ?: throw PostNotFoundException("${like.postId} was not found.")
|
||||
followers.forEach { follower ->
|
||||
|
@ -41,8 +43,8 @@ class ActivityPubReactionServiceImpl(
|
|||
}
|
||||
|
||||
override suspend fun removeReaction(like: Reaction) {
|
||||
val followers = userService.findFollowersById(like.userId)
|
||||
val user = userService.findById(like.userId)
|
||||
val followers = followerQueryService.findFollowersById(like.userId)
|
||||
val user = userQueryService.findById(like.userId)
|
||||
val post =
|
||||
iPostRepository.findOneById(like.postId) ?: throw PostNotFoundException("${like.postId} was not found.")
|
||||
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.form.RefreshToken
|
||||
import dev.usbharu.hideout.exception.InvalidRefreshTokenException
|
||||
import dev.usbharu.hideout.query.UserQueryService
|
||||
import dev.usbharu.hideout.repository.IJwtRefreshTokenRepository
|
||||
import dev.usbharu.hideout.service.core.IMetaService
|
||||
import dev.usbharu.hideout.service.user.IUserService
|
||||
import dev.usbharu.hideout.util.RsaUtil
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -25,7 +25,7 @@ import java.util.*
|
|||
class JwtServiceImpl(
|
||||
private val metaService: IMetaService,
|
||||
private val refreshTokenRepository: IJwtRefreshTokenRepository,
|
||||
private val userService: IUserService
|
||||
private val userQueryService: UserQueryService
|
||||
) : IJwtService {
|
||||
|
||||
private val privateKey by lazy {
|
||||
|
@ -72,7 +72,7 @@ class JwtServiceImpl(
|
|||
val token = refreshTokenRepository.findByToken(refreshToken.refreshToken)
|
||||
?: throw InvalidRefreshTokenException("Invalid Refresh Token")
|
||||
|
||||
val user = userService.findById(token.userId)
|
||||
val user = userQueryService.findById(token.userId)
|
||||
|
||||
val now = Instant.now()
|
||||
if (token.createdAt.isAfter(now)) {
|
||||
|
|
|
@ -7,8 +7,6 @@ import dev.usbharu.hideout.domain.model.hideout.entity.User
|
|||
@Suppress("TooManyFunctions")
|
||||
interface IUserService {
|
||||
|
||||
suspend fun findById(id: Long): User
|
||||
|
||||
suspend fun findByNameLocalUser(name: 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.service.activitypub.ActivityPubSendFollowService
|
||||
import org.koin.core.annotation.Single
|
||||
import java.lang.Integer.min
|
||||
import java.time.Instant
|
||||
|
||||
@Single
|
||||
|
@ -20,17 +19,6 @@ class UserService(
|
|||
) :
|
||||
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 {
|
||||
return userRepository.findByNameAndDomain(name, Config.configData.domain)
|
||||
?: 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.form.RefreshToken
|
||||
import dev.usbharu.hideout.exception.InvalidRefreshTokenException
|
||||
import dev.usbharu.hideout.query.UserQueryService
|
||||
import dev.usbharu.hideout.repository.IJwtRefreshTokenRepository
|
||||
import dev.usbharu.hideout.service.core.IMetaService
|
||||
import dev.usbharu.hideout.service.user.IUserService
|
||||
import dev.usbharu.hideout.util.Base64Util
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.runTest
|
||||
|
@ -102,7 +102,7 @@ class JwtServiceImplTest {
|
|||
)
|
||||
onBlocking { generateId() } doReturn 2L
|
||||
}
|
||||
val userService = mock<IUserService> {
|
||||
val userService = mock<UserQueryService> {
|
||||
onBlocking { findById(1L) } doReturn User(
|
||||
id = 1L,
|
||||
name = "test",
|
||||
|
|
Loading…
Reference in New Issue