refactor: 不要な関数を削除

This commit is contained in:
usbharu 2023-08-10 19:04:16 +09:00
parent 399d7d369e
commit 4e39c05e6c
3 changed files with 23 additions and 12 deletions

View File

@ -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)) {

View File

@ -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<User>
suspend fun findById(id: Long): User

View File

@ -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<IUserService> {
val userQueryService = mock<UserQueryService> {
onBlocking { findById(eq(1L)) } doReturn User(
1L,
"test",
@ -69,11 +70,20 @@ class ActivityPubNoteServiceImplTest {
publicKey = "",
createdAt = Instant.now()
)
}
val followerQueryService = mock<FollowerQueryService> {
onBlocking { findFollowersById(eq(1L)) } doReturn followers
}
val jobQueueParentService = mock<JobQueueParentService>()
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<String, Any>(