refactor: 不要な関数を削除

This commit is contained in:
usbharu 2023-08-10 19:13:42 +09:00
parent e781d1467f
commit 642912d5f3
6 changed files with 36 additions and 26 deletions

View File

@ -12,6 +12,8 @@ import dev.usbharu.hideout.domain.model.job.DeliverReactionJob
import dev.usbharu.hideout.domain.model.job.DeliverRemoveReactionJob import dev.usbharu.hideout.domain.model.job.DeliverRemoveReactionJob
import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob
import dev.usbharu.hideout.plugins.* import dev.usbharu.hideout.plugins.*
import dev.usbharu.hideout.query.FollowerQueryService
import dev.usbharu.hideout.query.UserQueryService
import dev.usbharu.hideout.repository.IUserRepository import dev.usbharu.hideout.repository.IUserRepository
import dev.usbharu.hideout.routing.register import dev.usbharu.hideout.routing.register
import dev.usbharu.hideout.service.activitypub.ActivityPubService import dev.usbharu.hideout.service.activitypub.ActivityPubService
@ -120,7 +122,8 @@ fun Application.parent() {
userAuthService = inject<IUserAuthService>().value, userAuthService = inject<IUserAuthService>().value,
userRepository = inject<IUserRepository>().value, userRepository = inject<IUserRepository>().value,
jwtService = inject<IJwtService>().value, jwtService = inject<IJwtService>().value,
metaService = inject<IMetaService>().value userQueryService = inject<UserQueryService>().value,
followerQueryService = inject<FollowerQueryService>().value
) )
} }

View File

