From 7ec997c1d5b1292c56489deaee7bec41772e42e1 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sun, 11 Aug 2024 16:33:22 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E3=82=88=E3=81=8F=E3=81=AA=E3=81=84?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=81=A0=E3=81=A3=E3=81=9F=E3=81=AE=E3=81=A7?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=AB=E3=83=90=E3=83=83=E3=82=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actor/GetUserDetailApplicationService.kt | 15 ++++++++------- .../LocalUserAbstractApplicationServiceTest.kt | 3 ++- .../mastodon/interfaces/api/SpringAccountApi.kt | 8 +++++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/GetUserDetailApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/GetUserDetailApplicationService.kt index 0d67740d..6d990ee2 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/GetUserDetailApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/GetUserDetailApplicationService.kt @@ -17,11 +17,12 @@ package dev.usbharu.hideout.core.application.actor import dev.usbharu.hideout.core.application.exception.InternalServerException -import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService +import dev.usbharu.hideout.core.application.shared.AbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.emoji.CustomEmojiRepository -import dev.usbharu.hideout.core.domain.model.support.principal.FromApi +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.userdetails.UserDetailRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -33,10 +34,10 @@ class GetUserDetailApplicationService( private val customEmojiRepository: CustomEmojiRepository, transaction: Transaction, ) : - LocalUserAbstractApplicationService(transaction, Companion.logger) { - override suspend fun internalExecute(command: Unit, principal: FromApi): UserDetail { - val userDetail = userDetailRepository.findById(principal.userDetailId) - ?: throw IllegalArgumentException("User ${principal.userDetailId} does not exist") + AbstractApplicationService(transaction, Companion.logger) { + override suspend fun internalExecute(command: GetUserDetail, principal: Principal): UserDetail { + val userDetail = userDetailRepository.findById(UserDetailId(command.id)) + ?: throw IllegalArgumentException("User ${command.id} does not exist") val actor = actorRepository.findById(userDetail.actorId) ?: throw InternalServerException("Actor ${userDetail.actorId} not found") @@ -46,6 +47,6 @@ class GetUserDetailApplicationService( } companion object { - private val logger = LoggerFactory.getLogger(GetUserDetailApplicationService::class.java) + val logger = LoggerFactory.getLogger(GetUserDetailApplicationService::class.java) } } diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/shared/LocalUserAbstractApplicationServiceTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/shared/LocalUserAbstractApplicationServiceTest.kt index a52a29d7..581bac6a 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/shared/LocalUserAbstractApplicationServiceTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/shared/LocalUserAbstractApplicationServiceTest.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.core.application.shared +import dev.usbharu.hideout.core.application.exception.PermissionDeniedException import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous import dev.usbharu.hideout.core.domain.model.support.principal.FromApi import kotlinx.coroutines.test.runTest @@ -17,7 +18,7 @@ class LocalUserAbstractApplicationServiceTest { } } - org.junit.jupiter.api.assertThrows { + org.junit.jupiter.api.assertThrows { value.execute(Unit, Anonymous) } } 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 a860cded..15b9226b 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 @@ -16,7 +16,9 @@ package dev.usbharu.hideout.mastodon.interfaces.api +import dev.usbharu.hideout.core.application.actor.GetUserDetail import dev.usbharu.hideout.core.application.actor.GetUserDetailApplicationService +import dev.usbharu.hideout.core.application.exception.PermissionDeniedException import dev.usbharu.hideout.core.application.relationship.acceptfollowrequest.AcceptFollowRequest import dev.usbharu.hideout.core.application.relationship.acceptfollowrequest.UserAcceptFollowRequestApplicationService import dev.usbharu.hideout.core.application.relationship.block.Block @@ -159,7 +161,11 @@ class SpringAccountApi( override suspend fun apiV1AccountsVerifyCredentialsGet(): ResponseEntity { val principal = principalContextHolder.getPrincipal() val localActor = - getUserDetailApplicationService.execute(Unit, principal) + getUserDetailApplicationService.execute( + GetUserDetail( + principal.userDetailId?.id ?: throw PermissionDeniedException() + ), principal + ) return ResponseEntity.ok( CredentialAccount(