From c056b7598b1a18b7d55437e6e91a99111f70e975 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 6 Aug 2024 13:00:00 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E3=81=97=E3=81=84=E8=AA=8D?= =?UTF-8?q?=E5=8F=AF=E3=82=B7=E3=82=B9=E3=83=86=E3=83=A0=E3=82=92=E7=B5=84?= =?UTF-8?q?=E3=81=BF=E8=BE=BC=E3=81=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/application/filter/RegisterFilter.kt | 2 - .../UserRegisterFilterApplicationService.kt | 10 +-- .../application/post/RegisterLocalPost.kt | 1 - .../RegisterLocalPostApplicationService.kt | 11 ++-- .../AcceptFollowRequest.kt | 4 +- ...erAcceptFollowRequestApplicationService.kt | 10 +-- .../application/relationship/block/Block.kt | 4 +- .../block/UserBlockApplicationService.kt | 10 +-- .../followrequest/FollowRequest.kt | 4 +- .../UserFollowRequestApplicationService.kt | 10 +-- .../relationship/get/GetRelationship.kt | 4 +- .../get/GetRelationshipApplicationService.kt | 10 +-- .../application/relationship/mute/Mute.kt | 4 +- .../mute/UserMuteApplicationService.kt | 10 +-- .../RejectFollowRequest.kt | 4 +- ...erRejectFollowRequestApplicationService.kt | 10 +-- .../RemoveFromFollowers.kt | 2 +- ...erRemoveFromFollowersApplicationService.kt | 11 ++-- .../relationship/unblock/Unblock.kt | 4 +- .../unblock/UserUnblockApplicationService.kt | 10 +-- .../relationship/unfollow/Unfollow.kt | 4 +- .../UserUnfollowApplicationService.kt | 10 +-- .../application/relationship/unmute/Unmute.kt | 4 +- .../unmute/UserUnmuteApplicationService.kt | 10 +-- .../application/shared/CommandExecutor.kt | 30 --------- .../domain/model/support/principal/FromApi.kt | 9 ++- .../principal/PrincipalContextHolder.kt | 5 ++ .../ExposedPrincipalQueryService.kt | 37 +++++++++++ .../DelegateCommandExecutorFactory.kt | 36 ---------- .../springframework/HttpCommandExecutor.kt | 27 -------- .../SpringMvcCommandExecutorFactory.kt | 31 --------- .../oauth2/Oauth2CommandExecutor.kt | 24 ------- .../oauth2/Oauth2CommandExecutorFactory.kt | 33 ---------- ...ingSecurityOauth2PrincipalContextHolder.kt | 27 ++++++++ .../interfaces/api/auth/AuthController.kt | 2 - .../core/query/principal/PrincipalDTO.kt | 6 ++ .../query/principal/PrincipalQueryService.kt | 7 ++ .../interfaces/api/SpringAccountApi.kt | 65 +++++++++---------- .../interfaces/api/SpringFilterApi.kt | 22 +++---- .../mastodon/interfaces/api/SpringMediaApi.kt | 6 +- .../interfaces/api/SpringStatusApi.kt | 15 ++--- 41 files changed, 210 insertions(+), 335 deletions(-) delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/shared/CommandExecutor.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/principal/PrincipalContextHolder.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedquery/ExposedPrincipalQueryService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/DelegateCommandExecutorFactory.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/HttpCommandExecutor.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/SpringMvcCommandExecutorFactory.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/Oauth2CommandExecutor.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/Oauth2CommandExecutorFactory.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/SpringSecurityOauth2PrincipalContextHolder.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/principal/PrincipalDTO.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/principal/PrincipalQueryService.kt diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/RegisterFilter.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/RegisterFilter.kt index f4f8dd91..3fd9a35f 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/RegisterFilter.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/RegisterFilter.kt @@ -18,12 +18,10 @@ package dev.usbharu.hideout.core.application.filter import dev.usbharu.hideout.core.domain.model.filter.FilterAction import dev.usbharu.hideout.core.domain.model.filter.FilterContext -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId data class RegisterFilter( val filterName: String, val filterContext: Set, val filterAction: FilterAction, val filterKeywords: Set, - val userDetailId: UserDetailId ) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserRegisterFilterApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserRegisterFilterApplicationService.kt index 8bf5b3a3..bf12c041 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserRegisterFilterApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserRegisterFilterApplicationService.kt @@ -16,11 +16,11 @@ package dev.usbharu.hideout.core.application.filter -import dev.usbharu.hideout.core.application.shared.AbstractApplicationService +import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.filter.* import dev.usbharu.hideout.core.domain.model.filter.FilterKeyword -import dev.usbharu.hideout.core.domain.model.support.principal.Principal +import dev.usbharu.hideout.core.domain.model.support.principal.FromApi import dev.usbharu.hideout.core.domain.shared.id.IdGenerateService import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -31,16 +31,16 @@ class UserRegisterFilterApplicationService( private val filterRepository: FilterRepository, transaction: Transaction, ) : - AbstractApplicationService( + LocalUserAbstractApplicationService( transaction, logger ) { - override suspend fun internalExecute(command: RegisterFilter, principal: Principal): Filter { + override suspend fun internalExecute(command: RegisterFilter, principal: FromApi): Filter { val filter = dev.usbharu.hideout.core.domain.model.filter.Filter.create( id = FilterId(idGenerateService.generateId()), - userDetailId = command.userDetailId, + userDetailId = principal.userDetailId, name = FilterName(command.filterName), filterContext = command.filterContext, filterAction = command.filterAction, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPost.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPost.kt index 16f1092e..b5fd2f71 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPost.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPost.kt @@ -19,7 +19,6 @@ package dev.usbharu.hideout.core.application.post import dev.usbharu.hideout.core.domain.model.post.Visibility data class RegisterLocalPost( - val userDetailId: Long, val content: String, val overview: String?, val visibility: Visibility, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationService.kt index 95bfe505..d0658179 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationService.kt @@ -16,15 +16,14 @@ package dev.usbharu.hideout.core.application.post -import dev.usbharu.hideout.core.application.shared.AbstractApplicationService +import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.media.MediaId import dev.usbharu.hideout.core.domain.model.post.PostId import dev.usbharu.hideout.core.domain.model.post.PostOverview import dev.usbharu.hideout.core.domain.model.post.PostRepository -import dev.usbharu.hideout.core.domain.model.support.principal.Principal -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId +import dev.usbharu.hideout.core.domain.model.support.principal.FromApi import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import dev.usbharu.hideout.core.infrastructure.factory.PostFactoryImpl import org.slf4j.Logger @@ -38,11 +37,11 @@ class RegisterLocalPostApplicationService( private val postRepository: PostRepository, private val userDetailRepository: UserDetailRepository, transaction: Transaction, -) : AbstractApplicationService(transaction, Companion.logger) { +) : LocalUserAbstractApplicationService(transaction, Companion.logger) { - override suspend fun internalExecute(command: RegisterLocalPost, principal: Principal): Long { + override suspend fun internalExecute(command: RegisterLocalPost, principal: FromApi): Long { val actorId = ( - userDetailRepository.findById(UserDetailId(command.userDetailId)) + userDetailRepository.findById(principal.userDetailId) ?: throw IllegalStateException("actor not found") ).actorId diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/AcceptFollowRequest.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/AcceptFollowRequest.kt index 16085792..6c0d9f20 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/AcceptFollowRequest.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/AcceptFollowRequest.kt @@ -16,6 +16,4 @@ package dev.usbharu.hideout.core.application.relationship.acceptfollowrequest -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId - -data class AcceptFollowRequest(val sourceActorId: Long, val userDetailId: UserDetailId) +data class AcceptFollowRequest(val sourceActorId: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/UserAcceptFollowRequestApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/UserAcceptFollowRequestApplicationService.kt index ef7a382a..a80497e6 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/UserAcceptFollowRequestApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/UserAcceptFollowRequestApplicationService.kt @@ -17,12 +17,12 @@ package dev.usbharu.hideout.core.application.relationship.acceptfollowrequest import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService -import dev.usbharu.hideout.core.application.shared.AbstractApplicationService +import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository -import dev.usbharu.hideout.core.domain.model.support.principal.Principal +import dev.usbharu.hideout.core.domain.model.support.principal.FromApi import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -34,10 +34,10 @@ class UserAcceptFollowRequestApplicationService( private val actorRepository: ActorRepository, private val userDetailRepository: UserDetailRepository, ) : - AbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: AcceptFollowRequest, principal: Principal) { + LocalUserAbstractApplicationService(transaction, logger) { + override suspend fun internalExecute(command: AcceptFollowRequest, principal: FromApi) { - val userDetail = userDetailRepository.findById(command.userDetailId)!! + val userDetail = userDetailRepository.findById(principal.userDetailId)!! val actor = actorRepository.findById(userDetail.actorId)!! val targetId = ActorId(command.sourceActorId) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/block/Block.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/block/Block.kt index 8441162c..7a095b92 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/block/Block.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/block/Block.kt @@ -16,6 +16,4 @@ package dev.usbharu.hideout.core.application.relationship.block -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId - -data class Block(val targetActorId: Long, val userDetailId: UserDetailId) +data class Block(val targetActorId: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/block/UserBlockApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/block/UserBlockApplicationService.kt index f8baa681..91a99c4f 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/block/UserBlockApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/block/UserBlockApplicationService.kt @@ -16,13 +16,13 @@ package dev.usbharu.hideout.core.application.relationship.block -import dev.usbharu.hideout.core.application.shared.AbstractApplicationService +import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.relationship.Relationship import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository -import dev.usbharu.hideout.core.domain.model.support.principal.Principal +import dev.usbharu.hideout.core.domain.model.support.principal.FromApi import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import dev.usbharu.hideout.core.domain.service.relationship.RelationshipDomainService import org.slf4j.LoggerFactory @@ -36,10 +36,10 @@ class UserBlockApplicationService( private val userDetailRepository: UserDetailRepository, private val relationshipDomainService: RelationshipDomainService, ) : - AbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: Block, principal: Principal) { + LocalUserAbstractApplicationService(transaction, logger) { + override suspend fun internalExecute(command: Block, principal: FromApi) { - val userDetail = userDetailRepository.findById(command.userDetailId)!! + val userDetail = userDetailRepository.findById(principal.userDetailId)!! val actor = actorRepository.findById(userDetail.actorId)!! val targetId = ActorId(command.targetActorId) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/followrequest/FollowRequest.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/followrequest/FollowRequest.kt index 1c83f259..3f8de0a7 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/followrequest/FollowRequest.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/followrequest/FollowRequest.kt @@ -16,6 +16,4 @@ package dev.usbharu.hideout.core.application.relationship.followrequest -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId - -data class FollowRequest(val targetActorId: Long, val userDetailId: UserDetailId) +data class FollowRequest(val targetActorId: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/followrequest/UserFollowRequestApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/followrequest/UserFollowRequestApplicationService.kt index b1dfe181..0c9d967d 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/followrequest/UserFollowRequestApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/followrequest/UserFollowRequestApplicationService.kt @@ -16,13 +16,13 @@ package dev.usbharu.hideout.core.application.relationship.followrequest -import dev.usbharu.hideout.core.application.shared.AbstractApplicationService +import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.relationship.Relationship import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository -import dev.usbharu.hideout.core.domain.model.support.principal.Principal +import dev.usbharu.hideout.core.domain.model.support.principal.FromApi import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -33,14 +33,14 @@ class UserFollowRequestApplicationService( transaction: Transaction, private val actorRepository: ActorRepository, private val userDetailRepository: UserDetailRepository, -) : AbstractApplicationService( +) : LocalUserAbstractApplicationService( transaction, logger ) { - override suspend fun internalExecute(command: FollowRequest, principal: Principal) { + override suspend fun internalExecute(command: FollowRequest, principal: FromApi) { - val userDetail = userDetailRepository.findById(command.userDetailId)!! + val userDetail = userDetailRepository.findById(principal.userDetailId)!! val actor = actorRepository.findById(userDetail.actorId)!! val targetId = ActorId(command.targetActorId) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationship.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationship.kt index 49427257..90df1b82 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationship.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationship.kt @@ -16,6 +16,4 @@ package dev.usbharu.hideout.core.application.relationship.get -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId - -data class GetRelationship(val targetActorId: Long, val userDetailId: UserDetailId) +data class GetRelationship(val targetActorId: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationshipApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationshipApplicationService.kt index ecc8b6e7..b832710d 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationshipApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationshipApplicationService.kt @@ -16,14 +16,14 @@ package dev.usbharu.hideout.core.application.relationship.get -import dev.usbharu.hideout.core.application.shared.AbstractApplicationService +import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.actorinstancerelationship.ActorInstanceRelationship import dev.usbharu.hideout.core.domain.model.actorinstancerelationship.ActorInstanceRelationshipRepository import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository -import dev.usbharu.hideout.core.domain.model.support.principal.Principal +import dev.usbharu.hideout.core.domain.model.support.principal.FromApi import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -36,12 +36,12 @@ class GetRelationshipApplicationService( private val actorInstanceRelationshipRepository: ActorInstanceRelationshipRepository, transaction: Transaction, ) : - AbstractApplicationService( + LocalUserAbstractApplicationService( transaction, logger ) { - override suspend fun internalExecute(command: GetRelationship, principal: Principal): Relationship { - val userDetail = userDetailRepository.findById(command.userDetailId)!! + override suspend fun internalExecute(command: GetRelationship, principal: FromApi): Relationship { + val userDetail = userDetailRepository.findById(principal.userDetailId)!! val actor = actorRepository.findById(userDetail.actorId)!! val targetId = ActorId(command.targetActorId) val target = actorRepository.findById(targetId)!! diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/mute/Mute.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/mute/Mute.kt index fffd5258..79a56830 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/mute/Mute.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/mute/Mute.kt @@ -16,6 +16,4 @@ package dev.usbharu.hideout.core.application.relationship.mute -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId - -data class Mute(val targetActorId: Long, val userDetailId: UserDetailId) +data class Mute(val targetActorId: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/mute/UserMuteApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/mute/UserMuteApplicationService.kt index 999a76fc..7c611d24 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/mute/UserMuteApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/mute/UserMuteApplicationService.kt @@ -17,13 +17,13 @@ package dev.usbharu.hideout.core.application.relationship.mute import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService -import dev.usbharu.hideout.core.application.shared.AbstractApplicationService +import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.relationship.Relationship import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository -import dev.usbharu.hideout.core.domain.model.support.principal.Principal +import dev.usbharu.hideout.core.domain.model.support.principal.FromApi import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -35,10 +35,10 @@ class UserMuteApplicationService( private val actorRepository: ActorRepository, private val userDetailRepository: UserDetailRepository, ) : - AbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: Mute, principal: Principal) { + LocalUserAbstractApplicationService(transaction, logger) { + override suspend fun internalExecute(command: Mute, principal: FromApi) { - val userDetail = userDetailRepository.findById(command.userDetailId)!! + val userDetail = userDetailRepository.findById(principal.userDetailId)!! val actor = actorRepository.findById(userDetail.actorId)!! val targetId = ActorId(command.targetActorId) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/RejectFollowRequest.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/RejectFollowRequest.kt index e22b8e05..4662eff1 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/RejectFollowRequest.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/RejectFollowRequest.kt @@ -16,6 +16,4 @@ package dev.usbharu.hideout.core.application.relationship.rejectfollowrequest -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId - -data class RejectFollowRequest(val sourceActorId: Long, val userDetailId: UserDetailId) +data class RejectFollowRequest(val sourceActorId: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/UserRejectFollowRequestApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/UserRejectFollowRequestApplicationService.kt index b2f39da4..97adbdd0 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/UserRejectFollowRequestApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/UserRejectFollowRequestApplicationService.kt @@ -17,12 +17,12 @@ package dev.usbharu.hideout.core.application.relationship.rejectfollowrequest import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService -import dev.usbharu.hideout.core.application.shared.AbstractApplicationService +import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository -import dev.usbharu.hideout.core.domain.model.support.principal.Principal +import dev.usbharu.hideout.core.domain.model.support.principal.FromApi import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -34,10 +34,10 @@ class UserRejectFollowRequestApplicationService( private val actorRepository: ActorRepository, private val userDetailRepository: UserDetailRepository, ) : - AbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: RejectFollowRequest, principal: Principal) { + LocalUserAbstractApplicationService(transaction, logger) { + override suspend fun internalExecute(command: RejectFollowRequest, principal: FromApi) { - val userDetail = userDetailRepository.findById(command.userDetailId)!! + val userDetail = userDetailRepository.findById(principal.userDetailId)!! val actor = actorRepository.findById(userDetail.actorId)!! val targetId = ActorId(command.sourceActorId) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/removefromfollowers/RemoveFromFollowers.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/removefromfollowers/RemoveFromFollowers.kt index ff8bdd63..f9642099 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/removefromfollowers/RemoveFromFollowers.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/removefromfollowers/RemoveFromFollowers.kt @@ -16,4 +16,4 @@ package dev.usbharu.hideout.core.application.relationship.removefromfollowers -data class RemoveFromFollowers(val targetActorId: Long, val userDetailId: Long) +data class RemoveFromFollowers(val targetActorId: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/removefromfollowers/UserRemoveFromFollowersApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/removefromfollowers/UserRemoveFromFollowersApplicationService.kt index 2d6ab718..d3e50e50 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/removefromfollowers/UserRemoveFromFollowersApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/removefromfollowers/UserRemoveFromFollowersApplicationService.kt @@ -17,14 +17,13 @@ package dev.usbharu.hideout.core.application.relationship.removefromfollowers import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService -import dev.usbharu.hideout.core.application.shared.AbstractApplicationService +import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.relationship.Relationship import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository -import dev.usbharu.hideout.core.domain.model.support.principal.Principal -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId +import dev.usbharu.hideout.core.domain.model.support.principal.FromApi import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -36,10 +35,10 @@ class UserRemoveFromFollowersApplicationService( private val actorRepository: ActorRepository, private val userDetailRepository: UserDetailRepository, ) : - AbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: RemoveFromFollowers, principal: Principal) { + LocalUserAbstractApplicationService(transaction, logger) { + override suspend fun internalExecute(command: RemoveFromFollowers, principal: FromApi) { - val userDetail = userDetailRepository.findById(UserDetailId(command.userDetailId))!! + val userDetail = userDetailRepository.findById(principal.userDetailId)!! val actor = actorRepository.findById(userDetail.actorId)!! val targetId = ActorId(command.targetActorId) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unblock/Unblock.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unblock/Unblock.kt index 7b376ce1..7b85c603 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unblock/Unblock.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unblock/Unblock.kt @@ -16,6 +16,4 @@ package dev.usbharu.hideout.core.application.relationship.unblock -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId - -data class Unblock(val targetActorId: Long, val userDetailId: UserDetailId) +data class Unblock(val targetActorId: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unblock/UserUnblockApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unblock/UserUnblockApplicationService.kt index fd8a1962..d5417799 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unblock/UserUnblockApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unblock/UserUnblockApplicationService.kt @@ -17,13 +17,13 @@ package dev.usbharu.hideout.core.application.relationship.unblock import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService -import dev.usbharu.hideout.core.application.shared.AbstractApplicationService +import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.relationship.Relationship import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository -import dev.usbharu.hideout.core.domain.model.support.principal.Principal +import dev.usbharu.hideout.core.domain.model.support.principal.FromApi import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -35,10 +35,10 @@ class UserUnblockApplicationService( private val actorRepository: ActorRepository, private val userDetailRepository: UserDetailRepository, ) : - AbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: Unblock, principal: Principal) { + LocalUserAbstractApplicationService(transaction, logger) { + override suspend fun internalExecute(command: Unblock, principal: FromApi) { - val userDetail = userDetailRepository.findById(command.userDetailId)!! + val userDetail = userDetailRepository.findById(principal.userDetailId)!! val actor = actorRepository.findById(userDetail.actorId)!! val targetId = ActorId(command.targetActorId) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unfollow/Unfollow.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unfollow/Unfollow.kt index 36353933..60190dab 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unfollow/Unfollow.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unfollow/Unfollow.kt @@ -16,6 +16,4 @@ package dev.usbharu.hideout.core.application.relationship.unfollow -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId - -data class Unfollow(val targetActorId: Long, val userDetailId: UserDetailId) +data class Unfollow(val targetActorId: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unfollow/UserUnfollowApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unfollow/UserUnfollowApplicationService.kt index 9c44a183..a7068d00 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unfollow/UserUnfollowApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unfollow/UserUnfollowApplicationService.kt @@ -17,13 +17,13 @@ package dev.usbharu.hideout.core.application.relationship.unfollow import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService -import dev.usbharu.hideout.core.application.shared.AbstractApplicationService +import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.relationship.Relationship import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository -import dev.usbharu.hideout.core.domain.model.support.principal.Principal +import dev.usbharu.hideout.core.domain.model.support.principal.FromApi import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -35,10 +35,10 @@ class UserUnfollowApplicationService( private val actorRepository: ActorRepository, private val userDetailRepository: UserDetailRepository, ) : - AbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: Unfollow, principal: Principal) { + LocalUserAbstractApplicationService(transaction, logger) { + override suspend fun internalExecute(command: Unfollow, principal: FromApi) { - val userDetail = userDetailRepository.findById(command.userDetailId)!! + val userDetail = userDetailRepository.findById(principal.userDetailId)!! val actor = actorRepository.findById(userDetail.actorId)!! val targetId = ActorId(command.targetActorId) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unmute/Unmute.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unmute/Unmute.kt index 8df2fbab..1939ee25 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unmute/Unmute.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unmute/Unmute.kt @@ -16,6 +16,4 @@ package dev.usbharu.hideout.core.application.relationship.unmute -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId - -data class Unmute(val targetActorId: Long, val userDetailId: UserDetailId) +data class Unmute(val targetActorId: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unmute/UserUnmuteApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unmute/UserUnmuteApplicationService.kt index 2ddcd20a..b90ba059 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unmute/UserUnmuteApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unmute/UserUnmuteApplicationService.kt @@ -17,13 +17,13 @@ package dev.usbharu.hideout.core.application.relationship.unmute import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService -import dev.usbharu.hideout.core.application.shared.AbstractApplicationService +import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.relationship.Relationship import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository -import dev.usbharu.hideout.core.domain.model.support.principal.Principal +import dev.usbharu.hideout.core.domain.model.support.principal.FromApi import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -35,14 +35,14 @@ class UserUnmuteApplicationService( private val actorRepository: ActorRepository, private val userDetailRepository: UserDetailRepository, ) : - AbstractApplicationService(transaction, logger) { + LocalUserAbstractApplicationService(transaction, logger) { companion object { private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) } - override suspend fun internalExecute(command: Unmute, principal: Principal) { + override suspend fun internalExecute(command: Unmute, principal: FromApi) { - val userDetail = userDetailRepository.findById(command.userDetailId)!! + val userDetail = userDetailRepository.findById(principal.userDetailId)!! val actor = actorRepository.findById(userDetail.actorId)!! val targetId = ActorId(command.targetActorId) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/shared/CommandExecutor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/shared/CommandExecutor.kt deleted file mode 100644 index 1974ba16..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/shared/CommandExecutor.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.core.application.shared - -interface CommandExecutor { - val executor: String -} - -interface UserDetailGettableCommandExecutor : CommandExecutor { - val userDetailId: Long -} - -data class DomainEventCommandExecutor( - override val executor: String, - val commandExecutor: CommandExecutor? -) : CommandExecutor \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/principal/FromApi.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/principal/FromApi.kt index 93215882..2ce5f785 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/principal/FromApi.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/principal/FromApi.kt @@ -4,7 +4,12 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.support.acct.Acct import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId -class FromApi(actorId: ActorId, override val userDetailId: UserDetailId, override val acct: Acct) : Principal( - actorId, userDetailId, +class FromApi( + actorId: ActorId, + override val userDetailId: UserDetailId, + override val acct: Acct +) : Principal( + actorId, + userDetailId, acct ) \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/principal/PrincipalContextHolder.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/principal/PrincipalContextHolder.kt new file mode 100644 index 00000000..464363ce --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/principal/PrincipalContextHolder.kt @@ -0,0 +1,5 @@ +package dev.usbharu.hideout.core.domain.model.support.principal + +interface PrincipalContextHolder { + suspend fun getPrincipal(): Principal +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedquery/ExposedPrincipalQueryService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedquery/ExposedPrincipalQueryService.kt new file mode 100644 index 00000000..413ccc67 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedquery/ExposedPrincipalQueryService.kt @@ -0,0 +1,37 @@ +package dev.usbharu.hideout.core.infrastructure.exposedquery + +import dev.usbharu.hideout.core.domain.model.actor.ActorId +import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId +import dev.usbharu.hideout.core.infrastructure.exposedrepository.AbstractRepository +import dev.usbharu.hideout.core.infrastructure.exposedrepository.Actors +import dev.usbharu.hideout.core.infrastructure.exposedrepository.UserDetails +import dev.usbharu.hideout.core.query.principal.PrincipalDTO +import dev.usbharu.hideout.core.query.principal.PrincipalQueryService +import org.jetbrains.exposed.sql.selectAll +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Repository + +@Repository +class ExposedPrincipalQueryService : PrincipalQueryService, AbstractRepository() { + override suspend fun findByUserDetailId(userDetailId: UserDetailId): PrincipalDTO { + return query { + UserDetails.leftJoin(Actors).selectAll().where { UserDetails.id eq userDetailId.id }.single() + .let { + PrincipalDTO( + UserDetailId(it[UserDetails.id]), + ActorId(it[UserDetails.actorId]), + it[Actors.name], + it[Actors.domain] + ) + } + } + } + + override val logger: Logger + get() = Companion.logger + + companion object { + private val logger: Logger = LoggerFactory.getLogger(ExposedPrincipalQueryService::class.java) + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/DelegateCommandExecutorFactory.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/DelegateCommandExecutorFactory.kt deleted file mode 100644 index cedebc83..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/DelegateCommandExecutorFactory.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.core.infrastructure.springframework - -import dev.usbharu.hideout.core.application.shared.CommandExecutor -import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.Oauth2CommandExecutorFactory -import org.springframework.security.core.context.SecurityContextHolder -import org.springframework.security.oauth2.jwt.Jwt -import org.springframework.stereotype.Component - -@Component -class DelegateCommandExecutorFactory( - private val oauth2CommandExecutorFactory: Oauth2CommandExecutorFactory, - private val mvcCommandExecutorFactory: SpringMvcCommandExecutorFactory, -) { - fun getCommandExecutor(): CommandExecutor { - if (SecurityContextHolder.getContext().authentication.principal is Jwt) { - return oauth2CommandExecutorFactory.getCommandExecutor() - } - return mvcCommandExecutorFactory.getCommandExecutor() - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/HttpCommandExecutor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/HttpCommandExecutor.kt deleted file mode 100644 index e7b28ed5..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/HttpCommandExecutor.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.core.infrastructure.springframework - -import dev.usbharu.hideout.core.application.shared.CommandExecutor - -open class HttpCommandExecutor( - override val executor: String, - val ip: String, - val userAgent: String, -) : CommandExecutor { - override fun toString(): String = "HttpCommandExecutor(executor='$executor', ip='$ip', userAgent='$userAgent')" -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/SpringMvcCommandExecutorFactory.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/SpringMvcCommandExecutorFactory.kt deleted file mode 100644 index 7a9b5940..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/SpringMvcCommandExecutorFactory.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.core.infrastructure.springframework - -import org.springframework.security.core.context.SecurityContextHolder -import org.springframework.stereotype.Component -import org.springframework.web.context.request.RequestContextHolder -import org.springframework.web.context.request.ServletRequestAttributes - -@Component -class SpringMvcCommandExecutorFactory { - fun getCommandExecutor(): HttpCommandExecutor { - val name = SecurityContextHolder.getContext().authentication?.name ?: "ANONYMOUS" - val request = (RequestContextHolder.currentRequestAttributes() as ServletRequestAttributes).request - return HttpCommandExecutor(name, request.remoteAddr, request.getHeader("user-agent").orEmpty()) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/Oauth2CommandExecutor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/Oauth2CommandExecutor.kt deleted file mode 100644 index 9cf58a40..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/Oauth2CommandExecutor.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.core.infrastructure.springframework.oauth2 - -import dev.usbharu.hideout.core.application.shared.CommandExecutor -import dev.usbharu.hideout.core.application.shared.UserDetailGettableCommandExecutor - -class Oauth2CommandExecutor(override val executor: String, override val userDetailId: Long) : - CommandExecutor, - UserDetailGettableCommandExecutor diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/Oauth2CommandExecutorFactory.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/Oauth2CommandExecutorFactory.kt deleted file mode 100644 index 1416a2a3..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/Oauth2CommandExecutorFactory.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.core.infrastructure.springframework.oauth2 - -import org.springframework.security.core.context.SecurityContextHolder -import org.springframework.security.oauth2.jwt.Jwt -import org.springframework.stereotype.Component - -@Component -class Oauth2CommandExecutorFactory { - fun getCommandExecutor(): Oauth2CommandExecutor { - val principal = SecurityContextHolder.getContext().authentication.principal as Jwt - - return Oauth2CommandExecutor( - principal.subject, - principal.getClaim("uid").toLong() - ) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/SpringSecurityOauth2PrincipalContextHolder.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/SpringSecurityOauth2PrincipalContextHolder.kt new file mode 100644 index 00000000..68341349 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/SpringSecurityOauth2PrincipalContextHolder.kt @@ -0,0 +1,27 @@ +package dev.usbharu.hideout.core.infrastructure.springframework.oauth2 + +import dev.usbharu.hideout.core.domain.model.support.acct.Acct +import dev.usbharu.hideout.core.domain.model.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder +import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId +import dev.usbharu.hideout.core.query.principal.PrincipalQueryService +import org.springframework.security.core.context.SecurityContextHolder +import org.springframework.security.oauth2.jwt.Jwt +import org.springframework.stereotype.Component + +@Component +class SpringSecurityOauth2PrincipalContextHolder(private val principalQueryService: PrincipalQueryService) : + PrincipalContextHolder { + override suspend fun getPrincipal(): FromApi { + val principal = SecurityContextHolder.getContext().authentication?.principal as Jwt + + val id = principal.getClaim("uid").toLong() + val userDetail = principalQueryService.findByUserDetailId(UserDetailId(id)) + + return FromApi( + userDetail.actorId, + userDetail.userDetailId, + Acct(userDetail.username, userDetail.host) + ) + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt index 64687efd..8872d60d 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt @@ -19,7 +19,6 @@ package dev.usbharu.hideout.core.interfaces.api.auth import dev.usbharu.hideout.core.application.actor.RegisterLocalActor import dev.usbharu.hideout.core.application.actor.RegisterLocalActorApplicationService import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous -import dev.usbharu.hideout.core.infrastructure.springframework.SpringMvcCommandExecutorFactory import jakarta.servlet.http.HttpServletRequest import org.springframework.stereotype.Controller import org.springframework.validation.annotation.Validated @@ -30,7 +29,6 @@ import org.springframework.web.bind.annotation.PostMapping @Controller class AuthController( private val registerLocalActorApplicationService: RegisterLocalActorApplicationService, - private val springMvcCommandExecutorFactory: SpringMvcCommandExecutorFactory, ) { @GetMapping("/auth/sign_up") @Suppress("FunctionOnlyReturningConstant") diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/principal/PrincipalDTO.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/principal/PrincipalDTO.kt new file mode 100644 index 00000000..40b0cb90 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/principal/PrincipalDTO.kt @@ -0,0 +1,6 @@ +package dev.usbharu.hideout.core.query.principal + +import dev.usbharu.hideout.core.domain.model.actor.ActorId +import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId + +data class PrincipalDTO(val userDetailId: UserDetailId, val actorId: ActorId, val username: String, val host: String) \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/principal/PrincipalQueryService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/principal/PrincipalQueryService.kt new file mode 100644 index 00000000..3aa01531 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/query/principal/PrincipalQueryService.kt @@ -0,0 +1,7 @@ +package dev.usbharu.hideout.core.query.principal + +import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId + +interface PrincipalQueryService { + suspend fun findByUserDetailId(userDetailId: UserDetailId): PrincipalDTO +} \ No newline at end of file diff --git a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringAccountApi.kt b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringAccountApi.kt index 2f367367..4a3dd110 100644 --- a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringAccountApi.kt +++ b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringAccountApi.kt @@ -38,8 +38,7 @@ import dev.usbharu.hideout.core.application.relationship.unfollow.Unfollow import dev.usbharu.hideout.core.application.relationship.unfollow.UserUnfollowApplicationService import dev.usbharu.hideout.core.application.relationship.unmute.Unmute import dev.usbharu.hideout.core.application.relationship.unmute.UserUnmuteApplicationService -import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.Oauth2CommandExecutor -import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.Oauth2CommandExecutorFactory +import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.SpringSecurityOauth2PrincipalContextHolder import dev.usbharu.hideout.mastodon.application.accounts.GetAccount import dev.usbharu.hideout.mastodon.application.accounts.GetAccountApplicationService import dev.usbharu.hideout.mastodon.interfaces.api.generated.AccountApi @@ -49,7 +48,6 @@ import org.springframework.stereotype.Controller @Controller class SpringAccountApi( - private val oauth2CommandExecutorFactory: Oauth2CommandExecutorFactory, private val getUserDetailApplicationService: GetUserDetailApplicationService, private val getAccountApplicationService: GetAccountApplicationService, private val userFollowRequestApplicationService: UserFollowRequestApplicationService, @@ -62,31 +60,33 @@ class SpringAccountApi( private val userRejectFollowRequestApplicationService: UserRejectFollowRequestApplicationService, private val userRemoveFromFollowersApplicationService: UserRemoveFromFollowersApplicationService, private val userUnfollowApplicationService: UserUnfollowApplicationService, + private val principalContextHolder: SpringSecurityOauth2PrincipalContextHolder ) : AccountApi { override suspend fun apiV1AccountsIdBlockPost(id: String): ResponseEntity { - val executor = oauth2CommandExecutorFactory.getCommandExecutor() - userBlockApplicationService.execute(Block(id.toLong())) - return fetchRelationship(id, executor) + userBlockApplicationService.execute(Block(id.toLong()), principalContextHolder.getPrincipal()) + return fetchRelationship(id) } override suspend fun apiV1AccountsIdFollowPost( id: String, followRequestBody: FollowRequestBody?, ): ResponseEntity { - val executor = oauth2CommandExecutorFactory.getCommandExecutor() + userFollowRequestApplicationService.execute( - FollowRequest(id.toLong()) + FollowRequest(id.toLong()), principalContextHolder.getPrincipal() ) - return fetchRelationship(id, executor) + return fetchRelationship(id) } private suspend fun fetchRelationship( id: String, - executor: Oauth2CommandExecutor, ): ResponseEntity { - val relationship = getRelationshipApplicationService.execute(GetRelationship(id.toLong())) + val relationship = getRelationshipApplicationService.execute( + GetRelationship(id.toLong()), + principalContextHolder.getPrincipal() + ) return ResponseEntity.ok( Relationship( id = relationship.targetId.toString(), @@ -109,49 +109,44 @@ class SpringAccountApi( override suspend fun apiV1AccountsIdGet(id: String): ResponseEntity { return ResponseEntity.ok( getAccountApplicationService.execute( - GetAccount(id) + GetAccount(id), principalContextHolder.getPrincipal() ) ) } override suspend fun apiV1AccountsIdMutePost(id: String): ResponseEntity { - val executor = oauth2CommandExecutorFactory.getCommandExecutor() userMuteApplicationService.execute( - Mute(id.toLong()) + Mute(id.toLong()), principalContextHolder.getPrincipal() ) - return fetchRelationship(id, executor) + return fetchRelationship(id) } override suspend fun apiV1AccountsIdRemoveFromFollowersPost(id: String): ResponseEntity { - val executor = oauth2CommandExecutorFactory.getCommandExecutor() userRemoveFromFollowersApplicationService.execute( - RemoveFromFollowers(id.toLong()) + RemoveFromFollowers(id.toLong()), principalContextHolder.getPrincipal() ) - return fetchRelationship(id, executor) + return fetchRelationship(id) } override suspend fun apiV1AccountsIdUnblockPost(id: String): ResponseEntity { - val executor = oauth2CommandExecutorFactory.getCommandExecutor() userUnblockApplicationService.execute( - Unblock(id.toLong()) + Unblock(id.toLong()), principalContextHolder.getPrincipal() ) - return fetchRelationship(id, executor) + return fetchRelationship(id) } override suspend fun apiV1AccountsIdUnfollowPost(id: String): ResponseEntity { - val executor = oauth2CommandExecutorFactory.getCommandExecutor() userUnfollowApplicationService.execute( - Unfollow(id.toLong()) + Unfollow(id.toLong()), principalContextHolder.getPrincipal() ) - return fetchRelationship(id, executor) + return fetchRelationship(id) } override suspend fun apiV1AccountsIdUnmutePost(id: String): ResponseEntity { - val executor = oauth2CommandExecutorFactory.getCommandExecutor() userUnmuteApplicationService.execute( - Unmute(id.toLong()) + Unmute(id.toLong()), principalContextHolder.getPrincipal() ) - return fetchRelationship(id, executor) + return fetchRelationship(id) } override suspend fun apiV1AccountsPost(accountsCreateRequest: AccountsCreateRequest): ResponseEntity { @@ -163,9 +158,9 @@ class SpringAccountApi( } override suspend fun apiV1AccountsVerifyCredentialsGet(): ResponseEntity { - val commandExecutor = oauth2CommandExecutorFactory.getCommandExecutor() + val principal = principalContextHolder.getPrincipal() val localActor = - getUserDetailApplicationService.execute(GetUserDetail(commandExecutor.userDetailId)) + getUserDetailApplicationService.execute(GetUserDetail(principal.userDetailId.id), principal) return ResponseEntity.ok( CredentialAccount( @@ -215,19 +210,19 @@ class SpringAccountApi( } override suspend fun apiV1FollowRequestsAccountIdAuthorizePost(accountId: String): ResponseEntity { - val executor = oauth2CommandExecutorFactory.getCommandExecutor() + userAcceptFollowRequestApplicationService.execute( - AcceptFollowRequest(accountId.toLong()) + AcceptFollowRequest(accountId.toLong()), principalContextHolder.getPrincipal() ) - return fetchRelationship(accountId, executor) + return fetchRelationship(accountId) } override suspend fun apiV1FollowRequestsAccountIdRejectPost(accountId: String): ResponseEntity { - val executor = oauth2CommandExecutorFactory.getCommandExecutor() + userRejectFollowRequestApplicationService.execute( - RejectFollowRequest(accountId.toLong()) + RejectFollowRequest(accountId.toLong()), principalContextHolder.getPrincipal() ) - return fetchRelationship(accountId, executor) + return fetchRelationship(accountId) } } \ No newline at end of file diff --git a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringFilterApi.kt b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringFilterApi.kt index c5b31e19..c5748dab 100644 --- a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringFilterApi.kt +++ b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringFilterApi.kt @@ -20,7 +20,7 @@ import dev.usbharu.hideout.core.application.filter.* import dev.usbharu.hideout.core.domain.model.filter.FilterAction import dev.usbharu.hideout.core.domain.model.filter.FilterContext import dev.usbharu.hideout.core.domain.model.filter.FilterMode -import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.Oauth2CommandExecutorFactory +import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder import dev.usbharu.hideout.mastodon.application.filter.DeleteFilterV1 import dev.usbharu.hideout.mastodon.application.filter.DeleteFilterV1ApplicationService import dev.usbharu.hideout.mastodon.application.filter.GetFilterV1 @@ -36,18 +36,18 @@ import org.springframework.stereotype.Controller @Controller class SpringFilterApi( - private val oauth2CommandExecutorFactory: Oauth2CommandExecutorFactory, private val userRegisterFilterApplicationService: UserRegisterFilterApplicationService, private val getFilterV1ApplicationService: GetFilterV1ApplicationService, private val deleteFilterV1ApplicationService: DeleteFilterV1ApplicationService, private val userDeleteFilterApplicationService: UserDeleteFilterApplicationService, private val userGetFilterApplicationService: UserGetFilterApplicationService, + private val principalContextHolder: PrincipalContextHolder ) : FilterApi { override suspend fun apiV1FiltersIdDelete(id: String): ResponseEntity { return ResponseEntity.ok( deleteFilterV1ApplicationService.execute( - DeleteFilterV1(id.toLong()) + DeleteFilterV1(id.toLong()), principalContextHolder.getPrincipal() ) ) } @@ -55,7 +55,7 @@ class SpringFilterApi( override suspend fun apiV1FiltersIdGet(id: String): ResponseEntity { return ResponseEntity.ok( getFilterV1ApplicationService.execute( - GetFilterV1(id.toLong()) + GetFilterV1(id.toLong()), principalContextHolder.getPrincipal() ) ) } @@ -72,7 +72,7 @@ class SpringFilterApi( } override suspend fun apiV1FiltersPost(v1FilterPostRequest: V1FilterPostRequest): ResponseEntity { - val executor = oauth2CommandExecutorFactory.getCommandExecutor() + val filterMode = if (v1FilterPostRequest.wholeWord == true) { FilterMode.WHOLE_WORD } else { @@ -91,11 +91,11 @@ class SpringFilterApi( RegisterFilter( v1FilterPostRequest.phrase, filterContext, FilterAction.WARN, setOf(RegisterFilterKeyword(v1FilterPostRequest.phrase, filterMode)) - ) + ), principalContextHolder.getPrincipal() ) return ResponseEntity.ok( getFilterV1ApplicationService.execute( - GetFilterV1(filter.filterKeywords.first().id) + GetFilterV1(filter.filterKeywords.first().id), principalContextHolder.getPrincipal() ) ) } @@ -116,14 +116,14 @@ class SpringFilterApi( override suspend fun apiV2FiltersIdDelete(id: String): ResponseEntity { userDeleteFilterApplicationService.execute( - DeleteFilter(id.toLong()) + DeleteFilter(id.toLong()), principalContextHolder.getPrincipal() ) return ResponseEntity.ok(Unit) } override suspend fun apiV2FiltersIdGet(id: String): ResponseEntity { val filter = userGetFilterApplicationService.execute( - GetFilter(id.toLong()) + GetFilter(id.toLong()), principalContextHolder.getPrincipal() ) return ResponseEntity.ok( filter(filter) @@ -186,7 +186,7 @@ class SpringFilterApi( } override suspend fun apiV2FiltersPost(filterPostRequest: FilterPostRequest): ResponseEntity { - val executor = oauth2CommandExecutorFactory.getCommandExecutor() + val filter = userRegisterFilterApplicationService.execute( RegisterFilter( filterName = filterPostRequest.title, @@ -216,7 +216,7 @@ class SpringFilterApi( } ) }.toSet() - ) + ), principalContextHolder.getPrincipal() ) return ResponseEntity.ok(filter(filter)) } diff --git a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringMediaApi.kt b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringMediaApi.kt index 60f133f9..c22afbc7 100644 --- a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringMediaApi.kt +++ b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringMediaApi.kt @@ -19,7 +19,7 @@ package dev.usbharu.hideout.mastodon.interfaces.api import dev.usbharu.hideout.core.application.media.UploadMedia import dev.usbharu.hideout.core.application.media.UploadMediaApplicationService import dev.usbharu.hideout.core.domain.model.media.FileType.* -import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.Oauth2CommandExecutorFactory +import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder import dev.usbharu.hideout.mastodon.interfaces.api.generated.MediaApi import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.MediaAttachment import org.springframework.http.ResponseEntity @@ -30,7 +30,7 @@ import java.nio.file.Files @Controller class SpringMediaApi( private val uploadMediaApplicationService: UploadMediaApplicationService, - private val oauth2CommandExecutorFactory: Oauth2CommandExecutorFactory + private val principalContextHolder: PrincipalContextHolder ) : MediaApi { override suspend fun apiV1MediaPost( file: MultipartFile, @@ -52,7 +52,7 @@ class SpringMediaApi( file.originalFilename ?: file.name, null, description - ) + ), principalContextHolder.getPrincipal() ) return ResponseEntity.ok( diff --git a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringStatusApi.kt b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringStatusApi.kt index 09eac878..0fe04e58 100644 --- a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringStatusApi.kt +++ b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/SpringStatusApi.kt @@ -19,8 +19,7 @@ package dev.usbharu.hideout.mastodon.interfaces.api import dev.usbharu.hideout.core.application.post.RegisterLocalPost import dev.usbharu.hideout.core.application.post.RegisterLocalPostApplicationService import dev.usbharu.hideout.core.domain.model.post.Visibility -import dev.usbharu.hideout.core.infrastructure.springframework.DelegateCommandExecutorFactory -import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.Oauth2CommandExecutor +import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder import dev.usbharu.hideout.mastodon.application.status.GetStatus import dev.usbharu.hideout.mastodon.application.status.GetStatusApplicationService import dev.usbharu.hideout.mastodon.interfaces.api.generated.StatusApi @@ -32,9 +31,9 @@ import org.springframework.stereotype.Controller @Controller class SpringStatusApi( - private val delegateCommandExecutorFactory: DelegateCommandExecutorFactory, private val registerLocalPostApplicationService: RegisterLocalPostApplicationService, private val getStatusApplicationService: GetStatusApplicationService, + private val principalContextHolder: PrincipalContextHolder ) : StatusApi { override suspend fun apiV1StatusesIdEmojiReactionsEmojiDelete(id: String, emoji: String): ResponseEntity { return super.apiV1StatusesIdEmojiReactionsEmojiDelete(id, emoji) @@ -48,16 +47,15 @@ class SpringStatusApi( return ResponseEntity.ok( getStatusApplicationService.execute( - GetStatus(id) + GetStatus(id), principalContextHolder.getPrincipal() ) ) } override suspend fun apiV1StatusesPost(statusesRequest: StatusesRequest): ResponseEntity { - val executor = delegateCommandExecutorFactory.getCommandExecutor() as Oauth2CommandExecutor + val execute = registerLocalPostApplicationService.execute( RegisterLocalPost( - userDetailId = executor.userDetailId, content = statusesRequest.status.orEmpty(), overview = statusesRequest.spoilerText, visibility = when (statusesRequest.visibility) { @@ -71,11 +69,12 @@ class SpringStatusApi( replyId = statusesRequest.inReplyToId?.toLong(), sensitive = statusesRequest.sensitive == true, mediaIds = statusesRequest.mediaIds.orEmpty().map { it.toLong() } - ) + ), principalContextHolder.getPrincipal() ) - val status = getStatusApplicationService.execute(GetStatus(execute.toString())) + val status = + getStatusApplicationService.execute(GetStatus(execute.toString()), principalContextHolder.getPrincipal()) return ResponseEntity.ok( status )