From f4d30e837e5ab229f1bf482097a871dd15f14009 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Mon, 12 Aug 2024 21:38:07 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8A=95=E7=A8=BF=E8=A9=B3=E7=B4=B0?= =?UTF-8?q?=E3=83=9A=E3=83=BC=E3=82=B8=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MigrationLocalActorApplicationService.kt | 4 +- ...StartDeleteLocalActorApplicationService.kt | 4 +- .../UserDeleteFilterApplicationService.kt | 4 +- .../filter/UserGetFilterApplicationService.kt | 4 +- .../UserRegisterFilterApplicationService.kt | 4 +- .../GetLocalInstanceApplicationService.kt | 31 +++++++ .../core/application/instance/Instance.kt | 14 +++ .../media/UploadMediaApplicationService.kt | 4 +- .../core/application/post/ActorDetail.kt | 35 +++++++ .../post/DeleteLocalPostApplicationService.kt | 4 +- .../core/application/post/GetPostDetail.kt | 3 + .../post/GetPostDetailApplicationService.kt | 91 +++++++++++++++++++ .../core/application/post/MediaDetail.kt | 28 ++++++ .../core/application/post/PostDetail.kt | 60 ++++++++++++ .../RegisterLocalPostApplicationService.kt | 4 +- .../post/UpdateLocalNoteApplicationService.kt | 4 +- ...erAcceptFollowRequestApplicationService.kt | 4 +- .../block/UserBlockApplicationService.kt | 4 +- .../UserFollowRequestApplicationService.kt | 4 +- .../get/GetRelationshipApplicationService.kt | 4 +- .../mute/UserMuteApplicationService.kt | 4 +- ...erRejectFollowRequestApplicationService.kt | 4 +- ...erRemoveFromFollowersApplicationService.kt | 4 +- .../unblock/UserUnblockApplicationService.kt | 4 +- .../UserUnfollowApplicationService.kt | 4 +- .../unmute/UserUnmuteApplicationService.kt | 4 +- .../LocalUserAbstractApplicationService.kt | 6 +- ...dTimelineRelationshipApplicationService.kt | 4 +- .../hideout/core/config/ApplicationConfig.kt | 2 +- .../hideout/core/config/SecurityConfig.kt | 1 + .../domain/model/media/MediaRepository.kt | 1 + .../hideout/core/domain/model/post/Post.kt | 2 + .../principal/{FromApi.kt => LocalUser.kt} | 2 +- .../infrastructure/exposed/PostQueryMapper.kt | 8 +- .../ExposedPostRepository.kt | 1 + .../exposedrepository/MediaRepositoryImpl.kt | 9 ++ ...SecurityFormLoginPrincipalContextHolder.kt | 35 +++++++ ...ingSecurityOauth2PrincipalContextHolder.kt | 6 +- .../interfaces/web/posts/PostsController.kt | 27 ++++++ .../src/main/resources/application.yml | 2 + .../messages/hideout-web-messages.properties | 10 ++ .../hideout-web-messages_en_US.properties | 9 ++ .../hideout-web-messages_ja_JP.properties | 10 ++ .../resources/templates/fragments-post.html | 53 +++++++++++ .../main/resources/templates/postById.html | 32 +++++++ ...grationLocalActorApplicationServiceTest.kt | 14 +-- ...tDeleteLocalActorApplicationServiceTest.kt | 8 +- .../UserDeleteFilterApplicationServiceTest.kt | 8 +- .../UserGetFilterApplicationServiceTest.kt | 8 +- .../DeleteLocalPostApplicationServiceTest.kt | 6 +- ...RegisterLocalPostApplicationServiceTest.kt | 6 +- .../UpdateLocalNoteApplicationServiceTest.kt | 12 +-- ...ceptFollowRequestApplicationServiceTest.kt | 8 +- ...LocalUserAbstractApplicationServiceTest.kt | 4 +- .../post/DefaultPostReadAccessControlTest.kt | 14 +-- .../accounts/GetAccountApplicationService.kt | 4 +- .../DeleteFilterV1ApplicationService.kt | 4 +- .../interfaces/api/SpringFilterApi.kt | 4 +- .../mastodon/interfaces/api/SpringMediaApi.kt | 4 +- .../interfaces/api/SpringStatusApi.kt | 4 +- .../StatusQueryServiceImplTest.kt | 4 +- 61 files changed, 562 insertions(+), 108 deletions(-) create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/GetLocalInstanceApplicationService.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/Instance.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/ActorDetail.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/GetPostDetail.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/GetPostDetailApplicationService.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/MediaDetail.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/PostDetail.kt rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/principal/{FromApi.kt => LocalUser.kt} (95%) create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/SpringSecurityFormLoginPrincipalContextHolder.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/posts/PostsController.kt create mode 100644 hideout-core/src/main/resources/messages/hideout-web-messages.properties create mode 100644 hideout-core/src/main/resources/messages/hideout-web-messages_en_US.properties create mode 100644 hideout-core/src/main/resources/messages/hideout-web-messages_ja_JP.properties create mode 100644 hideout-core/src/main/resources/templates/fragments-post.html create mode 100644 hideout-core/src/main/resources/templates/postById.html diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/MigrationLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/MigrationLocalActorApplicationService.kt index 9e0a01e6..a9198f67 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/MigrationLocalActorApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/MigrationLocalActorApplicationService.kt @@ -22,7 +22,7 @@ import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationS 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.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import dev.usbharu.hideout.core.domain.service.actor.local.AccountMigrationCheck.* import dev.usbharu.hideout.core.domain.service.actor.local.LocalActorMigrationCheckDomainService @@ -37,7 +37,7 @@ class MigrationLocalActorApplicationService( private val userDetailRepository: UserDetailRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: MigrationLocalActor, principal: FromApi) { + override suspend fun internalExecute(command: MigrationLocalActor, principal: LocalUser) { if (command.from != principal.actorId.id) { throw PermissionDeniedException() } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/StartDeleteLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/StartDeleteLocalActorApplicationService.kt index 9fd8669b..288fdf22 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/StartDeleteLocalActorApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/StartDeleteLocalActorApplicationService.kt @@ -21,7 +21,7 @@ import dev.usbharu.hideout.core.application.exception.PermissionDeniedException 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.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -30,7 +30,7 @@ class StartDeleteLocalActorApplicationService( transaction: Transaction, private val actorRepository: ActorRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: DeleteLocalActor, principal: FromApi) { + override suspend fun internalExecute(command: DeleteLocalActor, principal: LocalUser) { if (command.actorId != principal.actorId) { throw PermissionDeniedException() } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserDeleteFilterApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserDeleteFilterApplicationService.kt index 9333ec83..19b07618 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserDeleteFilterApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserDeleteFilterApplicationService.kt @@ -21,7 +21,7 @@ import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationS import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.filter.FilterId import dev.usbharu.hideout.core.domain.model.filter.FilterRepository -import dev.usbharu.hideout.core.domain.model.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -31,7 +31,7 @@ class UserDeleteFilterApplicationService(private val filterRepository: FilterRep transaction, logger ) { - override suspend fun internalExecute(command: DeleteFilter, principal: FromApi) { + override suspend fun internalExecute(command: DeleteFilter, principal: LocalUser) { val filter = filterRepository.findByFilterId(FilterId(command.filterId)) ?: throw IllegalArgumentException("not found") if (filter.userDetailId != principal.userDetailId) { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserGetFilterApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserGetFilterApplicationService.kt index cecb5a5d..1038fe2a 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserGetFilterApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserGetFilterApplicationService.kt @@ -21,7 +21,7 @@ import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationS import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.filter.FilterId import dev.usbharu.hideout.core.domain.model.filter.FilterRepository -import dev.usbharu.hideout.core.domain.model.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -31,7 +31,7 @@ class UserGetFilterApplicationService(private val filterRepository: FilterReposi transaction, logger ) { - override suspend fun internalExecute(command: GetFilter, principal: FromApi): Filter { + override suspend fun internalExecute(command: GetFilter, principal: LocalUser): Filter { val filter = filterRepository.findByFilterId(FilterId(command.filterId)) ?: throw IllegalArgumentException("Not Found") if (filter.userDetailId != principal.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 bf12c041..8f4a45ec 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 @@ -20,7 +20,7 @@ import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationS 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.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import dev.usbharu.hideout.core.domain.shared.id.IdGenerateService import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -36,7 +36,7 @@ class UserRegisterFilterApplicationService( logger ) { - override suspend fun internalExecute(command: RegisterFilter, principal: FromApi): Filter { + override suspend fun internalExecute(command: RegisterFilter, principal: LocalUser): Filter { val filter = dev.usbharu.hideout.core.domain.model.filter.Filter.create( id = FilterId(idGenerateService.generateId()), diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/GetLocalInstanceApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/GetLocalInstanceApplicationService.kt new file mode 100644 index 00000000..19c32b90 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/GetLocalInstanceApplicationService.kt @@ -0,0 +1,31 @@ +package dev.usbharu.hideout.core.application.instance + +import dev.usbharu.hideout.core.application.exception.InternalServerException +import dev.usbharu.hideout.core.application.shared.AbstractApplicationService +import dev.usbharu.hideout.core.application.shared.Transaction +import dev.usbharu.hideout.core.config.ApplicationConfig +import dev.usbharu.hideout.core.domain.model.instance.InstanceRepository +import dev.usbharu.hideout.core.domain.model.support.principal.Principal +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service + +@Service +class GetLocalInstanceApplicationService( + private val applicationConfig: ApplicationConfig, + private val instanceRepository: InstanceRepository, + transaction: Transaction +) : + AbstractApplicationService( + transaction, logger + ) { + override suspend fun internalExecute(command: Unit, principal: Principal): Instance { + val instance = (instanceRepository.findByUrl(applicationConfig.url.toURI()) + ?: throw InternalServerException("Local instance not found.")) + + return Instance.of(instance) + } + + companion object { + private val logger = LoggerFactory.getLogger(GetLocalInstanceApplicationService::class.java) + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/Instance.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/Instance.kt new file mode 100644 index 00000000..80adde56 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/Instance.kt @@ -0,0 +1,14 @@ +package dev.usbharu.hideout.core.application.instance + +import dev.usbharu.hideout.core.domain.model.instance.Instance +import java.net.URI + +data class Instance(val id: Long, val name: String, val url: URI, val description: String) { + companion object { + fun of(instance: Instance): dev.usbharu.hideout.core.application.instance.Instance { + return Instance( + instance.id.instanceId, instance.name.name, instance.url, instance.description.description + ) + } + } +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/media/UploadMediaApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/media/UploadMediaApplicationService.kt index 4773f60f..c3b3379a 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/media/UploadMediaApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/media/UploadMediaApplicationService.kt @@ -19,7 +19,7 @@ package dev.usbharu.hideout.core.application.media import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.media.* -import dev.usbharu.hideout.core.domain.model.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import dev.usbharu.hideout.core.domain.shared.id.IdGenerateService import dev.usbharu.hideout.core.external.media.MediaProcessor import dev.usbharu.hideout.core.external.mediastore.MediaStore @@ -39,7 +39,7 @@ class UploadMediaApplicationService( transaction, logger ) { - override suspend fun internalExecute(command: UploadMedia, principal: FromApi): Media { + override suspend fun internalExecute(command: UploadMedia, principal: LocalUser): Media { val process = mediaProcessor.process(command.path, command.name, null) val id = idGenerateService.generateId() val thumbnailUri = if (process.thumbnailPath != null) { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/ActorDetail.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/ActorDetail.kt new file mode 100644 index 00000000..5513227f --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/ActorDetail.kt @@ -0,0 +1,35 @@ +package dev.usbharu.hideout.core.application.post + + +import dev.usbharu.hideout.core.domain.model.actor.Actor +import dev.usbharu.hideout.core.domain.model.instance.Instance +import dev.usbharu.hideout.core.domain.model.media.Media +import java.net.URI + +data class ActorDetail( + val actorId: Long, + val instanceId: Long, + val instanceName: String, + val name: String, + val domain: String, + val screenName: String, + val url: URI, + val locked: Boolean, + val icon: URI?, +) { + companion object { + fun of(actor: Actor, instance: Instance, iconMedia: Media?): ActorDetail { + return ActorDetail( + actor.id.id, + actor.instance.instanceId, + instance.name.name, + actor.name.name, + actor.domain.domain, + actor.screenName.screenName, + actor.url, + actor.locked, + iconMedia?.url + ) + } + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/DeleteLocalPostApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/DeleteLocalPostApplicationService.kt index 511f9629..00c41804 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/DeleteLocalPostApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/DeleteLocalPostApplicationService.kt @@ -22,7 +22,7 @@ import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.post.PostId import dev.usbharu.hideout.core.domain.model.post.PostRepository -import dev.usbharu.hideout.core.domain.model.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -32,7 +32,7 @@ class DeleteLocalPostApplicationService( private val actorRepository: ActorRepository, transaction: Transaction, ) : LocalUserAbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: DeleteLocalPost, principal: FromApi) { + override suspend fun internalExecute(command: DeleteLocalPost, principal: LocalUser) { val findById = postRepository.findById(PostId(command.postId))!! if (findById.actorId != principal.actorId) { throw PermissionDeniedException() diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/GetPostDetail.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/GetPostDetail.kt new file mode 100644 index 00000000..796e167b --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/GetPostDetail.kt @@ -0,0 +1,3 @@ +package dev.usbharu.hideout.core.application.post + +data class GetPostDetail(val postId: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/GetPostDetailApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/GetPostDetailApplicationService.kt new file mode 100644 index 00000000..55fcf60e --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/GetPostDetailApplicationService.kt @@ -0,0 +1,91 @@ +package dev.usbharu.hideout.core.application.post + +import dev.usbharu.hideout.core.application.exception.InternalServerException +import dev.usbharu.hideout.core.application.exception.PermissionDeniedException +import dev.usbharu.hideout.core.application.shared.AbstractApplicationService +import dev.usbharu.hideout.core.application.shared.Transaction +import dev.usbharu.hideout.core.domain.model.actor.Actor +import dev.usbharu.hideout.core.domain.model.actor.ActorRepository +import dev.usbharu.hideout.core.domain.model.instance.Instance +import dev.usbharu.hideout.core.domain.model.instance.InstanceRepository +import dev.usbharu.hideout.core.domain.model.media.Media +import dev.usbharu.hideout.core.domain.model.media.MediaRepository +import dev.usbharu.hideout.core.domain.model.post.PostId +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.service.post.IPostReadAccessControl +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service + +@Service +class GetPostDetailApplicationService( + transaction: Transaction, + private val postRepository: PostRepository, + private val actorRepository: ActorRepository, + private val instanceRepository: InstanceRepository, + private val mediaRepository: MediaRepository, + private val iPostReadAccessControl: IPostReadAccessControl +) : AbstractApplicationService( + transaction, logger +) { + override suspend fun internalExecute(command: GetPostDetail, principal: Principal): PostDetail { + val post = postRepository.findById(PostId(command.postId)) + ?: throw IllegalArgumentException("Post ${command.postId} not found.") + if (iPostReadAccessControl.isAllow(post, principal).not()) { + throw PermissionDeniedException() + } + val actor = + actorRepository.findById(post.actorId) ?: throw InternalServerException("Actor ${post.actorId} not found.") + val instance = instanceRepository.findById(post.instanceId) + ?: throw InternalServerException("Instance ${post.instanceId} not found.") + + val iconMedia = actor.icon?.let { mediaRepository.findById(it) } + + val mediaList = mediaRepository.findByIds(post.mediaIds) + + return PostDetail.of( + post, + actor, + instance, + iconMedia, + mediaList, + post.replyId?.let { fetchChild(it, actor, instance, iconMedia, principal) }, + post.repostId?.let { fetchChild(it, actor, instance, iconMedia, principal) }, + post.moveTo?.let { fetchChild(it, actor, instance, iconMedia, principal) }, + ) + } + + private suspend fun fetchChild( + postId: PostId, + actor: Actor, + instance: Instance, + iconMedia: Media?, + principal: Principal + ): PostDetail? { + val post = postRepository.findById(postId) ?: return null + + if (iPostReadAccessControl.isAllow(post, principal).not()) { + throw PermissionDeniedException() + } + + val (first, second: Instance, third) = if (actor.id != post.actorId) { + Triple( + actorRepository.findById(post.actorId) ?: return null, + instanceRepository.findById(actor.instance) ?: return null, + actor.icon?.let { mediaRepository.findById(it) } + ) + } else { + Triple(actor, instance, iconMedia) + } + + val mediaList = mediaRepository.findByIds(post.mediaIds) + return PostDetail.of( + post, first, second, third, mediaList + ) + + } + + companion object { + private val logger = LoggerFactory.getLogger(GetPostDetailApplicationService::class.java) + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/MediaDetail.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/MediaDetail.kt new file mode 100644 index 00000000..3ce780dc --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/MediaDetail.kt @@ -0,0 +1,28 @@ +package dev.usbharu.hideout.core.application.post + +import dev.usbharu.hideout.core.domain.model.media.Media +import java.net.URI + +data class MediaDetail( + val mediaId: Long, + val type: String, + val url: URI, + val thumbnailUrl: URI?, + val sensitive: Boolean, + val description: String, + val blurhash: String +) { + companion object { + fun of(media: Media): MediaDetail { + return MediaDetail( + media.id.id, + media.type.name, + media.url, + media.thumbnailUrl, + false, + media.description?.description.orEmpty(), + media.blurHash?.hash.orEmpty() + ) + } + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/PostDetail.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/PostDetail.kt new file mode 100644 index 00000000..f3be33d8 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/PostDetail.kt @@ -0,0 +1,60 @@ +package dev.usbharu.hideout.core.application.post + +import dev.usbharu.hideout.core.domain.model.actor.Actor +import dev.usbharu.hideout.core.domain.model.instance.Instance +import dev.usbharu.hideout.core.domain.model.media.Media +import dev.usbharu.hideout.core.domain.model.post.Post +import dev.usbharu.hideout.core.domain.model.post.Visibility +import java.net.URI +import java.time.Instant + +data class PostDetail( + val id: Long, + val actor: ActorDetail, + val overview: String?, + val text: String, + val content: String, + val createdAt: Instant, + val visibility: Visibility, + val pureRepost: Boolean, + val url: URI, + val apId: URI, + val repost: PostDetail?, + val reply: PostDetail?, + val sensitive: Boolean, + val deleted: Boolean, + val mediaDetailList: List, + val moveTo: PostDetail? +) { + companion object { + fun of( + post: Post, + actor: Actor, + instance: Instance, + iconMedia: Media?, + mediaList: List, + reply: PostDetail? = null, + repost: PostDetail? = null, + moveTo: PostDetail? = null, + ): PostDetail { + return PostDetail( + id = post.id.id, + actor = ActorDetail.of(actor, instance, iconMedia), + overview = post.overview?.overview, + text = post.text, + content = post.content.content, + createdAt = post.createdAt, + visibility = post.visibility, + pureRepost = post.isPureRepost, + url = post.url, + apId = post.apId, + repost = repost, + reply = reply, + sensitive = post.sensitive, + deleted = false, + mediaDetailList = mediaList.map { MediaDetail.of(it) }, + moveTo = moveTo + ) + } + } +} 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 0cc237da..ad950c66 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 @@ -24,7 +24,7 @@ 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.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import dev.usbharu.hideout.core.infrastructure.factory.PostFactoryImpl import org.slf4j.Logger import org.slf4j.LoggerFactory @@ -38,7 +38,7 @@ class RegisterLocalPostApplicationService( transaction: Transaction, ) : LocalUserAbstractApplicationService(transaction, Companion.logger) { - override suspend fun internalExecute(command: RegisterLocalPost, principal: FromApi): Long { + override suspend fun internalExecute(command: RegisterLocalPost, principal: LocalUser): Long { val actorId = principal.actorId val actor = actorRepository.findById(actorId) ?: throw InternalServerException("Actor $actorId not found.") diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNoteApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNoteApplicationService.kt index 17bafb70..9c9b4003 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNoteApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNoteApplicationService.kt @@ -25,7 +25,7 @@ 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.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository import dev.usbharu.hideout.core.infrastructure.factory.PostContentFactoryImpl import org.slf4j.LoggerFactory @@ -40,7 +40,7 @@ class UpdateLocalNoteApplicationService( private val actorRepository: ActorRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: UpdateLocalNote, principal: FromApi) { + override suspend fun internalExecute(command: UpdateLocalNote, principal: LocalUser) { val post = postRepository.findById(PostId(command.postId)) ?: throw IllegalArgumentException("Post ${command.postId} not found.") if (post.actorId != principal.actorId) { 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 1f17a0df..5a9197ee 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 @@ -23,7 +23,7 @@ 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.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -34,7 +34,7 @@ class UserAcceptFollowRequestApplicationService( private val actorRepository: ActorRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: AcceptFollowRequest, principal: FromApi) { + override suspend fun internalExecute(command: AcceptFollowRequest, principal: LocalUser) { val actor = actorRepository.findById(principal.actorId) ?: throw InternalServerException("Actor ${principal.actorId} not found") 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 c78b6702..62924469 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 @@ -22,7 +22,7 @@ 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.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import dev.usbharu.hideout.core.domain.service.relationship.RelationshipDomainService import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -35,7 +35,7 @@ class UserBlockApplicationService( private val relationshipDomainService: RelationshipDomainService, ) : LocalUserAbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: Block, principal: FromApi) { + override suspend fun internalExecute(command: Block, principal: LocalUser) { val actor = actorRepository.findById(principal.actorId) 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 21cabd81..e277f786 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 @@ -23,7 +23,7 @@ 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.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -37,7 +37,7 @@ class UserFollowRequestApplicationService( logger ) { - override suspend fun internalExecute(command: FollowRequest, principal: FromApi) { + override suspend fun internalExecute(command: FollowRequest, principal: LocalUser) { val actor = actorRepository.findById(principal.actorId) ?: throw InternalServerException("Actor ${principal.actorId} not found.") 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 2e3a7b98..e863befd 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 @@ -24,7 +24,7 @@ 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.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -39,7 +39,7 @@ class GetRelationshipApplicationService( transaction, logger ) { - override suspend fun internalExecute(command: GetRelationship, principal: FromApi): Relationship { + override suspend fun internalExecute(command: GetRelationship, principal: LocalUser): Relationship { val actor = actorRepository.findById(principal.actorId) ?: throw InternalServerException("Actor ${principal.actorId} not found.") val targetId = ActorId(command.targetActorId) 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 bb330b61..537e4f1d 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 @@ -24,7 +24,7 @@ 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.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -35,7 +35,7 @@ class UserMuteApplicationService( private val actorRepository: ActorRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: Mute, principal: FromApi) { + override suspend fun internalExecute(command: Mute, principal: LocalUser) { val actor = actorRepository.findById(principal.actorId) ?: throw InternalServerException("Actor ${principal.actorId} not found.") 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 eac8320a..2301fd2f 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 @@ -23,7 +23,7 @@ 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.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -34,7 +34,7 @@ class UserRejectFollowRequestApplicationService( private val actorRepository: ActorRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: RejectFollowRequest, principal: FromApi) { + override suspend fun internalExecute(command: RejectFollowRequest, principal: LocalUser) { val actor = actorRepository.findById(principal.actorId) ?: throw InternalServerException("Actor ${principal.actorId} not found.") 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 957b5be2..adce9c61 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 @@ -24,7 +24,7 @@ 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.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -35,7 +35,7 @@ class UserRemoveFromFollowersApplicationService( private val actorRepository: ActorRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: RemoveFromFollowers, principal: FromApi) { + override suspend fun internalExecute(command: RemoveFromFollowers, principal: LocalUser) { val actor = actorRepository.findById(principal.actorId) ?: throw InternalServerException("Actor ${principal.actorId} not found.") 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 efba1a83..1e0e8d38 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 @@ -24,7 +24,7 @@ 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.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -35,7 +35,7 @@ class UserUnblockApplicationService( private val actorRepository: ActorRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: Unblock, principal: FromApi) { + override suspend fun internalExecute(command: Unblock, principal: LocalUser) { val actor = actorRepository.findById(principal.actorId) ?: throw InternalServerException("Actor ${principal.actorId} not found.") 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 87809a0d..e747fda8 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 @@ -24,7 +24,7 @@ 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.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -35,7 +35,7 @@ class UserUnfollowApplicationService( private val actorRepository: ActorRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { - override suspend fun internalExecute(command: Unfollow, principal: FromApi) { + override suspend fun internalExecute(command: Unfollow, principal: LocalUser) { val actor = actorRepository.findById(principal.actorId) ?: throw InternalServerException("Actor ${principal.actorId} not found.") 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 5681c066..7c41fcc6 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 @@ -24,7 +24,7 @@ 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.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -39,7 +39,7 @@ class UserUnmuteApplicationService( private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) } - override suspend fun internalExecute(command: Unmute, principal: FromApi) { + override suspend fun internalExecute(command: Unmute, principal: LocalUser) { val actor = actorRepository.findById(principal.actorId) ?: throw InternalServerException("Actor ${principal.actorId} not found.") diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/shared/LocalUserAbstractApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/shared/LocalUserAbstractApplicationService.kt index 1bcd4b26..8c4eb0bc 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/shared/LocalUserAbstractApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/shared/LocalUserAbstractApplicationService.kt @@ -1,18 +1,18 @@ package dev.usbharu.hideout.core.application.shared import dev.usbharu.hideout.core.application.exception.PermissionDeniedException -import dev.usbharu.hideout.core.domain.model.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import dev.usbharu.hideout.core.domain.model.support.principal.Principal import org.slf4j.Logger abstract class LocalUserAbstractApplicationService(transaction: Transaction, logger: Logger) : AbstractApplicationService(transaction, logger) { override suspend fun internalExecute(command: T, principal: Principal): R { - if (principal !is FromApi) { + if (principal !is LocalUser) { throw PermissionDeniedException() } return internalExecute(command, principal) } - protected abstract suspend fun internalExecute(command: T, principal: FromApi): R + protected abstract suspend fun internalExecute(command: T, principal: LocalUser): R } \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/timeline/UserAddTimelineRelationshipApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/timeline/UserAddTimelineRelationshipApplicationService.kt index 712ab270..b0ea5580 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/timeline/UserAddTimelineRelationshipApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/timeline/UserAddTimelineRelationshipApplicationService.kt @@ -2,7 +2,7 @@ package dev.usbharu.hideout.core.application.timeline import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction -import dev.usbharu.hideout.core.domain.model.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationshipRepository import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -15,7 +15,7 @@ class UserAddTimelineRelationshipApplicationService( LocalUserAbstractApplicationService( transaction, logger ) { - override suspend fun internalExecute(command: AddTimelineRelationship, principal: FromApi) { + override suspend fun internalExecute(command: AddTimelineRelationship, principal: LocalUser) { timelineRelationshipRepository.save(command.timelineRelationship) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/ApplicationConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/ApplicationConfig.kt index 5cb5941c..bbc461ec 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/ApplicationConfig.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/ApplicationConfig.kt @@ -24,4 +24,4 @@ data class ApplicationConfig( val url: URL, val private: Boolean = true, val keySize: Int = 2048, -) +) \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt index 17320fb8..59069df4 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt @@ -81,6 +81,7 @@ class SecurityConfig { authorize(GET, "/auth/sign_up", hasRole("ANONYMOUS")) authorize(POST, "/auth/sign_up", permitAll) + authorize(GET, "/users/{username}/posts/{postId}", permitAll) authorize(anyRequest, authenticated) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaRepository.kt index cc5321b8..f762af7b 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/MediaRepository.kt @@ -19,5 +19,6 @@ package dev.usbharu.hideout.core.domain.model.media interface MediaRepository { suspend fun save(media: Media): Media suspend fun findById(id: MediaId): Media? + suspend fun findByIds(ids: List): List suspend fun delete(media: Media) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt index d7d3f8e3..9a578c79 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt @@ -83,6 +83,8 @@ class Post( } } + val isPureRepost = content == PostContent.empty && overview == null && replyId == null && repostId != null + var content = content get() { if (hide) { 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/LocalUser.kt similarity index 95% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/principal/FromApi.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/principal/LocalUser.kt index 2ce5f785..afe7334e 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/LocalUser.kt @@ -4,7 +4,7 @@ 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( +class LocalUser( actorId: ActorId, override val userDetailId: UserDetailId, override val acct: Acct diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostQueryMapper.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostQueryMapper.kt index f3cf3407..653533ed 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostQueryMapper.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostQueryMapper.kt @@ -38,14 +38,14 @@ class PostQueryMapper(private val postResultRowMapper: ResultRowMapper) : it .first() .let(postResultRowMapper::map) - .apply { - buildPost(it) + .run { + buildPost(this, it) } } } - private fun Post.buildPost(it: List) { - reconstructWith( + private fun buildPost(post: Post, it: List): Post { + return post.reconstructWith( mediaIds = it.mapNotNull { resultRow: ResultRow -> resultRow .getOrNull(PostsMedia.mediaId) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt index e0bb4f46..e3598182 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt @@ -157,6 +157,7 @@ class ExposedPostRepository( override suspend fun findById(id: PostId): Post? = query { Posts + .leftJoin(PostsMedia) .selectAll() .where { Posts.id eq id.id diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt index b9ab43de..a6ac6b26 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt @@ -39,6 +39,15 @@ class MediaRepositoryImpl : MediaRepository, AbstractRepository() { } } + override suspend fun findByIds(ids: List): List { + return query { + return@query Media + .selectAll() + .where { Media.id inList ids.map { it.id } } + .map { it.toMedia() } + } + } + override suspend fun delete(media: dev.usbharu.hideout.core.domain.model.media.Media): Unit = query { Media.deleteWhere { id eq id diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/SpringSecurityFormLoginPrincipalContextHolder.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/SpringSecurityFormLoginPrincipalContextHolder.kt new file mode 100644 index 00000000..32ca47c4 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/SpringSecurityFormLoginPrincipalContextHolder.kt @@ -0,0 +1,35 @@ +package dev.usbharu.hideout.core.infrastructure.springframework + +import dev.usbharu.hideout.core.application.shared.Transaction +import dev.usbharu.hideout.core.domain.model.support.acct.Acct +import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser +import dev.usbharu.hideout.core.domain.model.support.principal.Principal +import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder +import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId +import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.HideoutUserDetails +import dev.usbharu.hideout.core.query.principal.PrincipalQueryService +import org.springframework.security.core.context.SecurityContextHolder +import org.springframework.stereotype.Component + +@Component("formLogin") +class SpringSecurityFormLoginPrincipalContextHolder( + private val transaction: Transaction, + private val principalQueryService: PrincipalQueryService +) : PrincipalContextHolder { + override suspend fun getPrincipal(): Principal { + val hideoutUserDetails = + SecurityContextHolder.getContext().authentication?.principal as? HideoutUserDetails ?: return Anonymous + + return transaction.transaction { + + val userDetail = principalQueryService.findByUserDetailId(UserDetailId(hideoutUserDetails.userDetailsId)) + LocalUser( + 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/infrastructure/springframework/oauth2/SpringSecurityOauth2PrincipalContextHolder.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/SpringSecurityOauth2PrincipalContextHolder.kt index ebf56530..95984983 100644 --- 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 @@ -3,7 +3,7 @@ package dev.usbharu.hideout.core.infrastructure.springframework.oauth2 import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.support.acct.Acct import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous -import dev.usbharu.hideout.core.domain.model.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import dev.usbharu.hideout.core.domain.model.support.principal.Principal import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId @@ -12,7 +12,7 @@ import org.springframework.security.core.context.SecurityContextHolder import org.springframework.security.oauth2.jwt.Jwt import org.springframework.stereotype.Component -@Component +@Component("oauth2") class SpringSecurityOauth2PrincipalContextHolder( private val principalQueryService: PrincipalQueryService, private val transaction: Transaction @@ -26,7 +26,7 @@ class SpringSecurityOauth2PrincipalContextHolder( val id = principal.getClaim("uid").toLong() val userDetail = principalQueryService.findByUserDetailId(UserDetailId(id)) - return@transaction FromApi( + return@transaction LocalUser( userDetail.actorId, userDetail.userDetailId, Acct(userDetail.username, userDetail.host) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/posts/PostsController.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/posts/PostsController.kt new file mode 100644 index 00000000..e7092484 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/posts/PostsController.kt @@ -0,0 +1,27 @@ +package dev.usbharu.hideout.core.interfaces.web.posts + +import dev.usbharu.hideout.core.application.instance.GetLocalInstanceApplicationService +import dev.usbharu.hideout.core.application.post.GetPostDetail +import dev.usbharu.hideout.core.application.post.GetPostDetailApplicationService +import dev.usbharu.hideout.core.infrastructure.springframework.SpringSecurityFormLoginPrincipalContextHolder +import org.springframework.stereotype.Controller +import org.springframework.ui.Model +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable + +@Controller +class PostsController( + private val getPostDetailApplicationService: GetPostDetailApplicationService, + private val springSecurityFormLoginPrincipalContextHolder: SpringSecurityFormLoginPrincipalContextHolder, + private val getLocalInstanceApplicationService: GetLocalInstanceApplicationService +) { + @GetMapping("/users/{name}/posts/{id}") + suspend fun postById(@PathVariable id: Long, model: Model): String { + val principal = springSecurityFormLoginPrincipalContextHolder.getPrincipal() + val post = getPostDetailApplicationService.execute(GetPostDetail(id), principal) + val instance = getLocalInstanceApplicationService.execute(Unit, principal) + model.addAttribute("post", post) + model.addAttribute("instance", instance) + return "postById" + } +} \ No newline at end of file diff --git a/hideout-core/src/main/resources/application.yml b/hideout-core/src/main/resources/application.yml index 95ad5a20..c4bcecdd 100644 --- a/hideout-core/src/main/resources/application.yml +++ b/hideout-core/src/main/resources/application.yml @@ -47,6 +47,8 @@ spring: threads: virtual: enabled: true + messages: + basename: messages.hideout-web-messages server: tomcat: basedir: tomcat diff --git a/hideout-core/src/main/resources/messages/hideout-web-messages.properties b/hideout-core/src/main/resources/messages/hideout-web-messages.properties new file mode 100644 index 00000000..4151646d --- /dev/null +++ b/hideout-core/src/main/resources/messages/hideout-web-messages.properties @@ -0,0 +1,10 @@ +common.audio=\u30AA\u30FC\u30C7\u30A3\u30AA +common.audio-download-link=\u97F3\u58F0\u30D5\u30A1\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9 +common.media-original-link=\u30AA\u30EA\u30B8\u30CA\u30EB +common.thumbnail=\u30B5\u30E0\u30CD\u30A4\u30EB +common.unknwon-file-type=\u4E0D\u660E\u306A\u30D5\u30A1\u30A4\u30EB\u5F62\u5F0F +common.video=\u52D5\u753B +common.video-download-link=\u52D5\u753B\u30D5\u30A1\u30A4\u30EB\u307E\u305F\u306F\u30B5\u30E0\u30CD\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9 +post-by-id.title={0} \u3055\u3093\u306E\u6295\u7A3F - {1} +post.repost=\u30EA\u30DD\u30B9\u30C8 +post.repost-by={0}\u304C\u30EA\u30DD\u30B9\u30C8 \ No newline at end of file diff --git a/hideout-core/src/main/resources/messages/hideout-web-messages_en_US.properties b/hideout-core/src/main/resources/messages/hideout-web-messages_en_US.properties new file mode 100644 index 00000000..f56efdb9 --- /dev/null +++ b/hideout-core/src/main/resources/messages/hideout-web-messages_en_US.properties @@ -0,0 +1,9 @@ +common.audio=Audio +common.audio-download-link=Download the audio. +common.media-original-link=original +common.thumbnail=thumbnail +common.unknwon-file-type=Unknown filetype +common.video=Video +common.video-download-link=Download the Video or thumbnail. +post.repost=Repost +post.repost-by=Repost by {0} \ No newline at end of file diff --git a/hideout-core/src/main/resources/messages/hideout-web-messages_ja_JP.properties b/hideout-core/src/main/resources/messages/hideout-web-messages_ja_JP.properties new file mode 100644 index 00000000..4151646d --- /dev/null +++ b/hideout-core/src/main/resources/messages/hideout-web-messages_ja_JP.properties @@ -0,0 +1,10 @@ +common.audio=\u30AA\u30FC\u30C7\u30A3\u30AA +common.audio-download-link=\u97F3\u58F0\u30D5\u30A1\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9 +common.media-original-link=\u30AA\u30EA\u30B8\u30CA\u30EB +common.thumbnail=\u30B5\u30E0\u30CD\u30A4\u30EB +common.unknwon-file-type=\u4E0D\u660E\u306A\u30D5\u30A1\u30A4\u30EB\u5F62\u5F0F +common.video=\u52D5\u753B +common.video-download-link=\u52D5\u753B\u30D5\u30A1\u30A4\u30EB\u307E\u305F\u306F\u30B5\u30E0\u30CD\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9 +post-by-id.title={0} \u3055\u3093\u306E\u6295\u7A3F - {1} +post.repost=\u30EA\u30DD\u30B9\u30C8 +post.repost-by={0}\u304C\u30EA\u30DD\u30B9\u30C8 \ No newline at end of file diff --git a/hideout-core/src/main/resources/templates/fragments-post.html b/hideout-core/src/main/resources/templates/fragments-post.html new file mode 100644 index 00000000..5b9533b6 --- /dev/null +++ b/hideout-core/src/main/resources/templates/fragments-post.html @@ -0,0 +1,53 @@ + + + + + Title + + + + +
+ + +
+

+
+ +
+ +
+
+ + + + + + + + +

Unknown filetype

+
+
+ +
+
+ +
+ + + + +
+ + + + \ No newline at end of file diff --git a/hideout-core/src/main/resources/templates/postById.html b/hideout-core/src/main/resources/templates/postById.html new file mode 100644 index 00000000..99c7126d --- /dev/null +++ b/hideout-core/src/main/resources/templates/postById.html @@ -0,0 +1,32 @@ + + + + + Posts - hideout + + + + + \ No newline at end of file diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/actor/MigrationLocalActorApplicationServiceTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/actor/MigrationLocalActorApplicationServiceTest.kt index 3148980d..0dad132b 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/actor/MigrationLocalActorApplicationServiceTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/actor/MigrationLocalActorApplicationServiceTest.kt @@ -7,7 +7,7 @@ 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.actor.TestActorFactory 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.LocalUser import dev.usbharu.hideout.core.domain.model.userdetails.UserDetail import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailHashedPassword import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId @@ -48,7 +48,7 @@ class MigrationLocalActorApplicationServiceTest { assertThrows { service.execute( MigrationLocalActor(1, 2), - FromApi(ActorId(3), UserDetailId(3), Acct("test", "example.com")) + LocalUser(ActorId(3), UserDetailId(3), Acct("test", "example.com")) ) } } @@ -64,7 +64,7 @@ class MigrationLocalActorApplicationServiceTest { assertThrows { service.execute( MigrationLocalActor(1, 2), - FromApi(ActorId(1), UserDetailId(1), Acct("test", "example.com")) + LocalUser(ActorId(1), UserDetailId(1), Acct("test", "example.com")) ) } } @@ -81,7 +81,7 @@ class MigrationLocalActorApplicationServiceTest { assertThrows { service.execute( MigrationLocalActor(1, 2), - FromApi(ActorId(1), UserDetailId(1), Acct("test", "example.com")) + LocalUser(ActorId(1), UserDetailId(1), Acct("test", "example.com")) ) } } @@ -91,7 +91,7 @@ class MigrationLocalActorApplicationServiceTest { assertThrows { service.execute( MigrationLocalActor(1, 2), - FromApi(ActorId(1), UserDetailId(1), Acct("test", "example.com")) + LocalUser(ActorId(1), UserDetailId(1), Acct("test", "example.com")) ) } } @@ -119,7 +119,7 @@ class MigrationLocalActorApplicationServiceTest { service.execute( MigrationLocalActor(1, 2), - FromApi(ActorId(1), UserDetailId(1), Acct("test", "example.com")) + LocalUser(ActorId(1), UserDetailId(1), Acct("test", "example.com")) ) argumentCaptor { @@ -161,7 +161,7 @@ class MigrationLocalActorApplicationServiceTest { assertThrows { service.execute( MigrationLocalActor(1, 2), - FromApi(ActorId(1), UserDetailId(1), Acct("test", "example.com")) + LocalUser(ActorId(1), UserDetailId(1), Acct("test", "example.com")) ) } } diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/actor/StartDeleteLocalActorApplicationServiceTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/actor/StartDeleteLocalActorApplicationServiceTest.kt index f99645bf..27fac11f 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/actor/StartDeleteLocalActorApplicationServiceTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/actor/StartDeleteLocalActorApplicationServiceTest.kt @@ -6,7 +6,7 @@ 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.actor.TestActorFactory 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.LocalUser import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Test @@ -38,7 +38,7 @@ class StartDeleteLocalActorApplicationServiceTest { service.execute( DeleteLocalActor(ActorId(1)), - FromApi(ActorId(1), UserDetailId((1)), Acct("test", "example.com")) + LocalUser(ActorId(1), UserDetailId((1)), Acct("test", "example.com")) ) } @@ -47,7 +47,7 @@ class StartDeleteLocalActorApplicationServiceTest { assertThrows { service.execute( DeleteLocalActor(ActorId(2)), - FromApi(ActorId(1), UserDetailId((1)), Acct("test", "example.com")) + LocalUser(ActorId(1), UserDetailId((1)), Acct("test", "example.com")) ) } } @@ -57,7 +57,7 @@ class StartDeleteLocalActorApplicationServiceTest { assertThrows { service.execute( DeleteLocalActor(ActorId(1)), - FromApi(ActorId(1), UserDetailId((1)), Acct("test", "example.com")) + LocalUser(ActorId(1), UserDetailId((1)), Acct("test", "example.com")) ) } } diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/filter/UserDeleteFilterApplicationServiceTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/filter/UserDeleteFilterApplicationServiceTest.kt index 3928ea45..fe2546f6 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/filter/UserDeleteFilterApplicationServiceTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/filter/UserDeleteFilterApplicationServiceTest.kt @@ -6,7 +6,7 @@ import dev.usbharu.hideout.core.domain.model.filter.* import dev.usbharu.hideout.core.domain.model.filter.Filter import dev.usbharu.hideout.core.domain.model.filter.FilterKeyword 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.LocalUser import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Test @@ -43,7 +43,7 @@ class UserDeleteFilterApplicationServiceTest { whenever(filterRepository.findByFilterId(FilterId(1))).doReturn(filter) service.execute( - DeleteFilter(1), FromApi( + DeleteFilter(1), LocalUser( ActorId(1), UserDetailId(1), Acct("test", "example.com") ) @@ -56,7 +56,7 @@ class UserDeleteFilterApplicationServiceTest { fun フィルターが見つからない場合失敗() = runTest { assertThrows { service.execute( - DeleteFilter(1), FromApi( + DeleteFilter(1), LocalUser( ActorId(1), UserDetailId(1), Acct("test", "example.com") ) @@ -77,7 +77,7 @@ class UserDeleteFilterApplicationServiceTest { assertThrows { service.execute( - DeleteFilter(1), FromApi( + DeleteFilter(1), LocalUser( ActorId(3), UserDetailId(3), Acct("test", "example.com") ) diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/filter/UserGetFilterApplicationServiceTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/filter/UserGetFilterApplicationServiceTest.kt index b3b2db82..f7d2e01f 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/filter/UserGetFilterApplicationServiceTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/filter/UserGetFilterApplicationServiceTest.kt @@ -6,7 +6,7 @@ import dev.usbharu.hideout.core.domain.model.filter.* import dev.usbharu.hideout.core.domain.model.filter.Filter import dev.usbharu.hideout.core.domain.model.filter.FilterKeyword 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.LocalUser import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Test @@ -43,7 +43,7 @@ class UserGetFilterApplicationServiceTest { whenever(filterRepository.findByFilterId(FilterId(1))).doReturn(filter) service.execute( - GetFilter(1), FromApi( + GetFilter(1), LocalUser( ActorId(1), UserDetailId(1), Acct("test", "example.com") ) @@ -64,7 +64,7 @@ class UserGetFilterApplicationServiceTest { assertThrows { service.execute( - GetFilter(1), FromApi( + GetFilter(1), LocalUser( ActorId(3), UserDetailId(3), Acct("test", "example.com") ) @@ -76,7 +76,7 @@ class UserGetFilterApplicationServiceTest { fun フィルターが見つからない場合失敗() = runTest { assertThrows { service.execute( - GetFilter(1), FromApi( + GetFilter(1), LocalUser( ActorId(3), UserDetailId(3), Acct("test", "example.com") ) diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/post/DeleteLocalPostApplicationServiceTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/post/DeleteLocalPostApplicationServiceTest.kt index b4c747ba..4a804882 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/post/DeleteLocalPostApplicationServiceTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/post/DeleteLocalPostApplicationServiceTest.kt @@ -8,7 +8,7 @@ import dev.usbharu.hideout.core.domain.model.post.PostId import dev.usbharu.hideout.core.domain.model.post.PostRepository import dev.usbharu.hideout.core.domain.model.post.TestPostFactory 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.LocalUser import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Test @@ -41,7 +41,7 @@ class DeleteLocalPostApplicationServiceTest { whenever(postRepository.findById(PostId(1))).doReturn(TestPostFactory.create(actorId = 2)) whenever(actorRepository.findById(ActorId(2))).doReturn(TestActorFactory.create(id = 2)) - service.execute(DeleteLocalPost(1), FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com"))) + service.execute(DeleteLocalPost(1), LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com"))) } @Test @@ -49,7 +49,7 @@ class DeleteLocalPostApplicationServiceTest { whenever(postRepository.findById(PostId(1))).doReturn(TestPostFactory.create(actorId = 2)) assertThrows { - service.execute(DeleteLocalPost(1), FromApi(ActorId(3), UserDetailId(3), Acct("test", "example.com"))) + service.execute(DeleteLocalPost(1), LocalUser(ActorId(3), UserDetailId(3), Acct("test", "example.com"))) } } } \ No newline at end of file diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationServiceTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationServiceTest.kt index 40cc7162..cd4c11e7 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationServiceTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationServiceTest.kt @@ -8,7 +8,7 @@ import dev.usbharu.hideout.core.domain.model.post.PostRepository import dev.usbharu.hideout.core.domain.model.post.TestPostFactory import dev.usbharu.hideout.core.domain.model.post.Visibility 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.LocalUser import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId import dev.usbharu.hideout.core.infrastructure.factory.PostFactoryImpl import kotlinx.coroutines.test.runTest @@ -59,7 +59,7 @@ class RegisterLocalPostApplicationServiceTest { ).doReturn(post) service.execute( - RegisterLocalPost("content test", null, Visibility.PUBLIC, null, null, false, emptyList()), FromApi( + RegisterLocalPost("content test", null, Visibility.PUBLIC, null, null, false, emptyList()), LocalUser( ActorId(1), UserDetailId(1), Acct("test", "example.com") ) ) @@ -71,7 +71,7 @@ class RegisterLocalPostApplicationServiceTest { fun actorが見つからないと失敗() = runTest { assertThrows { service.execute( - RegisterLocalPost("content test", null, Visibility.PUBLIC, null, null, false, emptyList()), FromApi( + RegisterLocalPost("content test", null, Visibility.PUBLIC, null, null, false, emptyList()), LocalUser( ActorId(1), UserDetailId(1), Acct("test", "example.com") ) ) diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNoteApplicationServiceTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNoteApplicationServiceTest.kt index 25c8524b..7cb0e206 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNoteApplicationServiceTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/post/UpdateLocalNoteApplicationServiceTest.kt @@ -8,7 +8,7 @@ import dev.usbharu.hideout.core.domain.model.actor.TestActorFactory import dev.usbharu.hideout.core.domain.model.post.* import dev.usbharu.hideout.core.domain.model.post.Post 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.LocalUser import dev.usbharu.hideout.core.domain.model.userdetails.UserDetail import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailHashedPassword import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId @@ -63,7 +63,7 @@ class UpdateLocalNoteApplicationServiceTest { whenever(postContentFactoryImpl.create(eq("test"))).doReturn(content) service.execute( - UpdateLocalNote(post.id.id, null, "test", false, emptyList()), FromApi( + UpdateLocalNote(post.id.id, null, "test", false, emptyList()), LocalUser( post.actorId, UserDetailId(1), Acct("test", "example.com") @@ -84,7 +84,7 @@ class UpdateLocalNoteApplicationServiceTest { fun postが見つからない場合失敗() = runTest { assertThrows { service.execute( - UpdateLocalNote(1, null, "test", false, emptyList()), FromApi( + UpdateLocalNote(1, null, "test", false, emptyList()), LocalUser( ActorId(1), UserDetailId(1), Acct("test", "example.com") ) @@ -98,7 +98,7 @@ class UpdateLocalNoteApplicationServiceTest { assertThrows { service.execute( - UpdateLocalNote(1, null, "test", false, emptyList()), FromApi( + UpdateLocalNote(1, null, "test", false, emptyList()), LocalUser( ActorId(1), UserDetailId(1), Acct("test", "example.com") ) @@ -112,7 +112,7 @@ class UpdateLocalNoteApplicationServiceTest { assertThrows { service.execute( - UpdateLocalNote(1, null, "test", false, emptyList()), FromApi( + UpdateLocalNote(1, null, "test", false, emptyList()), LocalUser( ActorId(1), UserDetailId(1), Acct("test", "example.com") ) @@ -138,7 +138,7 @@ class UpdateLocalNoteApplicationServiceTest { assertThrows { service.execute( - UpdateLocalNote(post.id.id, null, "test", false, emptyList()), FromApi( + UpdateLocalNote(post.id.id, null, "test", false, emptyList()), LocalUser( post.actorId, UserDetailId(1), Acct("test", "example.com") diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/UserAcceptFollowRequestApplicationServiceTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/UserAcceptFollowRequestApplicationServiceTest.kt index 8f47c41f..353a9769 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/UserAcceptFollowRequestApplicationServiceTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/UserAcceptFollowRequestApplicationServiceTest.kt @@ -7,7 +7,7 @@ import dev.usbharu.hideout.core.domain.model.actor.TestActorFactory 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.acct.Acct -import dev.usbharu.hideout.core.domain.model.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions.assertFalse @@ -42,7 +42,7 @@ class UserAcceptFollowRequestApplicationServiceTest { @Test fun actorが見つからない場合失敗() = runTest { assertThrows { - service.execute(AcceptFollowRequest(1), FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com"))) + service.execute(AcceptFollowRequest(1), LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com"))) } } @@ -51,7 +51,7 @@ class UserAcceptFollowRequestApplicationServiceTest { whenever(actorRepository.findById(ActorId(2))).doReturn(TestActorFactory.create(id = 2)) assertThrows { - service.execute(AcceptFollowRequest(1), FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com"))) + service.execute(AcceptFollowRequest(1), LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com"))) } } @@ -68,7 +68,7 @@ class UserAcceptFollowRequestApplicationServiceTest { followRequesting = true, mutingFollowRequest = false ) ) - service.execute(AcceptFollowRequest(1), FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com"))) + service.execute(AcceptFollowRequest(1), LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com"))) argumentCaptor { verify(relationshipRepository).save(capture()) 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 581bac6a..ee8c84ec 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 @@ -2,7 +2,7 @@ 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 dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Test import org.slf4j.LoggerFactory @@ -13,7 +13,7 @@ class LocalUserAbstractApplicationServiceTest { fun requireFromAPI() = runTest { val logger = LoggerFactory.getLogger(javaClass) val value = object : LocalUserAbstractApplicationService(TestTransaction, logger) { - override suspend fun internalExecute(command: Unit, principal: FromApi) { + override suspend fun internalExecute(command: Unit, principal: LocalUser) { } } diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/service/post/DefaultPostReadAccessControlTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/service/post/DefaultPostReadAccessControlTest.kt index 2826cb58..5340309f 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/service/post/DefaultPostReadAccessControlTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/service/post/DefaultPostReadAccessControlTest.kt @@ -7,7 +7,7 @@ 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.acct.Acct import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous -import dev.usbharu.hideout.core.domain.model.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions.assertFalse @@ -44,7 +44,7 @@ class DefaultPostReadAccessControlTest { val actual = service.isAllow( TestPostFactory.create(actorId = 1), - FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com")) + LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com")) ) assertFalse(actual) @@ -72,7 +72,7 @@ class DefaultPostReadAccessControlTest { fun DirectでvisibleActorsに含まれていたら見れる() = runTest { val actual = service.isAllow( TestPostFactory.create(actorId = 1, visibility = Visibility.DIRECT, visibleActors = listOf(2)), - FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com")) + LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com")) ) assertTrue(actual) @@ -82,7 +82,7 @@ class DefaultPostReadAccessControlTest { fun DirectでvisibleActorsに含まれていなかったら見れない() = runTest { val actual = service.isAllow( TestPostFactory.create(actorId = 1, visibility = Visibility.DIRECT, visibleActors = listOf(3)), - FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com")) + LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com")) ) assertFalse(actual) @@ -111,7 +111,7 @@ class DefaultPostReadAccessControlTest { val actual = service.isAllow( TestPostFactory.create(actorId = 1, visibility = Visibility.FOLLOWERS), - FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com")) + LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com")) ) assertTrue(actual) @@ -121,7 +121,7 @@ class DefaultPostReadAccessControlTest { fun relationshipが見つからない場合見れない() = runTest { val actual = service.isAllow( TestPostFactory.create(actorId = 1, visibility = Visibility.FOLLOWERS), - FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com")) + LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com")) ) assertFalse(actual) @@ -150,7 +150,7 @@ class DefaultPostReadAccessControlTest { val actual = service.isAllow( TestPostFactory.create(actorId = 1, visibility = Visibility.FOLLOWERS), - FromApi(ActorId(2), UserDetailId(2), Acct("test", "example.com")) + LocalUser(ActorId(2), UserDetailId(2), Acct("test", "example.com")) ) assertFalse(actual) diff --git a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/accounts/GetAccountApplicationService.kt b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/accounts/GetAccountApplicationService.kt index 04d274a4..27f861c7 100644 --- a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/accounts/GetAccountApplicationService.kt +++ b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/accounts/GetAccountApplicationService.kt @@ -18,7 +18,7 @@ package dev.usbharu.hideout.mastodon.application.accounts import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction -import dev.usbharu.hideout.core.domain.model.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.Account import dev.usbharu.hideout.mastodon.query.AccountQueryService import org.slf4j.LoggerFactory @@ -30,7 +30,7 @@ class GetAccountApplicationService(private val accountQueryService: AccountQuery transaction, logger ) { - override suspend fun internalExecute(command: GetAccount, principal: FromApi): Account { + override suspend fun internalExecute(command: GetAccount, principal: LocalUser): Account { return accountQueryService.findById(command.accountId.toLong()) ?: throw Exception("Account not found") } diff --git a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/filter/DeleteFilterV1ApplicationService.kt b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/filter/DeleteFilterV1ApplicationService.kt index 919d51ef..dd48a024 100644 --- a/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/filter/DeleteFilterV1ApplicationService.kt +++ b/hideout-mastodon/src/main/kotlin/dev/usbharu/hideout/mastodon/application/filter/DeleteFilterV1ApplicationService.kt @@ -21,7 +21,7 @@ import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationS import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.filter.FilterKeywordId import dev.usbharu.hideout.core.domain.model.filter.FilterRepository -import dev.usbharu.hideout.core.domain.model.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -30,7 +30,7 @@ class DeleteFilterV1ApplicationService(private val filterRepository: FilterRepos LocalUserAbstractApplicationService( transaction, logger ) { - override suspend fun internalExecute(command: DeleteFilterV1, principal: FromApi) { + override suspend fun internalExecute(command: DeleteFilterV1, principal: LocalUser) { val filter = filterRepository.findByFilterKeywordId(FilterKeywordId(command.filterKeywordId)) ?: throw IllegalArgumentException("Filter ${command.filterKeywordId} not found") if (principal.userDetailId != filter.userDetailId) { 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 c5748dab..18e72dbb 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.domain.model.support.principal.PrincipalContextHolder +import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.SpringSecurityOauth2PrincipalContextHolder import dev.usbharu.hideout.mastodon.application.filter.DeleteFilterV1 import dev.usbharu.hideout.mastodon.application.filter.DeleteFilterV1ApplicationService import dev.usbharu.hideout.mastodon.application.filter.GetFilterV1 @@ -41,7 +41,7 @@ class SpringFilterApi( private val deleteFilterV1ApplicationService: DeleteFilterV1ApplicationService, private val userDeleteFilterApplicationService: UserDeleteFilterApplicationService, private val userGetFilterApplicationService: UserGetFilterApplicationService, - private val principalContextHolder: PrincipalContextHolder + private val principalContextHolder: SpringSecurityOauth2PrincipalContextHolder ) : FilterApi { override suspend fun apiV1FiltersIdDelete(id: String): ResponseEntity { 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 c22afbc7..0dff1da7 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.domain.model.support.principal.PrincipalContextHolder +import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.SpringSecurityOauth2PrincipalContextHolder 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 principalContextHolder: PrincipalContextHolder + private val principalContextHolder: SpringSecurityOauth2PrincipalContextHolder ) : MediaApi { override suspend fun apiV1MediaPost( file: MultipartFile, 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 3f981012..92b0e18a 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,7 +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.domain.model.support.principal.PrincipalContextHolder +import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.SpringSecurityOauth2PrincipalContextHolder import dev.usbharu.hideout.mastodon.application.status.GetStatus import dev.usbharu.hideout.mastodon.application.status.GetStatusApplicationService import dev.usbharu.hideout.mastodon.interfaces.api.StatusesRequest.Visibility.* @@ -32,7 +32,7 @@ import org.springframework.stereotype.Controller class SpringStatusApi( private val registerLocalPostApplicationService: RegisterLocalPostApplicationService, private val getStatusApplicationService: GetStatusApplicationService, - private val principalContextHolder: PrincipalContextHolder + private val principalContextHolder: SpringSecurityOauth2PrincipalContextHolder ) : StatusApi { override suspend fun apiV1StatusesIdEmojiReactionsEmojiDelete(id: String, emoji: String): ResponseEntity { return super.apiV1StatusesIdEmojiReactionsEmojiDelete(id, emoji) diff --git a/hideout-mastodon/src/test/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImplTest.kt b/hideout-mastodon/src/test/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImplTest.kt index a23dd3ef..da7ef30c 100644 --- a/hideout-mastodon/src/test/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImplTest.kt +++ b/hideout-mastodon/src/test/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImplTest.kt @@ -3,7 +3,7 @@ package dev.usbharu.hideout.mastodon.infrastructure.exposedquery import dev.usbharu.hideout.SpringApplication 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.support.principal.FromApi +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions.assertNull @@ -26,7 +26,7 @@ class StatusQueryServiceImplTest { @Test fun フォロワー限定をフォロワー以外は見れない() = runTest { val status = - statusQueryServiceImpl.findByPostId(4, FromApi(ActorId(1), UserDetailId(1), Acct("test", "example.com"))) + statusQueryServiceImpl.findByPostId(4, LocalUser(ActorId(1), UserDetailId(1), Acct("test", "example.com"))) assertNull(status) }