diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImpl.kt index 5d6338a5..29be3294 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImpl.kt @@ -10,9 +10,10 @@ import dev.usbharu.hideout.domain.model.job.DeliverPostJob import dev.usbharu.hideout.exception.ap.IllegalActivityPubObjectException import dev.usbharu.hideout.plugins.getAp 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 io.ktor.client.statement.* import kjob.core.job.JobProps @@ -24,16 +25,17 @@ import java.time.Instant class ActivityPubNoteServiceImpl( private val httpClient: HttpClient, private val jobQueueParentService: JobQueueParentService, - private val userService: IUserService, private val postRepository: IPostRepository, - private val activityPubUserService: ActivityPubUserService + private val activityPubUserService: ActivityPubUserService, + private val userQueryService: UserQueryService, + private val followerQueryService: FollowerQueryService ) : ActivityPubNoteService { private val logger = LoggerFactory.getLogger(this::class.java) override suspend fun createNote(post: Post) { - val followers = userService.findFollowersById(post.userId) - val userEntity = userService.findById(post.userId) + val followers = followerQueryService.findFollowersById(post.userId) + val userEntity = userQueryService.findById(post.userId) val note = Config.configData.objectMapper.writeValueAsString(post) followers.forEach { followerEntity -> jobQueueParentService.schedule(DeliverPostJob) { @@ -83,7 +85,7 @@ class ActivityPubNoteServiceImpl( } private suspend fun postToNote(post: Post): Note { - val user = userService.findById(post.userId) + val user = userQueryService.findById(post.userId) val reply = post.replyId?.let { postRepository.findOneById(it) } return Note( name = "Post", @@ -112,7 +114,7 @@ class ActivityPubNoteServiceImpl( targetActor ) val user = - userService.findByUrl(person.url ?: throw IllegalActivityPubObjectException("person.url is null")) + userQueryService.findByUrl(person.url ?: throw IllegalActivityPubObjectException("person.url is null")) val visibility = if (note.to.contains(public) && note.cc.contains(public)) { diff --git a/src/main/kotlin/dev/usbharu/hideout/service/user/IUserService.kt b/src/main/kotlin/dev/usbharu/hideout/service/user/IUserService.kt index f247b30a..782bb8d5 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/user/IUserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/user/IUserService.kt @@ -6,7 +6,6 @@ import dev.usbharu.hideout.domain.model.hideout.entity.User @Suppress("TooManyFunctions") interface IUserService { - suspend fun findAll(limit: Int? = 100, offset: Long? = 0): List suspend fun findById(id: Long): User diff --git a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImplTest.kt index eed2c9a2..3b831cba 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImplTest.kt @@ -9,8 +9,9 @@ import dev.usbharu.hideout.domain.model.hideout.entity.Post import dev.usbharu.hideout.domain.model.hideout.entity.User import dev.usbharu.hideout.domain.model.hideout.entity.Visibility import dev.usbharu.hideout.domain.model.job.DeliverPostJob +import dev.usbharu.hideout.query.FollowerQueryService +import dev.usbharu.hideout.query.UserQueryService import dev.usbharu.hideout.service.job.JobQueueParentService -import dev.usbharu.hideout.service.user.IUserService import io.ktor.client.* import io.ktor.client.engine.mock.* import kjob.core.job.JobProps @@ -55,7 +56,7 @@ class ActivityPubNoteServiceImplTest { createdAt = Instant.now() ) ) - val userService = mock { + val userQueryService = mock { onBlocking { findById(eq(1L)) } doReturn User( 1L, "test", @@ -69,11 +70,20 @@ class ActivityPubNoteServiceImplTest { publicKey = "", createdAt = Instant.now() ) + } + val followerQueryService = mock { onBlocking { findFollowersById(eq(1L)) } doReturn followers } val jobQueueParentService = mock() val activityPubNoteService = - ActivityPubNoteServiceImpl(mock(), jobQueueParentService, userService, mock(), mock()) + ActivityPubNoteServiceImpl( + mock(), + jobQueueParentService, + mock(), + mock(), + userQueryService, + followerQueryService + ) val postEntity = Post( 1L, 1L, @@ -96,7 +106,7 @@ class ActivityPubNoteServiceImplTest { respondOk() } ) - val activityPubNoteService = ActivityPubNoteServiceImpl(httpClient, mock(), mock(), mock(), mock()) + val activityPubNoteService = ActivityPubNoteServiceImpl(httpClient, mock(), mock(), mock(), mock(), mock()) activityPubNoteService.createNoteJob( JobProps( data = mapOf(