mirror of https://github.com/usbharu/Hideout.git
refactor: 不要な関数を削除
This commit is contained in:
parent
e781d1467f
commit
642912d5f3
|
@ -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.ReceiveFollowJob
|
||||
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.routing.register
|
||||
import dev.usbharu.hideout.service.activitypub.ActivityPubService
|
||||
|
@ -120,7 +122,8 @@ fun Application.parent() {
|
|||
userAuthService = inject<IUserAuthService>().value,
|
||||
userRepository = inject<IUserRepository>().value,
|
||||
jwtService = inject<IJwtService>().value,
|
||||
metaService = inject<IMetaService>().value
|
||||
userQueryService = inject<UserQueryService>().value,
|
||||
followerQueryService = inject<FollowerQueryService>().value
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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.routing.activitypub.inbox
|
||||
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.auth.HttpSignatureVerifyService
|
||||
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.user.IUserAuthService
|
||||
import dev.usbharu.hideout.service.user.IUserService
|
||||
|
@ -34,14 +35,15 @@ fun Application.configureRouting(
|
|||
userAuthService: IUserAuthService,
|
||||
userRepository: IUserRepository,
|
||||
jwtService: IJwtService,
|
||||
metaService: IMetaService
|
||||
userQueryService: UserQueryService,
|
||||
followerQueryService: FollowerQueryService
|
||||
) {
|
||||
install(AutoHeadResponse)
|
||||
routing {
|
||||
inbox(httpSignatureVerifyService, activityPubService)
|
||||
outbox()
|
||||
usersAP(activityPubUserService, userService)
|
||||
webfinger(userService)
|
||||
usersAP(activityPubUserService, userQueryService, followerQueryService)
|
||||
webfinger(userQueryService)
|
||||
route("/api/internal/v1") {
|
||||
posts(postService, reactionService)
|
||||
users(userService, userApiService)
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package dev.usbharu.hideout.routing.activitypub
|
||||
|
||||
import dev.usbharu.hideout.config.Config
|
||||
import dev.usbharu.hideout.exception.ParameterNotExistException
|
||||
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.user.IUserService
|
||||
import dev.usbharu.hideout.util.HttpUtil.Activity
|
||||
import dev.usbharu.hideout.util.HttpUtil.JsonLd
|
||||
import io.ktor.http.*
|
||||
|
@ -12,7 +14,11 @@ import io.ktor.server.request.*
|
|||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
|
||||
fun Routing.usersAP(activityPubUserService: ActivityPubUserService, userService: IUserService) {
|
||||
fun Routing.usersAP(
|
||||
activityPubUserService: ActivityPubUserService,
|
||||
userQueryService: UserQueryService,
|
||||
followerQueryService: FollowerQueryService
|
||||
) {
|
||||
route("/users/{name}") {
|
||||
createChild(ContentTypeRouteSelector(ContentType.Application.Activity, ContentType.Application.JsonLd)).handle {
|
||||
call.application.log.debug("Signature: ${call.request.header("Signature")}")
|
||||
|
@ -26,10 +32,11 @@ fun Routing.usersAP(activityPubUserService: ActivityPubUserService, userService:
|
|||
)
|
||||
}
|
||||
get {
|
||||
val userEntity = userService.findByNameLocalUser(
|
||||
call.parameters["name"] ?: throw ParameterNotExistException("Parameter(name='name') does not exist.")
|
||||
val userEntity = userQueryService.findByNameAndDomain(
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,14 @@ import dev.usbharu.hideout.config.Config
|
|||
import dev.usbharu.hideout.domain.model.wellknown.WebFinger
|
||||
import dev.usbharu.hideout.exception.IllegalParameterException
|
||||
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 io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
|
||||
fun Routing.webfinger(userService: IUserService) {
|
||||
fun Routing.webfinger(userQueryService: UserQueryService) {
|
||||
route("/.well-known/webfinger") {
|
||||
get {
|
||||
val acct = call.request.queryParameters["resource"]?.decodeURLPart()
|
||||
|
@ -25,7 +25,7 @@ fun Routing.webfinger(userService: IUserService) {
|
|||
.substringAfter("acct:")
|
||||
.trimStart('@')
|
||||
|
||||
val userEntity = userService.findByNameLocalUser(accountName)
|
||||
val userEntity = userQueryService.findByNameAndDomain(accountName, Config.configData.domain)
|
||||
|
||||
val webFinger = WebFinger(
|
||||
subject = acct,
|
||||
|
|
|
@ -9,6 +9,7 @@ import dev.usbharu.hideout.domain.model.hideout.dto.RemoteUserCreateDto
|
|||
import dev.usbharu.hideout.exception.UserNotFoundException
|
||||
import dev.usbharu.hideout.exception.ap.IllegalActivityPubObjectException
|
||||
import dev.usbharu.hideout.plugins.getAp
|
||||
import dev.usbharu.hideout.query.UserQueryService
|
||||
import dev.usbharu.hideout.service.user.IUserService
|
||||
import dev.usbharu.hideout.util.HttpUtil.Activity
|
||||
import io.ktor.client.*
|
||||
|
@ -20,13 +21,14 @@ import org.koin.core.annotation.Single
|
|||
@Single
|
||||
class ActivityPubUserServiceImpl(
|
||||
private val userService: IUserService,
|
||||
private val httpClient: HttpClient
|
||||
private val httpClient: HttpClient,
|
||||
private val userQueryService: UserQueryService
|
||||
) :
|
||||
ActivityPubUserService {
|
||||
|
||||
override suspend fun getPersonByName(name: String): Person {
|
||||
// TODO: JOINで書き直し
|
||||
val userEntity = userService.findByNameLocalUser(name)
|
||||
val userEntity = userQueryService.findByNameAndDomain(name, Config.configData.domain)
|
||||
val userUrl = "${Config.configData.url}/users/$name"
|
||||
return Person(
|
||||
type = emptyList(),
|
||||
|
@ -55,7 +57,7 @@ class ActivityPubUserServiceImpl(
|
|||
|
||||
override suspend fun fetchPerson(url: String, targetActor: String?): Person {
|
||||
return try {
|
||||
val userEntity = userService.findByUrl(url)
|
||||
val userEntity = userQueryService.findByUrl(url)
|
||||
return Person(
|
||||
type = emptyList(),
|
||||
name = userEntity.name,
|
||||
|
|
|
@ -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.hideout.entity.User
|
||||
import dev.usbharu.hideout.plugins.configureSerialization
|
||||
import dev.usbharu.hideout.query.UserQueryService
|
||||
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.JsonLd
|
||||
import io.ktor.client.request.*
|
||||
|
@ -62,8 +62,6 @@ class UsersAPTest {
|
|||
)
|
||||
person.context = listOf("https://www.w3.org/ns/activitystreams")
|
||||
|
||||
val userService = mock<IUserService> {}
|
||||
|
||||
val activityPubUserService = mock<ActivityPubUserService> {
|
||||
onBlocking { getPersonByName(anyString()) } doReturn person
|
||||
}
|
||||
|
@ -71,7 +69,7 @@ class UsersAPTest {
|
|||
application {
|
||||
configureSerialization()
|
||||
routing {
|
||||
usersAP(activityPubUserService, userService)
|
||||
usersAP(activityPubUserService, mock(), mock())
|
||||
}
|
||||
}
|
||||
client.get("/users/test") {
|
||||
|
@ -122,8 +120,6 @@ class UsersAPTest {
|
|||
)
|
||||
person.context = listOf("https://www.w3.org/ns/activitystreams")
|
||||
|
||||
val userService = mock<IUserService> {}
|
||||
|
||||
val activityPubUserService = mock<ActivityPubUserService> {
|
||||
onBlocking { getPersonByName(anyString()) } doReturn person
|
||||
}
|
||||
|
@ -131,7 +127,7 @@ class UsersAPTest {
|
|||
application {
|
||||
configureSerialization()
|
||||
routing {
|
||||
usersAP(activityPubUserService, userService)
|
||||
usersAP(activityPubUserService, mock(), mock())
|
||||
}
|
||||
}
|
||||
client.get("/users/test") {
|
||||
|
@ -174,8 +170,8 @@ class UsersAPTest {
|
|||
environment {
|
||||
config = ApplicationConfig("empty.conf")
|
||||
}
|
||||
val userService = mock<IUserService> {
|
||||
onBlocking { findByNameLocalUser(eq("test")) } doReturn User(
|
||||
val userService = mock<UserQueryService> {
|
||||
onBlocking { findByNameAndDomain(eq("test"), anyString()) } doReturn User(
|
||||
1L,
|
||||
"test",
|
||||
"example.com",
|
||||
|
@ -192,7 +188,7 @@ class UsersAPTest {
|
|||
}
|
||||
application {
|
||||
routing {
|
||||
usersAP(mock(), userService)
|
||||
usersAP(mock(), userService, mock())
|
||||
}
|
||||
}
|
||||
client.get("/users/test") {
|
||||
|
|
Loading…
Reference in New Issue