feat: 新しい認可システムを組み込み

This commit is contained in:
usbharu 2024-08-06 13:00:00 +09:00
parent 716bf190b5
commit c056b7598b
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
41 changed files with 210 additions and 335 deletions

View File

@ -18,12 +18,10 @@ package dev.usbharu.hideout.core.application.filter
import dev.usbharu.hideout.core.domain.model.filter.FilterAction
import dev.usbharu.hideout.core.domain.model.filter.FilterContext
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
data class RegisterFilter(
val filterName: String,
val filterContext: Set<FilterContext>,
val filterAction: FilterAction,
val filterKeywords: Set<RegisterFilterKeyword>,
val userDetailId: UserDetailId
)

View File

@ -16,11 +16,11 @@
package dev.usbharu.hideout.core.application.filter
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.filter.*
import dev.usbharu.hideout.core.domain.model.filter.FilterKeyword
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.shared.id.IdGenerateService
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -31,16 +31,16 @@ class UserRegisterFilterApplicationService(
private val filterRepository: FilterRepository,
transaction: Transaction,
) :
AbstractApplicationService<RegisterFilter, Filter>(
LocalUserAbstractApplicationService<RegisterFilter, Filter>(
transaction,
logger
) {
override suspend fun internalExecute(command: RegisterFilter, principal: Principal): Filter {
override suspend fun internalExecute(command: RegisterFilter, principal: FromApi): Filter {
val filter = dev.usbharu.hideout.core.domain.model.filter.Filter.create(
id = FilterId(idGenerateService.generateId()),
userDetailId = command.userDetailId,
userDetailId = principal.userDetailId,
name = FilterName(command.filterName),
filterContext = command.filterContext,
filterAction = command.filterAction,

View File

@ -19,7 +19,6 @@ package dev.usbharu.hideout.core.application.post
import dev.usbharu.hideout.core.domain.model.post.Visibility
data class RegisterLocalPost(
val userDetailId: Long,
val content: String,
val overview: String?,
val visibility: Visibility,

View File

@ -16,15 +16,14 @@
package dev.usbharu.hideout.core.application.post
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.media.MediaId
import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.post.PostOverview
import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import dev.usbharu.hideout.core.infrastructure.factory.PostFactoryImpl
import org.slf4j.Logger
@ -38,11 +37,11 @@ class RegisterLocalPostApplicationService(
private val postRepository: PostRepository,
private val userDetailRepository: UserDetailRepository,
transaction: Transaction,
) : AbstractApplicationService<RegisterLocalPost, Long>(transaction, Companion.logger) {
) : LocalUserAbstractApplicationService<RegisterLocalPost, Long>(transaction, Companion.logger) {
override suspend fun internalExecute(command: RegisterLocalPost, principal: Principal): Long {
override suspend fun internalExecute(command: RegisterLocalPost, principal: FromApi): Long {
val actorId = (
userDetailRepository.findById(UserDetailId(command.userDetailId))
userDetailRepository.findById(principal.userDetailId)
?: throw IllegalStateException("actor not found")
).actorId

View File

@ -16,6 +16,4 @@
package dev.usbharu.hideout.core.application.relationship.acceptfollowrequest
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
data class AcceptFollowRequest(val sourceActorId: Long, val userDetailId: UserDetailId)
data class AcceptFollowRequest(val sourceActorId: Long)

View File

@ -17,12 +17,12 @@
package dev.usbharu.hideout.core.application.relationship.acceptfollowrequest
import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -34,10 +34,10 @@ class UserAcceptFollowRequestApplicationService(
private val actorRepository: ActorRepository,
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<AcceptFollowRequest, Unit>(transaction, logger) {
override suspend fun internalExecute(command: AcceptFollowRequest, principal: Principal) {
LocalUserAbstractApplicationService<AcceptFollowRequest, Unit>(transaction, logger) {
override suspend fun internalExecute(command: AcceptFollowRequest, principal: FromApi) {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val userDetail = userDetailRepository.findById(principal.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!
val targetId = ActorId(command.sourceActorId)

View File

@ -16,6 +16,4 @@
package dev.usbharu.hideout.core.application.relationship.block
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
data class Block(val targetActorId: Long, val userDetailId: UserDetailId)
data class Block(val targetActorId: Long)

View File

@ -16,13 +16,13 @@
package dev.usbharu.hideout.core.application.relationship.block
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import dev.usbharu.hideout.core.domain.service.relationship.RelationshipDomainService
import org.slf4j.LoggerFactory
@ -36,10 +36,10 @@ class UserBlockApplicationService(
private val userDetailRepository: UserDetailRepository,
private val relationshipDomainService: RelationshipDomainService,
) :
AbstractApplicationService<Block, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Block, principal: Principal) {
LocalUserAbstractApplicationService<Block, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Block, principal: FromApi) {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val userDetail = userDetailRepository.findById(principal.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!
val targetId = ActorId(command.targetActorId)

View File

@ -16,6 +16,4 @@
package dev.usbharu.hideout.core.application.relationship.followrequest
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
data class FollowRequest(val targetActorId: Long, val userDetailId: UserDetailId)
data class FollowRequest(val targetActorId: Long)

View File

@ -16,13 +16,13 @@
package dev.usbharu.hideout.core.application.relationship.followrequest
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -33,14 +33,14 @@ class UserFollowRequestApplicationService(
transaction: Transaction,
private val actorRepository: ActorRepository,
private val userDetailRepository: UserDetailRepository,
) : AbstractApplicationService<FollowRequest, Unit>(
) : LocalUserAbstractApplicationService<FollowRequest, Unit>(
transaction,
logger
) {
override suspend fun internalExecute(command: FollowRequest, principal: Principal) {
override suspend fun internalExecute(command: FollowRequest, principal: FromApi) {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val userDetail = userDetailRepository.findById(principal.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!
val targetId = ActorId(command.targetActorId)

View File

@ -16,6 +16,4 @@
package dev.usbharu.hideout.core.application.relationship.get
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
data class GetRelationship(val targetActorId: Long, val userDetailId: UserDetailId)
data class GetRelationship(val targetActorId: Long)

View File

@ -16,14 +16,14 @@
package dev.usbharu.hideout.core.application.relationship.get
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.actorinstancerelationship.ActorInstanceRelationship
import dev.usbharu.hideout.core.domain.model.actorinstancerelationship.ActorInstanceRelationshipRepository
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -36,12 +36,12 @@ class GetRelationshipApplicationService(
private val actorInstanceRelationshipRepository: ActorInstanceRelationshipRepository,
transaction: Transaction,
) :
AbstractApplicationService<GetRelationship, Relationship>(
LocalUserAbstractApplicationService<GetRelationship, Relationship>(
transaction,
logger
) {
override suspend fun internalExecute(command: GetRelationship, principal: Principal): Relationship {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
override suspend fun internalExecute(command: GetRelationship, principal: FromApi): Relationship {
val userDetail = userDetailRepository.findById(principal.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!
val targetId = ActorId(command.targetActorId)
val target = actorRepository.findById(targetId)!!

View File

@ -16,6 +16,4 @@
package dev.usbharu.hideout.core.application.relationship.mute
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
data class Mute(val targetActorId: Long, val userDetailId: UserDetailId)
data class Mute(val targetActorId: Long)

View File

@ -17,13 +17,13 @@
package dev.usbharu.hideout.core.application.relationship.mute
import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -35,10 +35,10 @@ class UserMuteApplicationService(
private val actorRepository: ActorRepository,
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<Mute, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Mute, principal: Principal) {
LocalUserAbstractApplicationService<Mute, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Mute, principal: FromApi) {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val userDetail = userDetailRepository.findById(principal.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!
val targetId = ActorId(command.targetActorId)

View File

@ -16,6 +16,4 @@
package dev.usbharu.hideout.core.application.relationship.rejectfollowrequest
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
data class RejectFollowRequest(val sourceActorId: Long, val userDetailId: UserDetailId)
data class RejectFollowRequest(val sourceActorId: Long)

View File

@ -17,12 +17,12 @@
package dev.usbharu.hideout.core.application.relationship.rejectfollowrequest
import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -34,10 +34,10 @@ class UserRejectFollowRequestApplicationService(
private val actorRepository: ActorRepository,
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<RejectFollowRequest, Unit>(transaction, logger) {
override suspend fun internalExecute(command: RejectFollowRequest, principal: Principal) {
LocalUserAbstractApplicationService<RejectFollowRequest, Unit>(transaction, logger) {
override suspend fun internalExecute(command: RejectFollowRequest, principal: FromApi) {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val userDetail = userDetailRepository.findById(principal.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!
val targetId = ActorId(command.sourceActorId)

View File

@ -16,4 +16,4 @@
package dev.usbharu.hideout.core.application.relationship.removefromfollowers
data class RemoveFromFollowers(val targetActorId: Long, val userDetailId: Long)
data class RemoveFromFollowers(val targetActorId: Long)

View File

@ -17,14 +17,13 @@
package dev.usbharu.hideout.core.application.relationship.removefromfollowers
import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -36,10 +35,10 @@ class UserRemoveFromFollowersApplicationService(
private val actorRepository: ActorRepository,
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<RemoveFromFollowers, Unit>(transaction, logger) {
override suspend fun internalExecute(command: RemoveFromFollowers, principal: Principal) {
LocalUserAbstractApplicationService<RemoveFromFollowers, Unit>(transaction, logger) {
override suspend fun internalExecute(command: RemoveFromFollowers, principal: FromApi) {
val userDetail = userDetailRepository.findById(UserDetailId(command.userDetailId))!!
val userDetail = userDetailRepository.findById(principal.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!
val targetId = ActorId(command.targetActorId)

View File

@ -16,6 +16,4 @@
package dev.usbharu.hideout.core.application.relationship.unblock
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
data class Unblock(val targetActorId: Long, val userDetailId: UserDetailId)
data class Unblock(val targetActorId: Long)

View File

@ -17,13 +17,13 @@
package dev.usbharu.hideout.core.application.relationship.unblock
import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -35,10 +35,10 @@ class UserUnblockApplicationService(
private val actorRepository: ActorRepository,
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<Unblock, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Unblock, principal: Principal) {
LocalUserAbstractApplicationService<Unblock, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Unblock, principal: FromApi) {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val userDetail = userDetailRepository.findById(principal.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!
val targetId = ActorId(command.targetActorId)

View File

@ -16,6 +16,4 @@
package dev.usbharu.hideout.core.application.relationship.unfollow
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
data class Unfollow(val targetActorId: Long, val userDetailId: UserDetailId)
data class Unfollow(val targetActorId: Long)

View File

@ -17,13 +17,13 @@
package dev.usbharu.hideout.core.application.relationship.unfollow
import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -35,10 +35,10 @@ class UserUnfollowApplicationService(
private val actorRepository: ActorRepository,
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<Unfollow, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Unfollow, principal: Principal) {
LocalUserAbstractApplicationService<Unfollow, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Unfollow, principal: FromApi) {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val userDetail = userDetailRepository.findById(principal.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!
val targetId = ActorId(command.targetActorId)

View File

@ -16,6 +16,4 @@
package dev.usbharu.hideout.core.application.relationship.unmute
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
data class Unmute(val targetActorId: Long, val userDetailId: UserDetailId)
data class Unmute(val targetActorId: Long)

View File

@ -17,13 +17,13 @@
package dev.usbharu.hideout.core.application.relationship.unmute
import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -35,14 +35,14 @@ class UserUnmuteApplicationService(
private val actorRepository: ActorRepository,
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<Unmute, Unit>(transaction, logger) {
LocalUserAbstractApplicationService<Unmute, Unit>(transaction, logger) {
companion object {
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
override suspend fun internalExecute(command: Unmute, principal: Principal) {
override suspend fun internalExecute(command: Unmute, principal: FromApi) {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val userDetail = userDetailRepository.findById(principal.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!
val targetId = ActorId(command.targetActorId)

View File

@ -1,30 +0,0 @@
/*
* Copyright (C) 2024 usbharu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.usbharu.hideout.core.application.shared
interface CommandExecutor {
val executor: String
}
interface UserDetailGettableCommandExecutor : CommandExecutor {
val userDetailId: Long
}
data class DomainEventCommandExecutor(
override val executor: String,
val commandExecutor: CommandExecutor?
) : CommandExecutor

View File

@ -4,7 +4,12 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.support.acct.Acct
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
class FromApi(actorId: ActorId, override val userDetailId: UserDetailId, override val acct: Acct) : Principal(
actorId, userDetailId,
class FromApi(
actorId: ActorId,
override val userDetailId: UserDetailId,
override val acct: Acct
) : Principal(
actorId,
userDetailId,
acct
)

View File

@ -0,0 +1,5 @@
package dev.usbharu.hideout.core.domain.model.support.principal
interface PrincipalContextHolder {
suspend fun getPrincipal(): Principal
}

View File

@ -0,0 +1,37 @@
package dev.usbharu.hideout.core.infrastructure.exposedquery
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import dev.usbharu.hideout.core.infrastructure.exposedrepository.AbstractRepository
import dev.usbharu.hideout.core.infrastructure.exposedrepository.Actors
import dev.usbharu.hideout.core.infrastructure.exposedrepository.UserDetails
import dev.usbharu.hideout.core.query.principal.PrincipalDTO
import dev.usbharu.hideout.core.query.principal.PrincipalQueryService
import org.jetbrains.exposed.sql.selectAll
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Repository
@Repository
class ExposedPrincipalQueryService : PrincipalQueryService, AbstractRepository() {
override suspend fun findByUserDetailId(userDetailId: UserDetailId): PrincipalDTO {
return query {
UserDetails.leftJoin(Actors).selectAll().where { UserDetails.id eq userDetailId.id }.single()
.let {
PrincipalDTO(
UserDetailId(it[UserDetails.id]),
ActorId(it[UserDetails.actorId]),
it[Actors.name],
it[Actors.domain]
)
}
}
}
override val logger: Logger
get() = Companion.logger
companion object {
private val logger: Logger = LoggerFactory.getLogger(ExposedPrincipalQueryService::class.java)
}
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) 2024 usbharu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.usbharu.hideout.core.infrastructure.springframework
import dev.usbharu.hideout.core.application.shared.CommandExecutor
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.Oauth2CommandExecutorFactory
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.security.oauth2.jwt.Jwt
import org.springframework.stereotype.Component
@Component
class DelegateCommandExecutorFactory(
private val oauth2CommandExecutorFactory: Oauth2CommandExecutorFactory,
private val mvcCommandExecutorFactory: SpringMvcCommandExecutorFactory,
) {
fun getCommandExecutor(): CommandExecutor {
if (SecurityContextHolder.getContext().authentication.principal is Jwt) {
return oauth2CommandExecutorFactory.getCommandExecutor()
}
return mvcCommandExecutorFactory.getCommandExecutor()
}
}

View File

@ -1,27 +0,0 @@
/*
* Copyright (C) 2024 usbharu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.usbharu.hideout.core.infrastructure.springframework
import dev.usbharu.hideout.core.application.shared.CommandExecutor
open class HttpCommandExecutor(
override val executor: String,
val ip: String,
val userAgent: String,
) : CommandExecutor {
override fun toString(): String = "HttpCommandExecutor(executor='$executor', ip='$ip', userAgent='$userAgent')"
}

View File

@ -1,31 +0,0 @@
/*
* Copyright (C) 2024 usbharu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.usbharu.hideout.core.infrastructure.springframework
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.stereotype.Component
import org.springframework.web.context.request.RequestContextHolder
import org.springframework.web.context.request.ServletRequestAttributes
@Component
class SpringMvcCommandExecutorFactory {
fun getCommandExecutor(): HttpCommandExecutor {
val name = SecurityContextHolder.getContext().authentication?.name ?: "ANONYMOUS"
val request = (RequestContextHolder.currentRequestAttributes() as ServletRequestAttributes).request
return HttpCommandExecutor(name, request.remoteAddr, request.getHeader("user-agent").orEmpty())
}
}

View File

@ -1,24 +0,0 @@
/*
* Copyright (C) 2024 usbharu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.usbharu.hideout.core.infrastructure.springframework.oauth2
import dev.usbharu.hideout.core.application.shared.CommandExecutor
import dev.usbharu.hideout.core.application.shared.UserDetailGettableCommandExecutor
class Oauth2CommandExecutor(override val executor: String, override val userDetailId: Long) :
CommandExecutor,
UserDetailGettableCommandExecutor

View File

@ -1,33 +0,0 @@
/*
* Copyright (C) 2024 usbharu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.usbharu.hideout.core.infrastructure.springframework.oauth2
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.security.oauth2.jwt.Jwt
import org.springframework.stereotype.Component
@Component
class Oauth2CommandExecutorFactory {
fun getCommandExecutor(): Oauth2CommandExecutor {
val principal = SecurityContextHolder.getContext().authentication.principal as Jwt
return Oauth2CommandExecutor(
principal.subject,
principal.getClaim<String>("uid").toLong()
)
}
}

View File

@ -0,0 +1,27 @@
package dev.usbharu.hideout.core.infrastructure.springframework.oauth2
import dev.usbharu.hideout.core.domain.model.support.acct.Acct
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import dev.usbharu.hideout.core.query.principal.PrincipalQueryService
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.security.oauth2.jwt.Jwt
import org.springframework.stereotype.Component
@Component
class SpringSecurityOauth2PrincipalContextHolder(private val principalQueryService: PrincipalQueryService) :
PrincipalContextHolder {
override suspend fun getPrincipal(): FromApi {
val principal = SecurityContextHolder.getContext().authentication?.principal as Jwt
val id = principal.getClaim<String>("uid").toLong()
val userDetail = principalQueryService.findByUserDetailId(UserDetailId(id))
return FromApi(
userDetail.actorId,
userDetail.userDetailId,
Acct(userDetail.username, userDetail.host)
)
}
}

View File

@ -19,7 +19,6 @@ package dev.usbharu.hideout.core.interfaces.api.auth
import dev.usbharu.hideout.core.application.actor.RegisterLocalActor
import dev.usbharu.hideout.core.application.actor.RegisterLocalActorApplicationService
import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous
import dev.usbharu.hideout.core.infrastructure.springframework.SpringMvcCommandExecutorFactory
import jakarta.servlet.http.HttpServletRequest
import org.springframework.stereotype.Controller
import org.springframework.validation.annotation.Validated
@ -30,7 +29,6 @@ import org.springframework.web.bind.annotation.PostMapping
@Controller
class AuthController(
private val registerLocalActorApplicationService: RegisterLocalActorApplicationService,
private val springMvcCommandExecutorFactory: SpringMvcCommandExecutorFactory,
) {
@GetMapping("/auth/sign_up")
@Suppress("FunctionOnlyReturningConstant")

View File

@ -0,0 +1,6 @@
package dev.usbharu.hideout.core.query.principal
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
data class PrincipalDTO(val userDetailId: UserDetailId, val actorId: ActorId, val username: String, val host: String)

View File

@ -0,0 +1,7 @@
package dev.usbharu.hideout.core.query.principal
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
interface PrincipalQueryService {
suspend fun findByUserDetailId(userDetailId: UserDetailId): PrincipalDTO
}

View File

@ -38,8 +38,7 @@ import dev.usbharu.hideout.core.application.relationship.unfollow.Unfollow
import dev.usbharu.hideout.core.application.relationship.unfollow.UserUnfollowApplicationService
import dev.usbharu.hideout.core.application.relationship.unmute.Unmute
import dev.usbharu.hideout.core.application.relationship.unmute.UserUnmuteApplicationService
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.Oauth2CommandExecutor
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.Oauth2CommandExecutorFactory
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.SpringSecurityOauth2PrincipalContextHolder
import dev.usbharu.hideout.mastodon.application.accounts.GetAccount
import dev.usbharu.hideout.mastodon.application.accounts.GetAccountApplicationService
import dev.usbharu.hideout.mastodon.interfaces.api.generated.AccountApi
@ -49,7 +48,6 @@ import org.springframework.stereotype.Controller
@Controller
class SpringAccountApi(
private val oauth2CommandExecutorFactory: Oauth2CommandExecutorFactory,
private val getUserDetailApplicationService: GetUserDetailApplicationService,
private val getAccountApplicationService: GetAccountApplicationService,
private val userFollowRequestApplicationService: UserFollowRequestApplicationService,
@ -62,31 +60,33 @@ class SpringAccountApi(
private val userRejectFollowRequestApplicationService: UserRejectFollowRequestApplicationService,
private val userRemoveFromFollowersApplicationService: UserRemoveFromFollowersApplicationService,
private val userUnfollowApplicationService: UserUnfollowApplicationService,
private val principalContextHolder: SpringSecurityOauth2PrincipalContextHolder
) : AccountApi {
override suspend fun apiV1AccountsIdBlockPost(id: String): ResponseEntity<Relationship> {
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
userBlockApplicationService.execute(Block(id.toLong()))
return fetchRelationship(id, executor)
userBlockApplicationService.execute(Block(id.toLong()), principalContextHolder.getPrincipal())
return fetchRelationship(id)
}
override suspend fun apiV1AccountsIdFollowPost(
id: String,
followRequestBody: FollowRequestBody?,
): ResponseEntity<Relationship> {
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
userFollowRequestApplicationService.execute(
FollowRequest(id.toLong())
FollowRequest(id.toLong()), principalContextHolder.getPrincipal()
)
return fetchRelationship(id, executor)
return fetchRelationship(id)
}
private suspend fun fetchRelationship(
id: String,
executor: Oauth2CommandExecutor,
): ResponseEntity<Relationship> {
val relationship = getRelationshipApplicationService.execute(GetRelationship(id.toLong()))
val relationship = getRelationshipApplicationService.execute(
GetRelationship(id.toLong()),
principalContextHolder.getPrincipal()
)
return ResponseEntity.ok(
Relationship(
id = relationship.targetId.toString(),
@ -109,49 +109,44 @@ class SpringAccountApi(
override suspend fun apiV1AccountsIdGet(id: String): ResponseEntity<Account> {
return ResponseEntity.ok(
getAccountApplicationService.execute(
GetAccount(id)
GetAccount(id), principalContextHolder.getPrincipal()
)
)
}
override suspend fun apiV1AccountsIdMutePost(id: String): ResponseEntity<Relationship> {
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
userMuteApplicationService.execute(
Mute(id.toLong())
Mute(id.toLong()), principalContextHolder.getPrincipal()
)
return fetchRelationship(id, executor)
return fetchRelationship(id)
}
override suspend fun apiV1AccountsIdRemoveFromFollowersPost(id: String): ResponseEntity<Relationship> {
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
userRemoveFromFollowersApplicationService.execute(
RemoveFromFollowers(id.toLong())
RemoveFromFollowers(id.toLong()), principalContextHolder.getPrincipal()
)
return fetchRelationship(id, executor)
return fetchRelationship(id)
}
override suspend fun apiV1AccountsIdUnblockPost(id: String): ResponseEntity<Relationship> {
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
userUnblockApplicationService.execute(
Unblock(id.toLong())
Unblock(id.toLong()), principalContextHolder.getPrincipal()
)
return fetchRelationship(id, executor)
return fetchRelationship(id)
}
override suspend fun apiV1AccountsIdUnfollowPost(id: String): ResponseEntity<Relationship> {
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
userUnfollowApplicationService.execute(
Unfollow(id.toLong())
Unfollow(id.toLong()), principalContextHolder.getPrincipal()
)
return fetchRelationship(id, executor)
return fetchRelationship(id)
}
override suspend fun apiV1AccountsIdUnmutePost(id: String): ResponseEntity<Relationship> {
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
userUnmuteApplicationService.execute(
Unmute(id.toLong())
Unmute(id.toLong()), principalContextHolder.getPrincipal()
)
return fetchRelationship(id, executor)
return fetchRelationship(id)
}
override suspend fun apiV1AccountsPost(accountsCreateRequest: AccountsCreateRequest): ResponseEntity<Unit> {
@ -163,9 +158,9 @@ class SpringAccountApi(
}
override suspend fun apiV1AccountsVerifyCredentialsGet(): ResponseEntity<CredentialAccount> {
val commandExecutor = oauth2CommandExecutorFactory.getCommandExecutor()
val principal = principalContextHolder.getPrincipal()
val localActor =
getUserDetailApplicationService.execute(GetUserDetail(commandExecutor.userDetailId))
getUserDetailApplicationService.execute(GetUserDetail(principal.userDetailId.id), principal)
return ResponseEntity.ok(
CredentialAccount(
@ -215,19 +210,19 @@ class SpringAccountApi(
}
override suspend fun apiV1FollowRequestsAccountIdAuthorizePost(accountId: String): ResponseEntity<Relationship> {
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
userAcceptFollowRequestApplicationService.execute(
AcceptFollowRequest(accountId.toLong())
AcceptFollowRequest(accountId.toLong()), principalContextHolder.getPrincipal()
)
return fetchRelationship(accountId, executor)
return fetchRelationship(accountId)
}
override suspend fun apiV1FollowRequestsAccountIdRejectPost(accountId: String): ResponseEntity<Relationship> {
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
userRejectFollowRequestApplicationService.execute(
RejectFollowRequest(accountId.toLong())
RejectFollowRequest(accountId.toLong()), principalContextHolder.getPrincipal()
)
return fetchRelationship(accountId, executor)
return fetchRelationship(accountId)
}
}

View File

@ -20,7 +20,7 @@ import dev.usbharu.hideout.core.application.filter.*
import dev.usbharu.hideout.core.domain.model.filter.FilterAction
import dev.usbharu.hideout.core.domain.model.filter.FilterContext
import dev.usbharu.hideout.core.domain.model.filter.FilterMode
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.Oauth2CommandExecutorFactory
import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder
import dev.usbharu.hideout.mastodon.application.filter.DeleteFilterV1
import dev.usbharu.hideout.mastodon.application.filter.DeleteFilterV1ApplicationService
import dev.usbharu.hideout.mastodon.application.filter.GetFilterV1
@ -36,18 +36,18 @@ import org.springframework.stereotype.Controller
@Controller
class SpringFilterApi(
private val oauth2CommandExecutorFactory: Oauth2CommandExecutorFactory,
private val userRegisterFilterApplicationService: UserRegisterFilterApplicationService,
private val getFilterV1ApplicationService: GetFilterV1ApplicationService,
private val deleteFilterV1ApplicationService: DeleteFilterV1ApplicationService,
private val userDeleteFilterApplicationService: UserDeleteFilterApplicationService,
private val userGetFilterApplicationService: UserGetFilterApplicationService,
private val principalContextHolder: PrincipalContextHolder
) : FilterApi {
override suspend fun apiV1FiltersIdDelete(id: String): ResponseEntity<Any> {
return ResponseEntity.ok(
deleteFilterV1ApplicationService.execute(
DeleteFilterV1(id.toLong())
DeleteFilterV1(id.toLong()), principalContextHolder.getPrincipal()
)
)
}
@ -55,7 +55,7 @@ class SpringFilterApi(
override suspend fun apiV1FiltersIdGet(id: String): ResponseEntity<V1Filter> {
return ResponseEntity.ok(
getFilterV1ApplicationService.execute(
GetFilterV1(id.toLong())
GetFilterV1(id.toLong()), principalContextHolder.getPrincipal()
)
)
}
@ -72,7 +72,7 @@ class SpringFilterApi(
}
override suspend fun apiV1FiltersPost(v1FilterPostRequest: V1FilterPostRequest): ResponseEntity<V1Filter> {
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
val filterMode = if (v1FilterPostRequest.wholeWord == true) {
FilterMode.WHOLE_WORD
} else {
@ -91,11 +91,11 @@ class SpringFilterApi(
RegisterFilter(
v1FilterPostRequest.phrase, filterContext, FilterAction.WARN,
setOf(RegisterFilterKeyword(v1FilterPostRequest.phrase, filterMode))
)
), principalContextHolder.getPrincipal()
)
return ResponseEntity.ok(
getFilterV1ApplicationService.execute(
GetFilterV1(filter.filterKeywords.first().id)
GetFilterV1(filter.filterKeywords.first().id), principalContextHolder.getPrincipal()
)
)
}
@ -116,14 +116,14 @@ class SpringFilterApi(
override suspend fun apiV2FiltersIdDelete(id: String): ResponseEntity<Any> {
userDeleteFilterApplicationService.execute(
DeleteFilter(id.toLong())
DeleteFilter(id.toLong()), principalContextHolder.getPrincipal()
)
return ResponseEntity.ok(Unit)
}
override suspend fun apiV2FiltersIdGet(id: String): ResponseEntity<Filter> {
val filter = userGetFilterApplicationService.execute(
GetFilter(id.toLong())
GetFilter(id.toLong()), principalContextHolder.getPrincipal()
)
return ResponseEntity.ok(
filter(filter)
@ -186,7 +186,7 @@ class SpringFilterApi(
}
override suspend fun apiV2FiltersPost(filterPostRequest: FilterPostRequest): ResponseEntity<Filter> {
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
val filter = userRegisterFilterApplicationService.execute(
RegisterFilter(
filterName = filterPostRequest.title,
@ -216,7 +216,7 @@ class SpringFilterApi(
}
)
}.toSet()
)
), principalContextHolder.getPrincipal()
)
return ResponseEntity.ok(filter(filter))
}

View File

@ -19,7 +19,7 @@ package dev.usbharu.hideout.mastodon.interfaces.api
import dev.usbharu.hideout.core.application.media.UploadMedia
import dev.usbharu.hideout.core.application.media.UploadMediaApplicationService
import dev.usbharu.hideout.core.domain.model.media.FileType.*
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.Oauth2CommandExecutorFactory
import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder
import dev.usbharu.hideout.mastodon.interfaces.api.generated.MediaApi
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.MediaAttachment
import org.springframework.http.ResponseEntity
@ -30,7 +30,7 @@ import java.nio.file.Files
@Controller
class SpringMediaApi(
private val uploadMediaApplicationService: UploadMediaApplicationService,
private val oauth2CommandExecutorFactory: Oauth2CommandExecutorFactory
private val principalContextHolder: PrincipalContextHolder
) : MediaApi {
override suspend fun apiV1MediaPost(
file: MultipartFile,
@ -52,7 +52,7 @@ class SpringMediaApi(
file.originalFilename ?: file.name,
null,
description
)
), principalContextHolder.getPrincipal()
)
return ResponseEntity.ok(

View File

@ -19,8 +19,7 @@ package dev.usbharu.hideout.mastodon.interfaces.api
import dev.usbharu.hideout.core.application.post.RegisterLocalPost
import dev.usbharu.hideout.core.application.post.RegisterLocalPostApplicationService
import dev.usbharu.hideout.core.domain.model.post.Visibility
import dev.usbharu.hideout.core.infrastructure.springframework.DelegateCommandExecutorFactory
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.Oauth2CommandExecutor
import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder
import dev.usbharu.hideout.mastodon.application.status.GetStatus
import dev.usbharu.hideout.mastodon.application.status.GetStatusApplicationService
import dev.usbharu.hideout.mastodon.interfaces.api.generated.StatusApi
@ -32,9 +31,9 @@ import org.springframework.stereotype.Controller
@Controller
class SpringStatusApi(
private val delegateCommandExecutorFactory: DelegateCommandExecutorFactory,
private val registerLocalPostApplicationService: RegisterLocalPostApplicationService,
private val getStatusApplicationService: GetStatusApplicationService,
private val principalContextHolder: PrincipalContextHolder
) : StatusApi {
override suspend fun apiV1StatusesIdEmojiReactionsEmojiDelete(id: String, emoji: String): ResponseEntity<Status> {
return super.apiV1StatusesIdEmojiReactionsEmojiDelete(id, emoji)
@ -48,16 +47,15 @@ class SpringStatusApi(
return ResponseEntity.ok(
getStatusApplicationService.execute(
GetStatus(id)
GetStatus(id), principalContextHolder.getPrincipal()
)
)
}
override suspend fun apiV1StatusesPost(statusesRequest: StatusesRequest): ResponseEntity<Status> {
val executor = delegateCommandExecutorFactory.getCommandExecutor() as Oauth2CommandExecutor
val execute = registerLocalPostApplicationService.execute(
RegisterLocalPost(
userDetailId = executor.userDetailId,
content = statusesRequest.status.orEmpty(),
overview = statusesRequest.spoilerText,
visibility = when (statusesRequest.visibility) {
@ -71,11 +69,12 @@ class SpringStatusApi(
replyId = statusesRequest.inReplyToId?.toLong(),
sensitive = statusesRequest.sensitive == true,
mediaIds = statusesRequest.mediaIds.orEmpty().map { it.toLong() }
)
), principalContextHolder.getPrincipal()
)
val status = getStatusApplicationService.execute(GetStatus(execute.toString()))
val status =
getStatusApplicationService.execute(GetStatus(execute.toString()), principalContextHolder.getPrincipal())
return ResponseEntity.ok(
status
)