mirror of https://github.com/usbharu/Hideout.git
refactor: 不要な関数を削除
This commit is contained in:
parent
ab0350baf3
commit
d83d26f132
|
@ -10,9 +10,10 @@ import dev.usbharu.hideout.domain.model.job.DeliverPostJob
|
||||||
import dev.usbharu.hideout.exception.ap.IllegalActivityPubObjectException
|
import dev.usbharu.hideout.exception.ap.IllegalActivityPubObjectException
|
||||||
import dev.usbharu.hideout.plugins.getAp
|
import dev.usbharu.hideout.plugins.getAp
|
||||||
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 io.ktor.client.statement.*
|
import io.ktor.client.statement.*
|
||||||
import kjob.core.job.JobProps
|
import kjob.core.job.JobProps
|
||||||
|
@ -24,16 +25,17 @@ import java.time.Instant
|
||||||
class ActivityPubNoteServiceImpl(
|
class ActivityPubNoteServiceImpl(
|
||||||
private val httpClient: HttpClient,
|
private val httpClient: HttpClient,
|
||||||
private val jobQueueParentService: JobQueueParentService,
|
private val jobQueueParentService: JobQueueParentService,
|
||||||
private val userService: IUserService,
|
|
||||||
private val postRepository: IPostRepository,
|
private val postRepository: IPostRepository,
|
||||||
private val activityPubUserService: ActivityPubUserService
|
private val activityPubUserService: ActivityPubUserService,
|
||||||
|
private val userQueryService: UserQueryService,
|
||||||
|
private val followerQueryService: FollowerQueryService
|
||||||
) : ActivityPubNoteService {
|
) : ActivityPubNoteService {
|
||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(this::class.java)
|
private val logger = LoggerFactory.getLogger(this::class.java)
|
||||||
|
|
||||||
override suspend fun createNote(post: Post) {
|
override suspend fun createNote(post: Post) {
|
||||||
val followers = userService.findFollowersById(post.userId)
|
val followers = followerQueryService.findFollowersById(post.userId)
|
||||||
val userEntity = userService.findById(post.userId)
|
val userEntity = userQueryService.findById(post.userId)
|
||||||
val note = Config.configData.objectMapper.writeValueAsString(post)
|
val note = Config.configData.objectMapper.writeValueAsString(post)
|
||||||
followers.forEach { followerEntity ->
|
followers.forEach { followerEntity ->
|
||||||
jobQueueParentService.schedule(DeliverPostJob) {
|
jobQueueParentService.schedule(DeliverPostJob) {
|
||||||
|
@ -83,7 +85,7 @@ class ActivityPubNoteServiceImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun postToNote(post: Post): Note {
|
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) }
|
val reply = post.replyId?.let { postRepository.findOneById(it) }
|
||||||
return Note(
|
return Note(
|
||||||
name = "Post",
|
name = "Post",
|
||||||
|
@ -112,7 +114,7 @@ class ActivityPubNoteServiceImpl(
|
||||||
targetActor
|
targetActor
|
||||||
)
|
)
|
||||||
val user =
|
val user =
|
||||||
userService.findByUrl(person.url ?: throw IllegalActivityPubObjectException("person.url is null"))
|
userQueryService.findByUrl(person.url ?: throw IllegalActivityPubObjectException("person.url is null"))
|
||||||
|
|
||||||
val visibility =
|
val visibility =
|
||||||
if (note.to.contains(public) && note.cc.contains(public)) {
|
if (note.to.contains(public) && note.cc.contains(public)) {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import dev.usbharu.hideout.domain.model.hideout.entity.User
|
||||||
|
|
||||||
@Suppress("TooManyFunctions")
|
@Suppress("TooManyFunctions")
|
||||||
interface IUserService {
|
interface IUserService {
|
||||||
suspend fun findAll(limit: Int? = 100, offset: Long? = 0): List<User>
|
|
||||||
|
|
||||||
suspend fun findById(id: Long): User
|
suspend fun findById(id: Long): User
|
||||||
|
|
||||||
|
|
|
@ -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.User
|
||||||
import dev.usbharu.hideout.domain.model.hideout.entity.Visibility
|
import dev.usbharu.hideout.domain.model.hideout.entity.Visibility
|
||||||
import dev.usbharu.hideout.domain.model.job.DeliverPostJob
|
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.job.JobQueueParentService
|
||||||
import dev.usbharu.hideout.service.user.IUserService
|
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
import io.ktor.client.engine.mock.*
|
import io.ktor.client.engine.mock.*
|
||||||
import kjob.core.job.JobProps
|
import kjob.core.job.JobProps
|
||||||
|
@ -55,7 +56,7 @@ class ActivityPubNoteServiceImplTest {
|
||||||
createdAt = Instant.now()
|
createdAt = Instant.now()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val userService = mock<IUserService> {
|
val userQueryService = mock<UserQueryService> {
|
||||||
onBlocking { findById(eq(1L)) } doReturn User(
|
onBlocking { findById(eq(1L)) } doReturn User(
|
||||||
1L,
|
1L,
|
||||||
"test",
|
"test",
|
||||||
|
@ -69,11 +70,20 @@ class ActivityPubNoteServiceImplTest {
|
||||||
publicKey = "",
|
publicKey = "",
|
||||||
createdAt = Instant.now()
|
createdAt = Instant.now()
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
val followerQueryService = mock<FollowerQueryService> {
|
||||||
onBlocking { findFollowersById(eq(1L)) } doReturn followers
|
onBlocking { findFollowersById(eq(1L)) } doReturn followers
|
||||||
}
|
}
|
||||||
val jobQueueParentService = mock<JobQueueParentService>()
|
val jobQueueParentService = mock<JobQueueParentService>()
|
||||||
val activityPubNoteService =
|
val activityPubNoteService =
|
||||||
ActivityPubNoteServiceImpl(mock(), jobQueueParentService, userService, mock(), mock())
|
ActivityPubNoteServiceImpl(
|
||||||
|
mock(),
|
||||||
|
jobQueueParentService,
|
||||||
|
mock(),
|
||||||
|
mock(),
|
||||||
|
userQueryService,
|
||||||
|
followerQueryService
|
||||||
|
)
|
||||||
val postEntity = Post(
|
val postEntity = Post(
|
||||||
1L,
|
1L,
|
||||||
1L,
|
1L,
|
||||||
|
@ -96,7 +106,7 @@ class ActivityPubNoteServiceImplTest {
|
||||||
respondOk()
|
respondOk()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
val activityPubNoteService = ActivityPubNoteServiceImpl(httpClient, mock(), mock(), mock(), mock())
|
val activityPubNoteService = ActivityPubNoteServiceImpl(httpClient, mock(), mock(), mock(), mock(), mock())
|
||||||
activityPubNoteService.createNoteJob(
|
activityPubNoteService.createNoteJob(
|
||||||
JobProps(
|
JobProps(
|
||||||
data = mapOf<String, Any>(
|
data = mapOf<String, Any>(
|
||||||
|
|
Loading…
Reference in New Issue