@ -1,5 +1,7 @@
package dev.usbharu.hideout.plugins package dev.usbharu.hideout.plugins
import dev.usbharu.hideout.query.FollowerQueryService
import dev.usbharu.hideout.query.UserQueryService
import dev.usbharu.hideout.repository.IUserRepository import dev.usbharu.hideout.repository.IUserRepository
import dev.usbharu.hideout.routing.activitypub.inbox import dev.usbharu.hideout.routing.activitypub.inbox
import dev.usbharu.hideout.routing.activitypub.outbox import dev.usbharu.hideout.routing.activitypub.outbox
@ -14,7 +16,6 @@ import dev.usbharu.hideout.service.api.IPostApiService
import dev.usbharu.hideout.service.api.IUserApiService import dev.usbharu.hideout.service.api.IUserApiService
import dev.usbharu.hideout.service.auth.HttpSignatureVerifyService import dev.usbharu.hideout.service.auth.HttpSignatureVerifyService
import dev.usbharu.hideout.service.auth.IJwtService import dev.usbharu.hideout.service.auth.IJwtService
import dev.usbharu.hideout.service.core.IMetaService
import dev.usbharu.hideout.service.reaction.IReactionService import dev.usbharu.hideout.service.reaction.IReactionService
import dev.usbharu.hideout.service.user.IUserAuthService import dev.usbharu.hideout.service.user.IUserAuthService
import dev.usbharu.hideout.service.user.IUserService import dev.usbharu.hideout.service.user.IUserService
@ -34,14 +35,15 @@ fun Application.configureRouting(
userAuthService: IUserAuthService, userAuthService: IUserAuthService,
userRepository: IUserRepository, userRepository: IUserRepository,
jwtService: IJwtService, jwtService: IJwtService,
metaService: IMetaService userQueryService: UserQueryService,
followerQueryService: FollowerQueryService
) { ) {
install(AutoHeadResponse) install(AutoHeadResponse)
routing { routing {
inbox(httpSignatureVerifyService, activityPubService) inbox(httpSignatureVerifyService, activityPubService)
outbox() outbox()
usersAP(activityPubUserService, userService) usersAP(activityPubUserService, userQueryService, followerQueryService)
webfinger(userService) webfinger(userQueryService)
route("/api/internal/v1") { route("/api/internal/v1") {
posts(postService, reactionService) posts(postService, reactionService)
users(userService, userApiService) users(userService, userApiService)

View File

@ -1,9 +1,11 @@
package dev.usbharu.hideout.routing.activitypub package dev.usbharu.hideout.routing.activitypub
import dev.usbharu.hideout.config.Config
import dev.usbharu.hideout.exception.ParameterNotExistException import dev.usbharu.hideout.exception.ParameterNotExistException
import dev.usbharu.hideout.plugins.respondAp import dev.usbharu.hideout.plugins.respondAp
import dev.usbharu.hideout.query.FollowerQueryService
import dev.usbharu.hideout.query.UserQueryService
import dev.usbharu.hideout.service.activitypub.ActivityPubUserService import dev.usbharu.hideout.service.activitypub.ActivityPubUserService
import dev.usbharu.hideout.service.user.IUserService
import dev.usbharu.hideout.util.HttpUtil.Activity import dev.usbharu.hideout.util.HttpUtil.Activity
import dev.usbharu.hideout.util.HttpUtil.JsonLd import dev.usbharu.hideout.util.HttpUtil.JsonLd
import io.ktor.http.* import io.ktor.http.*
@ -12,7 +14,11 @@ import io.ktor.server.request.*
import io.ktor.server.response.* import io.ktor.server.response.*
import io.ktor.server.routing.* import io.ktor.server.routing.*
fun Routing.usersAP(activityPubUserService: ActivityPubUserService, userService: IUserService) { fun Routing.usersAP(
activityPubUserService: ActivityPubUserService,
userQueryService: UserQueryService,
followerQueryService: FollowerQueryService
) {
route("/users/{name}") { route("/users/{name}") {
createChild(ContentTypeRouteSelector(ContentType.Application.Activity, ContentType.Application.JsonLd)).handle { createChild(ContentTypeRouteSelector(ContentType.Application.Activity, ContentType.Application.JsonLd)).handle {
call.application.log.debug("Signature: ${call.request.header("Signature")}") call.application.log.debug("Signature: ${call.request.header("Signature")}")
@ -26,10 +32,11 @@ fun Routing.usersAP(activityPubUserService: ActivityPubUserService, userService:
) )
} }
get { get {
val userEntity = userService.findByNameLocalUser( val userEntity = userQueryService.findByNameAndDomain(
call.parameters["name"] ?: throw ParameterNotExistException("Parameter(name='name') does not exist.") call.parameters["name"] ?: throw ParameterNotExistException("Parameter(name='name') does not exist."),
Config.configData.domain
) )
call.respondText(userEntity.toString() + "\n" + userService.findFollowersById(userEntity.id)) call.respondText(userEntity.toString() + "\n" + followerQueryService.findFollowersById(userEntity.id))
} }
} }
} }

View File

@ -4,14 +4,14 @@ import dev.usbharu.hideout.config.Config
import dev.usbharu.hideout.domain.model.wellknown.WebFinger import dev.usbharu.hideout.domain.model.wellknown.WebFinger
import dev.usbharu.hideout.exception.IllegalParameterException import dev.usbharu.hideout.exception.IllegalParameterException
import dev.usbharu.hideout.exception.ParameterNotExistException import dev.usbharu.hideout.exception.ParameterNotExistException
import dev.usbharu.hideout.service.user.IUserService import dev.usbharu.hideout.query.UserQueryService
import dev.usbharu.hideout.util.HttpUtil.Activity import dev.usbharu.hideout.util.HttpUtil.Activity
import io.ktor.http.* import io.ktor.http.*
import io.ktor.server.application.* import io.ktor.server.application.*
import io.ktor.server.response.* import io.ktor.server.response.*
import io.ktor.server.routing.* import io.ktor.server.routing.*
fun Routing.webfinger(userService: IUserService) { fun Routing.webfinger(userQueryService: UserQueryService) {
route("/.well-known/webfinger") { route("/.well-known/webfinger") {
get { get {
val acct = call.request.queryParameters["resource"]?.decodeURLPart() val acct = call.request.queryParameters["resource"]?.decodeURLPart()
@ -25,7 +25,7 @@ fun Routing.webfinger(userService: IUserService) {
.substringAfter("acct:") .substringAfter("acct:")
.trimStart('@') .trimStart('@')
val userEntity = userService.findByNameLocalUser(accountName) val userEntity = userQueryService.findByNameAndDomain(accountName, Config.configData.domain)
val webFinger = WebFinger( val webFinger = WebFinger(
subject = acct, subject = acct,

View File

@ -9,6 +9,7 @@ import dev.usbharu.hideout.domain.model.hideout.dto.RemoteUserCreateDto
import dev.usbharu.hideout.exception.UserNotFoundException import dev.usbharu.hideout.exception.UserNotFoundException
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.query.UserQueryService
import dev.usbharu.hideout.service.user.IUserService import dev.usbharu.hideout.service.user.IUserService
import dev.usbharu.hideout.util.HttpUtil.Activity import dev.usbharu.hideout.util.HttpUtil.Activity
import io.ktor.client.* import io.ktor.client.*
@ -20,13 +21,14 @@ import org.koin.core.annotation.Single
@Single @Single
class ActivityPubUserServiceImpl( class ActivityPubUserServiceImpl(
private val userService: IUserService, private val userService: IUserService,
private val httpClient: HttpClient private val httpClient: HttpClient,
private val userQueryService: UserQueryService
) : ) :
ActivityPubUserService { ActivityPubUserService {
override suspend fun getPersonByName(name: String): Person { override suspend fun getPersonByName(name: String): Person {
// TODO: JOINで書き直し // TODO: JOINで書き直し
val userEntity = userService.findByNameLocalUser(name) val userEntity = userQueryService.findByNameAndDomain(name, Config.configData.domain)
val userUrl = "${Config.configData.url}/users/$name" val userUrl = "${Config.configData.url}/users/$name"
return Person( return Person(
type = emptyList(), type = emptyList(),
@ -55,7 +57,7 @@ class ActivityPubUserServiceImpl(
override suspend fun fetchPerson(url: String, targetActor: String?): Person { override suspend fun fetchPerson(url: String, targetActor: String?): Person {
return try { return try {
val userEntity = userService.findByUrl(url) val userEntity = userQueryService.findByUrl(url)
return Person( return Person(
type = emptyList(), type = emptyList(),
name = userEntity.name, name = userEntity.name,

View File

@ -11,8 +11,8 @@ import dev.usbharu.hideout.domain.model.ap.Key
import dev.usbharu.hideout.domain.model.ap.Person import dev.usbharu.hideout.domain.model.ap.Person
import dev.usbharu.hideout.domain.model.hideout.entity.User import dev.usbharu.hideout.domain.model.hideout.entity.User
import dev.usbharu.hideout.plugins.configureSerialization import dev.usbharu.hideout.plugins.configureSerialization
import dev.usbharu.hideout.query.UserQueryService
import dev.usbharu.hideout.service.activitypub.ActivityPubUserService import dev.usbharu.hideout.service.activitypub.ActivityPubUserService
import dev.usbharu.hideout.service.user.IUserService
import dev.usbharu.hideout.util.HttpUtil.Activity import dev.usbharu.hideout.util.HttpUtil.Activity
import dev.usbharu.hideout.util.HttpUtil.JsonLd import dev.usbharu.hideout.util.HttpUtil.JsonLd
import io.ktor.client.request.* import io.ktor.client.request.*
@ -62,8 +62,6 @@ class UsersAPTest {
) )
person.context = listOf("https://www.w3.org/ns/activitystreams") person.context = listOf("https://www.w3.org/ns/activitystreams")
val userService = mock<IUserService> {}
val activityPubUserService = mock<ActivityPubUserService> { val activityPubUserService = mock<ActivityPubUserService> {
onBlocking { getPersonByName(anyString()) } doReturn person onBlocking { getPersonByName(anyString()) } doReturn person
} }
@ -71,7 +69,7 @@ class UsersAPTest {
application { application {
configureSerialization() configureSerialization()
routing { routing {
usersAP(activityPubUserService, userService) usersAP(activityPubUserService, mock(), mock())
} }
} }
client.get("/users/test") { client.get("/users/test") {
@ -122,8 +120,6 @@ class UsersAPTest {
) )
person.context = listOf("https://www.w3.org/ns/activitystreams") person.context = listOf("https://www.w3.org/ns/activitystreams")
val userService = mock<IUserService> {}
val activityPubUserService = mock<ActivityPubUserService> { val activityPubUserService = mock<ActivityPubUserService> {
onBlocking { getPersonByName(anyString()) } doReturn person onBlocking { getPersonByName(anyString()) } doReturn person
} }
@ -131,7 +127,7 @@ class UsersAPTest {
application { application {
configureSerialization() configureSerialization()
routing { routing {
usersAP(activityPubUserService, userService) usersAP(activityPubUserService, mock(), mock())
} }
} }
client.get("/users/test") { client.get("/users/test") {
@ -174,8 +170,8 @@ class UsersAPTest {
environment { environment {
config = ApplicationConfig("empty.conf") config = ApplicationConfig("empty.conf")
} }
val userService = mock<IUserService> { val userService = mock<UserQueryService> {
onBlocking { findByNameLocalUser(eq("test")) } doReturn User( onBlocking { findByNameAndDomain(eq("test"), anyString()) } doReturn User(
1L, 1L,
"test", "test",
"example.com", "example.com",
@ -192,7 +188,7 @@ class UsersAPTest {
} }
application { application {
routing { routing {
usersAP(mock(), userService) usersAP(mock(), userService, mock())
} }
} }
client.get("/users/test") { client.get("/users/test") {