refactor: 一括検索を都度検索に変更

This commit is contained in:
usbharu 2023-08-10 19:23:12 +09:00
parent 6265d0772a
commit d2524a5684
3 changed files with 19 additions and 18 deletions

View File

@ -8,6 +8,7 @@ import dev.usbharu.hideout.domain.model.ap.Accept
import dev.usbharu.hideout.domain.model.ap.Follow import dev.usbharu.hideout.domain.model.ap.Follow
import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob
import dev.usbharu.hideout.plugins.postAp import dev.usbharu.hideout.plugins.postAp
import dev.usbharu.hideout.query.UserQueryService
import dev.usbharu.hideout.service.job.JobQueueParentService import dev.usbharu.hideout.service.job.JobQueueParentService
import dev.usbharu.hideout.service.user.IUserService import dev.usbharu.hideout.service.user.IUserService
import io.ktor.client.* import io.ktor.client.*
@ -20,7 +21,8 @@ class ActivityPubReceiveFollowServiceImpl(
private val jobQueueParentService: JobQueueParentService, private val jobQueueParentService: JobQueueParentService,
private val activityPubUserService: ActivityPubUserService, private val activityPubUserService: ActivityPubUserService,
private val userService: IUserService, private val userService: IUserService,
private val httpClient: HttpClient private val httpClient: HttpClient,
private val userQueryService: UserQueryService
) : ActivityPubReceiveFollowService { ) : ActivityPubReceiveFollowService {
override suspend fun receiveFollow(follow: Follow): ActivityPubResponse { override suspend fun receiveFollow(follow: Follow): ActivityPubResponse {
// TODO: Verify HTTP Signature // TODO: Verify HTTP Signature
@ -46,9 +48,11 @@ class ActivityPubReceiveFollowServiceImpl(
actor = targetActor actor = targetActor
) )
) )
val users =
userService.findByUrls(listOf(targetActor, follow.actor ?: throw IllegalArgumentException("actor is null")))
userService.followRequest(users.first { it.url == targetActor }.id, users.first { it.url == follow.actor }.id) val targetEntity = userQueryService.findByUrl(targetActor)
val followActorEntity =
userQueryService.findByUrl(follow.actor ?: throw java.lang.IllegalArgumentException("Actor is null"))
userService.followRequest(targetEntity.id, followActorEntity.id)
} }
} }

View File

@ -19,14 +19,6 @@ class UserService(
) : ) :
IUserService { IUserService {
override suspend fun findByNameLocalUser(name: String): User {
return userRepository.findByNameAndDomain(name, Config.configData.domain)
?: throw UserNotFoundException("$name was not found.")
}
override suspend fun findByUrl(url: String): User =
userRepository.findByUrl(url) ?: throw UserNotFoundException("$url was not found.")
override suspend fun findByUrls(urls: List<String>): List<User> = userRepository.findByUrls(urls) override suspend fun findByUrls(urls: List<String>): List<User> = userRepository.findByUrls(urls)
override suspend fun usernameAlreadyUse(username: String): Boolean { override suspend fun usernameAlreadyUse(username: String): Boolean {

View File

@ -9,6 +9,7 @@ import dev.usbharu.hideout.config.ConfigData
import dev.usbharu.hideout.domain.model.ap.* import dev.usbharu.hideout.domain.model.ap.*
import dev.usbharu.hideout.domain.model.hideout.entity.User import dev.usbharu.hideout.domain.model.hideout.entity.User
import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob
import dev.usbharu.hideout.query.UserQueryService
import dev.usbharu.hideout.service.job.JobQueueParentService import dev.usbharu.hideout.service.job.JobQueueParentService
import dev.usbharu.hideout.service.user.IUserService import dev.usbharu.hideout.service.user.IUserService
import io.ktor.client.* import io.ktor.client.*
@ -32,7 +33,7 @@ class ActivityPubReceiveFollowServiceImplTest {
onBlocking { schedule(eq(ReceiveFollowJob), any()) } doReturn Unit onBlocking { schedule(eq(ReceiveFollowJob), any()) } doReturn Unit
} }
val activityPubFollowService = val activityPubFollowService =
ActivityPubReceiveFollowServiceImpl(jobQueueParentService, mock(), mock(), mock()) ActivityPubReceiveFollowServiceImpl(jobQueueParentService, mock(), mock(), mock(), mock())
activityPubFollowService.receiveFollow( activityPubFollowService.receiveFollow(
Follow( Follow(
emptyList(), emptyList(),
@ -97,8 +98,8 @@ class ActivityPubReceiveFollowServiceImplTest {
val activityPubUserService = mock<ActivityPubUserService> { val activityPubUserService = mock<ActivityPubUserService> {
onBlocking { fetchPerson(anyString(), any()) } doReturn person onBlocking { fetchPerson(anyString(), any()) } doReturn person
} }
val userService = mock<IUserService> { val userQueryService = mock<UserQueryService> {
onBlocking { findByUrls(any()) } doReturn listOf( onBlocking { findByUrl(eq("https://example.com")) } doReturn
User( User(
id = 1L, id = 1L,
name = "test", name = "test",
@ -110,7 +111,8 @@ class ActivityPubReceiveFollowServiceImplTest {
url = "https://example.com", url = "https://example.com",
publicKey = "", publicKey = "",
createdAt = Instant.now() createdAt = Instant.now()
), )
onBlocking { findByUrl(eq("https://follower.example.com")) } doReturn
User( User(
id = 2L, id = 2L,
name = "follower", name = "follower",
@ -123,7 +125,9 @@ class ActivityPubReceiveFollowServiceImplTest {
publicKey = "", publicKey = "",
createdAt = Instant.now() createdAt = Instant.now()
) )
) }
val userService = mock<IUserService> {
onBlocking { followRequest(any(), any()) } doReturn false onBlocking { followRequest(any(), any()) } doReturn false
} }
val activityPubFollowService = val activityPubFollowService =
@ -156,7 +160,8 @@ class ActivityPubReceiveFollowServiceImplTest {
) )
respondOk() respondOk()
} }
) ),
userQueryService
) )
activityPubFollowService.receiveFollowJob( activityPubFollowService.receiveFollowJob(
JobProps( JobProps(