From 507c1d8932e0db7191573407680fef4da2a08708 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sun, 11 Aug 2024 00:28:32 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20principal=E3=81=AEactorId=E3=82=92?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../block/UserBlockApplicationService.kt | 7 +++--- .../UserFollowRequestApplicationService.kt | 8 +++---- .../get/GetRelationshipApplicationService.kt | 22 +++++++++---------- .../mute/UserMuteApplicationService.kt | 8 +++---- ...erRejectFollowRequestApplicationService.kt | 8 +++---- ...erRemoveFromFollowersApplicationService.kt | 8 +++---- .../unblock/UserUnblockApplicationService.kt | 8 +++---- .../UserUnfollowApplicationService.kt | 8 +++---- .../unmute/UserUnmuteApplicationService.kt | 8 +++---- 9 files changed, 35 insertions(+), 50 deletions(-) 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 91a99c4f..c78b6702 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 @@ -23,7 +23,6 @@ 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.FromApi -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import dev.usbharu.hideout.core.domain.service.relationship.RelationshipDomainService import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -33,14 +32,14 @@ class UserBlockApplicationService( private val relationshipRepository: RelationshipRepository, transaction: Transaction, private val actorRepository: ActorRepository, - private val userDetailRepository: UserDetailRepository, private val relationshipDomainService: RelationshipDomainService, ) : LocalUserAbstractApplicationService(transaction, logger) { override suspend fun internalExecute(command: Block, principal: FromApi) { - val userDetail = userDetailRepository.findById(principal.userDetailId)!! - val actor = actorRepository.findById(userDetail.actorId)!! + + val actor = actorRepository.findById(principal.actorId) + ?: throw IllegalStateException("Actor ${principal.actorId} not found") val targetId = ActorId(command.targetActorId) val relationship = relationshipRepository.findByActorIdAndTargetId(actor.id, targetId) ?: Relationship.default( 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 0c9d967d..21cabd81 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,6 +16,7 @@ package dev.usbharu.hideout.core.application.relationship.followrequest +import dev.usbharu.hideout.core.application.exception.InternalServerException 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 @@ -23,7 +24,6 @@ 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.FromApi -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -32,16 +32,14 @@ class UserFollowRequestApplicationService( private val relationshipRepository: RelationshipRepository, transaction: Transaction, private val actorRepository: ActorRepository, - private val userDetailRepository: UserDetailRepository, ) : LocalUserAbstractApplicationService( transaction, logger ) { override suspend fun internalExecute(command: FollowRequest, principal: FromApi) { - - val userDetail = userDetailRepository.findById(principal.userDetailId)!! - val actor = actorRepository.findById(userDetail.actorId)!! + val actor = actorRepository.findById(principal.actorId) + ?: throw InternalServerException("Actor ${principal.actorId} not found.") val targetId = ActorId(command.targetActorId) val relationship = relationshipRepository.findByActorIdAndTargetId(actor.id, targetId) ?: Relationship.default( 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 b832710d..2e3a7b98 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,6 +16,7 @@ package dev.usbharu.hideout.core.application.relationship.get +import dev.usbharu.hideout.core.application.exception.InternalServerException 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 @@ -24,7 +25,6 @@ import dev.usbharu.hideout.core.domain.model.actorinstancerelationship.ActorInst 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.FromApi -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -32,7 +32,6 @@ import org.springframework.stereotype.Service class GetRelationshipApplicationService( private val relationshipRepository: RelationshipRepository, private val actorRepository: ActorRepository, - private val userDetailRepository: UserDetailRepository, private val actorInstanceRelationshipRepository: ActorInstanceRelationshipRepository, transaction: Transaction, ) : @@ -41,19 +40,20 @@ class GetRelationshipApplicationService( logger ) { override suspend fun internalExecute(command: GetRelationship, principal: FromApi): Relationship { - val userDetail = userDetailRepository.findById(principal.userDetailId)!! - val actor = actorRepository.findById(userDetail.actorId)!! + val actor = actorRepository.findById(principal.actorId) + ?: throw InternalServerException("Actor ${principal.actorId} not found.") val targetId = ActorId(command.targetActorId) - val target = actorRepository.findById(targetId)!! + val target = actorRepository.findById(targetId) + ?: throw IllegalArgumentException("Actor ${command.targetActorId} not found.") val relationship = ( - relationshipRepository.findByActorIdAndTargetId(actor.id, targetId) - ?: dev.usbharu.hideout.core.domain.model.relationship.Relationship.default(actor.id, targetId) - ) + relationshipRepository.findByActorIdAndTargetId(actor.id, targetId) + ?: dev.usbharu.hideout.core.domain.model.relationship.Relationship.default(actor.id, targetId) + ) val relationship1 = ( - relationshipRepository.findByActorIdAndTargetId(targetId, actor.id) - ?: dev.usbharu.hideout.core.domain.model.relationship.Relationship.default(targetId, actor.id) - ) + relationshipRepository.findByActorIdAndTargetId(targetId, actor.id) + ?: dev.usbharu.hideout.core.domain.model.relationship.Relationship.default(targetId, actor.id) + ) val actorInstanceRelationship = actorInstanceRelationshipRepository.findByActorIdAndInstanceId(actor.id, target.instance) 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 7c611d24..bb330b61 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 @@ -16,6 +16,7 @@ package dev.usbharu.hideout.core.application.relationship.mute +import dev.usbharu.hideout.core.application.exception.InternalServerException import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction @@ -24,7 +25,6 @@ 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.FromApi -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -33,13 +33,11 @@ class UserMuteApplicationService( private val relationshipRepository: RelationshipRepository, transaction: Transaction, private val actorRepository: ActorRepository, - private val userDetailRepository: UserDetailRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { override suspend fun internalExecute(command: Mute, principal: FromApi) { - - val userDetail = userDetailRepository.findById(principal.userDetailId)!! - val actor = actorRepository.findById(userDetail.actorId)!! + val actor = actorRepository.findById(principal.actorId) + ?: throw InternalServerException("Actor ${principal.actorId} not found.") val targetId = ActorId(command.targetActorId) val relationship = relationshipRepository.findByActorIdAndTargetId(actor.id, targetId) ?: Relationship.default( 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 97adbdd0..eac8320a 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 @@ -16,6 +16,7 @@ package dev.usbharu.hideout.core.application.relationship.rejectfollowrequest +import dev.usbharu.hideout.core.application.exception.InternalServerException import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction @@ -23,7 +24,6 @@ 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.FromApi -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -32,13 +32,11 @@ class UserRejectFollowRequestApplicationService( private val relationshipRepository: RelationshipRepository, transaction: Transaction, private val actorRepository: ActorRepository, - private val userDetailRepository: UserDetailRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { override suspend fun internalExecute(command: RejectFollowRequest, principal: FromApi) { - - val userDetail = userDetailRepository.findById(principal.userDetailId)!! - val actor = actorRepository.findById(userDetail.actorId)!! + val actor = actorRepository.findById(principal.actorId) + ?: throw InternalServerException("Actor ${principal.actorId} not found.") val targetId = ActorId(command.sourceActorId) 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 d3e50e50..957b5be2 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 @@ -16,6 +16,7 @@ package dev.usbharu.hideout.core.application.relationship.removefromfollowers +import dev.usbharu.hideout.core.application.exception.InternalServerException import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction @@ -24,7 +25,6 @@ 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.FromApi -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -33,13 +33,11 @@ class UserRemoveFromFollowersApplicationService( private val relationshipRepository: RelationshipRepository, transaction: Transaction, private val actorRepository: ActorRepository, - private val userDetailRepository: UserDetailRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { override suspend fun internalExecute(command: RemoveFromFollowers, principal: FromApi) { - - val userDetail = userDetailRepository.findById(principal.userDetailId)!! - val actor = actorRepository.findById(userDetail.actorId)!! + val actor = actorRepository.findById(principal.actorId) + ?: throw InternalServerException("Actor ${principal.actorId} not found.") val targetId = ActorId(command.targetActorId) val relationship = relationshipRepository.findByActorIdAndTargetId(targetId, actor.id) ?: Relationship.default( 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 d5417799..efba1a83 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 @@ -16,6 +16,7 @@ package dev.usbharu.hideout.core.application.relationship.unblock +import dev.usbharu.hideout.core.application.exception.InternalServerException import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction @@ -24,7 +25,6 @@ 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.FromApi -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -33,13 +33,11 @@ class UserUnblockApplicationService( private val relationshipRepository: RelationshipRepository, transaction: Transaction, private val actorRepository: ActorRepository, - private val userDetailRepository: UserDetailRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { override suspend fun internalExecute(command: Unblock, principal: FromApi) { - - val userDetail = userDetailRepository.findById(principal.userDetailId)!! - val actor = actorRepository.findById(userDetail.actorId)!! + val actor = actorRepository.findById(principal.actorId) + ?: throw InternalServerException("Actor ${principal.actorId} not found.") val targetId = ActorId(command.targetActorId) val relationship = relationshipRepository.findByActorIdAndTargetId(actor.id, targetId) ?: Relationship.default( 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 a7068d00..87809a0d 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 @@ -16,6 +16,7 @@ package dev.usbharu.hideout.core.application.relationship.unfollow +import dev.usbharu.hideout.core.application.exception.InternalServerException import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction @@ -24,7 +25,6 @@ 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.FromApi -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -33,13 +33,11 @@ class UserUnfollowApplicationService( private val relationshipRepository: RelationshipRepository, transaction: Transaction, private val actorRepository: ActorRepository, - private val userDetailRepository: UserDetailRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { override suspend fun internalExecute(command: Unfollow, principal: FromApi) { - - val userDetail = userDetailRepository.findById(principal.userDetailId)!! - val actor = actorRepository.findById(userDetail.actorId)!! + val actor = actorRepository.findById(principal.actorId) + ?: throw InternalServerException("Actor ${principal.actorId} not found.") val targetId = ActorId(command.targetActorId) val relationship = relationshipRepository.findByActorIdAndTargetId(actor.id, targetId) ?: Relationship.default( 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 b90ba059..5681c066 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 @@ -16,6 +16,7 @@ package dev.usbharu.hideout.core.application.relationship.unmute +import dev.usbharu.hideout.core.application.exception.InternalServerException import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction @@ -24,7 +25,6 @@ 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.FromApi -import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -33,7 +33,6 @@ class UserUnmuteApplicationService( private val relationshipRepository: RelationshipRepository, transaction: Transaction, private val actorRepository: ActorRepository, - private val userDetailRepository: UserDetailRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { companion object { @@ -41,9 +40,8 @@ class UserUnmuteApplicationService( } override suspend fun internalExecute(command: Unmute, principal: FromApi) { - - val userDetail = userDetailRepository.findById(principal.userDetailId)!! - val actor = actorRepository.findById(userDetail.actorId)!! + val actor = actorRepository.findById(principal.actorId) + ?: throw InternalServerException("Actor ${principal.actorId} not found.") val targetId = ActorId(command.targetActorId) val relationship = relationshipRepository.findByActorIdAndTargetId(actor.id, targetId) ?: Relationship.default(