mirror of https://github.com/usbharu/Hideout.git
feat: 新しい認可システムを組み込み
This commit is contained in:
parent
716bf190b5
commit
c056b7598b
|
@ -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.FilterAction
|
||||||
import dev.usbharu.hideout.core.domain.model.filter.FilterContext
|
import dev.usbharu.hideout.core.domain.model.filter.FilterContext
|
||||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
|
||||||
|
|
||||||
data class RegisterFilter(
|
data class RegisterFilter(
|
||||||
val filterName: String,
|
val filterName: String,
|
||||||
val filterContext: Set<FilterContext>,
|
val filterContext: Set<FilterContext>,
|
||||||
val filterAction: FilterAction,
|
val filterAction: FilterAction,
|
||||||
val filterKeywords: Set<RegisterFilterKeyword>,
|
val filterKeywords: Set<RegisterFilterKeyword>,
|
||||||
val userDetailId: UserDetailId
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.application.filter
|
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.application.shared.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.model.filter.*
|
import dev.usbharu.hideout.core.domain.model.filter.*
|
||||||
import dev.usbharu.hideout.core.domain.model.filter.FilterKeyword
|
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 dev.usbharu.hideout.core.domain.shared.id.IdGenerateService
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -31,16 +31,16 @@ class UserRegisterFilterApplicationService(
|
||||||
private val filterRepository: FilterRepository,
|
private val filterRepository: FilterRepository,
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
) :
|
) :
|
||||||
AbstractApplicationService<RegisterFilter, Filter>(
|
LocalUserAbstractApplicationService<RegisterFilter, Filter>(
|
||||||
transaction,
|
transaction,
|
||||||
logger
|
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(
|
val filter = dev.usbharu.hideout.core.domain.model.filter.Filter.create(
|
||||||
id = FilterId(idGenerateService.generateId()),
|
id = FilterId(idGenerateService.generateId()),
|
||||||
userDetailId = command.userDetailId,
|
userDetailId = principal.userDetailId,
|
||||||
name = FilterName(command.filterName),
|
name = FilterName(command.filterName),
|
||||||
filterContext = command.filterContext,
|
filterContext = command.filterContext,
|
||||||
filterAction = command.filterAction,
|
filterAction = command.filterAction,
|
||||||
|
|
|
@ -19,7 +19,6 @@ package dev.usbharu.hideout.core.application.post
|
||||||
import dev.usbharu.hideout.core.domain.model.post.Visibility
|
import dev.usbharu.hideout.core.domain.model.post.Visibility
|
||||||
|
|
||||||
data class RegisterLocalPost(
|
data class RegisterLocalPost(
|
||||||
val userDetailId: Long,
|
|
||||||
val content: String,
|
val content: String,
|
||||||
val overview: String?,
|
val overview: String?,
|
||||||
val visibility: Visibility,
|
val visibility: Visibility,
|
||||||
|
|
|
@ -16,15 +16,14 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.application.post
|
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.application.shared.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
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.media.MediaId
|
||||||
import dev.usbharu.hideout.core.domain.model.post.PostId
|
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.PostOverview
|
||||||
import dev.usbharu.hideout.core.domain.model.post.PostRepository
|
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.support.principal.FromApi
|
||||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
|
||||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
|
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
|
||||||
import dev.usbharu.hideout.core.infrastructure.factory.PostFactoryImpl
|
import dev.usbharu.hideout.core.infrastructure.factory.PostFactoryImpl
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
|
@ -38,11 +37,11 @@ class RegisterLocalPostApplicationService(
|
||||||
private val postRepository: PostRepository,
|
private val postRepository: PostRepository,
|
||||||
private val userDetailRepository: UserDetailRepository,
|
private val userDetailRepository: UserDetailRepository,
|
||||||
transaction: Transaction,
|
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 = (
|
val actorId = (
|
||||||
userDetailRepository.findById(UserDetailId(command.userDetailId))
|
userDetailRepository.findById(principal.userDetailId)
|
||||||
?: throw IllegalStateException("actor not found")
|
?: throw IllegalStateException("actor not found")
|
||||||
).actorId
|
).actorId
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,4 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.application.relationship.acceptfollowrequest
|
package dev.usbharu.hideout.core.application.relationship.acceptfollowrequest
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
data class AcceptFollowRequest(val sourceActorId: Long)
|
||||||
|
|
||||||
data class AcceptFollowRequest(val sourceActorId: Long, val userDetailId: UserDetailId)
|
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
package dev.usbharu.hideout.core.application.relationship.acceptfollowrequest
|
package dev.usbharu.hideout.core.application.relationship.acceptfollowrequest
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService
|
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.application.shared.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
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.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
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.model.userdetails.UserDetailRepository
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -34,10 +34,10 @@ class UserAcceptFollowRequestApplicationService(
|
||||||
private val actorRepository: ActorRepository,
|
private val actorRepository: ActorRepository,
|
||||||
private val userDetailRepository: UserDetailRepository,
|
private val userDetailRepository: UserDetailRepository,
|
||||||
) :
|
) :
|
||||||
AbstractApplicationService<AcceptFollowRequest, Unit>(transaction, logger) {
|
LocalUserAbstractApplicationService<AcceptFollowRequest, Unit>(transaction, logger) {
|
||||||
override suspend fun internalExecute(command: AcceptFollowRequest, principal: Principal) {
|
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 actor = actorRepository.findById(userDetail.actorId)!!
|
||||||
|
|
||||||
val targetId = ActorId(command.sourceActorId)
|
val targetId = ActorId(command.sourceActorId)
|
||||||
|
|
|
@ -16,6 +16,4 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.application.relationship.block
|
package dev.usbharu.hideout.core.application.relationship.block
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
data class Block(val targetActorId: Long)
|
||||||
|
|
||||||
data class Block(val targetActorId: Long, val userDetailId: UserDetailId)
|
|
||||||
|
|
|
@ -16,13 +16,13 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.application.relationship.block
|
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.application.shared.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
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.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
|
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.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.model.userdetails.UserDetailRepository
|
||||||
import dev.usbharu.hideout.core.domain.service.relationship.RelationshipDomainService
|
import dev.usbharu.hideout.core.domain.service.relationship.RelationshipDomainService
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
@ -36,10 +36,10 @@ class UserBlockApplicationService(
|
||||||
private val userDetailRepository: UserDetailRepository,
|
private val userDetailRepository: UserDetailRepository,
|
||||||
private val relationshipDomainService: RelationshipDomainService,
|
private val relationshipDomainService: RelationshipDomainService,
|
||||||
) :
|
) :
|
||||||
AbstractApplicationService<Block, Unit>(transaction, logger) {
|
LocalUserAbstractApplicationService<Block, Unit>(transaction, logger) {
|
||||||
override suspend fun internalExecute(command: Block, principal: Principal) {
|
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 actor = actorRepository.findById(userDetail.actorId)!!
|
||||||
|
|
||||||
val targetId = ActorId(command.targetActorId)
|
val targetId = ActorId(command.targetActorId)
|
||||||
|
|
|
@ -16,6 +16,4 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.application.relationship.followrequest
|
package dev.usbharu.hideout.core.application.relationship.followrequest
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
data class FollowRequest(val targetActorId: Long)
|
||||||
|
|
||||||
data class FollowRequest(val targetActorId: Long, val userDetailId: UserDetailId)
|
|
||||||
|
|
|
@ -16,13 +16,13 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.application.relationship.followrequest
|
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.application.shared.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
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.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
|
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.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.model.userdetails.UserDetailRepository
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -33,14 +33,14 @@ class UserFollowRequestApplicationService(
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
private val actorRepository: ActorRepository,
|
private val actorRepository: ActorRepository,
|
||||||
private val userDetailRepository: UserDetailRepository,
|
private val userDetailRepository: UserDetailRepository,
|
||||||
) : AbstractApplicationService<FollowRequest, Unit>(
|
) : LocalUserAbstractApplicationService<FollowRequest, Unit>(
|
||||||
transaction,
|
transaction,
|
||||||
logger
|
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 actor = actorRepository.findById(userDetail.actorId)!!
|
||||||
|
|
||||||
val targetId = ActorId(command.targetActorId)
|
val targetId = ActorId(command.targetActorId)
|
||||||
|
|
|
@ -16,6 +16,4 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.application.relationship.get
|
package dev.usbharu.hideout.core.application.relationship.get
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
data class GetRelationship(val targetActorId: Long)
|
||||||
|
|
||||||
data class GetRelationship(val targetActorId: Long, val userDetailId: UserDetailId)
|
|
||||||
|
|
|
@ -16,14 +16,14 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.application.relationship.get
|
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.application.shared.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
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.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.actorinstancerelationship.ActorInstanceRelationship
|
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.actorinstancerelationship.ActorInstanceRelationshipRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
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.model.userdetails.UserDetailRepository
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -36,12 +36,12 @@ class GetRelationshipApplicationService(
|
||||||
private val actorInstanceRelationshipRepository: ActorInstanceRelationshipRepository,
|
private val actorInstanceRelationshipRepository: ActorInstanceRelationshipRepository,
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
) :
|
) :
|
||||||
AbstractApplicationService<GetRelationship, Relationship>(
|
LocalUserAbstractApplicationService<GetRelationship, Relationship>(
|
||||||
transaction,
|
transaction,
|
||||||
logger
|
logger
|
||||||
) {
|
) {
|
||||||
override suspend fun internalExecute(command: GetRelationship, principal: Principal): Relationship {
|
override suspend fun internalExecute(command: GetRelationship, principal: FromApi): Relationship {
|
||||||
val userDetail = userDetailRepository.findById(command.userDetailId)!!
|
val userDetail = userDetailRepository.findById(principal.userDetailId)!!
|
||||||
val actor = actorRepository.findById(userDetail.actorId)!!
|
val actor = actorRepository.findById(userDetail.actorId)!!
|
||||||
val targetId = ActorId(command.targetActorId)
|
val targetId = ActorId(command.targetActorId)
|
||||||
val target = actorRepository.findById(targetId)!!
|
val target = actorRepository.findById(targetId)!!
|
||||||
|
|
|
@ -16,6 +16,4 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.application.relationship.mute
|
package dev.usbharu.hideout.core.application.relationship.mute
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
data class Mute(val targetActorId: Long)
|
||||||
|
|
||||||
data class Mute(val targetActorId: Long, val userDetailId: UserDetailId)
|
|
||||||
|
|
|
@ -17,13 +17,13 @@
|
||||||
package dev.usbharu.hideout.core.application.relationship.mute
|
package dev.usbharu.hideout.core.application.relationship.mute
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService
|
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.application.shared.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
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.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
|
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.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.model.userdetails.UserDetailRepository
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -35,10 +35,10 @@ class UserMuteApplicationService(
|
||||||
private val actorRepository: ActorRepository,
|
private val actorRepository: ActorRepository,
|
||||||
private val userDetailRepository: UserDetailRepository,
|
private val userDetailRepository: UserDetailRepository,
|
||||||
) :
|
) :
|
||||||
AbstractApplicationService<Mute, Unit>(transaction, logger) {
|
LocalUserAbstractApplicationService<Mute, Unit>(transaction, logger) {
|
||||||
override suspend fun internalExecute(command: Mute, principal: Principal) {
|
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 actor = actorRepository.findById(userDetail.actorId)!!
|
||||||
|
|
||||||
val targetId = ActorId(command.targetActorId)
|
val targetId = ActorId(command.targetActorId)
|
||||||
|
|
|
@ -16,6 +16,4 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.application.relationship.rejectfollowrequest
|
package dev.usbharu.hideout.core.application.relationship.rejectfollowrequest
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
data class RejectFollowRequest(val sourceActorId: Long)
|
||||||
|
|
||||||
data class RejectFollowRequest(val sourceActorId: Long, val userDetailId: UserDetailId)
|
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
package dev.usbharu.hideout.core.application.relationship.rejectfollowrequest
|
package dev.usbharu.hideout.core.application.relationship.rejectfollowrequest
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService
|
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.application.shared.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
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.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
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.model.userdetails.UserDetailRepository
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -34,10 +34,10 @@ class UserRejectFollowRequestApplicationService(
|
||||||
private val actorRepository: ActorRepository,
|
private val actorRepository: ActorRepository,
|
||||||
private val userDetailRepository: UserDetailRepository,
|
private val userDetailRepository: UserDetailRepository,
|
||||||
) :
|
) :
|
||||||
AbstractApplicationService<RejectFollowRequest, Unit>(transaction, logger) {
|
LocalUserAbstractApplicationService<RejectFollowRequest, Unit>(transaction, logger) {
|
||||||
override suspend fun internalExecute(command: RejectFollowRequest, principal: Principal) {
|
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 actor = actorRepository.findById(userDetail.actorId)!!
|
||||||
|
|
||||||
val targetId = ActorId(command.sourceActorId)
|
val targetId = ActorId(command.sourceActorId)
|
||||||
|
|
|
@ -16,4 +16,4 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.application.relationship.removefromfollowers
|
package dev.usbharu.hideout.core.application.relationship.removefromfollowers
|
||||||
|
|
||||||
data class RemoveFromFollowers(val targetActorId: Long, val userDetailId: Long)
|
data class RemoveFromFollowers(val targetActorId: Long)
|
||||||
|
|
|
@ -17,14 +17,13 @@
|
||||||
package dev.usbharu.hideout.core.application.relationship.removefromfollowers
|
package dev.usbharu.hideout.core.application.relationship.removefromfollowers
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService
|
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.application.shared.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
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.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
|
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.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.UserDetailId
|
|
||||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
|
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -36,10 +35,10 @@ class UserRemoveFromFollowersApplicationService(
|
||||||
private val actorRepository: ActorRepository,
|
private val actorRepository: ActorRepository,
|
||||||
private val userDetailRepository: UserDetailRepository,
|
private val userDetailRepository: UserDetailRepository,
|
||||||
) :
|
) :
|
||||||
AbstractApplicationService<RemoveFromFollowers, Unit>(transaction, logger) {
|
LocalUserAbstractApplicationService<RemoveFromFollowers, Unit>(transaction, logger) {
|
||||||
override suspend fun internalExecute(command: RemoveFromFollowers, principal: Principal) {
|
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 actor = actorRepository.findById(userDetail.actorId)!!
|
||||||
|
|
||||||
val targetId = ActorId(command.targetActorId)
|
val targetId = ActorId(command.targetActorId)
|
||||||
|
|
|
@ -16,6 +16,4 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.application.relationship.unblock
|
package dev.usbharu.hideout.core.application.relationship.unblock
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
data class Unblock(val targetActorId: Long)
|
||||||
|
|
||||||
data class Unblock(val targetActorId: Long, val userDetailId: UserDetailId)
|
|
||||||
|
|
|
@ -17,13 +17,13 @@
|
||||||
package dev.usbharu.hideout.core.application.relationship.unblock
|
package dev.usbharu.hideout.core.application.relationship.unblock
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService
|
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.application.shared.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
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.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
|
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.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.model.userdetails.UserDetailRepository
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -35,10 +35,10 @@ class UserUnblockApplicationService(
|
||||||
private val actorRepository: ActorRepository,
|
private val actorRepository: ActorRepository,
|
||||||
private val userDetailRepository: UserDetailRepository,
|
private val userDetailRepository: UserDetailRepository,
|
||||||
) :
|
) :
|
||||||
AbstractApplicationService<Unblock, Unit>(transaction, logger) {
|
LocalUserAbstractApplicationService<Unblock, Unit>(transaction, logger) {
|
||||||
override suspend fun internalExecute(command: Unblock, principal: Principal) {
|
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 actor = actorRepository.findById(userDetail.actorId)!!
|
||||||
|
|
||||||
val targetId = ActorId(command.targetActorId)
|
val targetId = ActorId(command.targetActorId)
|
||||||
|
|
|
@ -16,6 +16,4 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.application.relationship.unfollow
|
package dev.usbharu.hideout.core.application.relationship.unfollow
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
data class Unfollow(val targetActorId: Long)
|
||||||
|
|
||||||
data class Unfollow(val targetActorId: Long, val userDetailId: UserDetailId)
|
|
||||||
|
|
|
@ -17,13 +17,13 @@
|
||||||
package dev.usbharu.hideout.core.application.relationship.unfollow
|
package dev.usbharu.hideout.core.application.relationship.unfollow
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService
|
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.application.shared.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
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.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
|
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.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.model.userdetails.UserDetailRepository
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -35,10 +35,10 @@ class UserUnfollowApplicationService(
|
||||||
private val actorRepository: ActorRepository,
|
private val actorRepository: ActorRepository,
|
||||||
private val userDetailRepository: UserDetailRepository,
|
private val userDetailRepository: UserDetailRepository,
|
||||||
) :
|
) :
|
||||||
AbstractApplicationService<Unfollow, Unit>(transaction, logger) {
|
LocalUserAbstractApplicationService<Unfollow, Unit>(transaction, logger) {
|
||||||
override suspend fun internalExecute(command: Unfollow, principal: Principal) {
|
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 actor = actorRepository.findById(userDetail.actorId)!!
|
||||||
|
|
||||||
val targetId = ActorId(command.targetActorId)
|
val targetId = ActorId(command.targetActorId)
|
||||||
|
|
|
@ -16,6 +16,4 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.application.relationship.unmute
|
package dev.usbharu.hideout.core.application.relationship.unmute
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
data class Unmute(val targetActorId: Long)
|
||||||
|
|
||||||
data class Unmute(val targetActorId: Long, val userDetailId: UserDetailId)
|
|
||||||
|
|
|
@ -17,13 +17,13 @@
|
||||||
package dev.usbharu.hideout.core.application.relationship.unmute
|
package dev.usbharu.hideout.core.application.relationship.unmute
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.application.relationship.block.UserBlockApplicationService
|
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.application.shared.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
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.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
|
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.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.model.userdetails.UserDetailRepository
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -35,14 +35,14 @@ class UserUnmuteApplicationService(
|
||||||
private val actorRepository: ActorRepository,
|
private val actorRepository: ActorRepository,
|
||||||
private val userDetailRepository: UserDetailRepository,
|
private val userDetailRepository: UserDetailRepository,
|
||||||
) :
|
) :
|
||||||
AbstractApplicationService<Unmute, Unit>(transaction, logger) {
|
LocalUserAbstractApplicationService<Unmute, Unit>(transaction, logger) {
|
||||||
companion object {
|
companion object {
|
||||||
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
|
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 actor = actorRepository.findById(userDetail.actorId)!!
|
||||||
|
|
||||||
val targetId = ActorId(command.targetActorId)
|
val targetId = ActorId(command.targetActorId)
|
||||||
|
|
|
@ -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
|
|
|
@ -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.support.acct.Acct
|
||||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
||||||
|
|
||||||
class FromApi(actorId: ActorId, override val userDetailId: UserDetailId, override val acct: Acct) : Principal(
|
class FromApi(
|
||||||
actorId, userDetailId,
|
actorId: ActorId,
|
||||||
|
override val userDetailId: UserDetailId,
|
||||||
|
override val acct: Acct
|
||||||
|
) : Principal(
|
||||||
|
actorId,
|
||||||
|
userDetailId,
|
||||||
acct
|
acct
|
||||||
)
|
)
|
|
@ -0,0 +1,5 @@
|
||||||
|
package dev.usbharu.hideout.core.domain.model.support.principal
|
||||||
|
|
||||||
|
interface PrincipalContextHolder {
|
||||||
|
suspend fun getPrincipal(): Principal
|
||||||
|
}
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -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()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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')"
|
|
||||||
}
|
|
|
@ -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())
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
|
|
|
@ -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()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.RegisterLocalActor
|
||||||
import dev.usbharu.hideout.core.application.actor.RegisterLocalActorApplicationService
|
import dev.usbharu.hideout.core.application.actor.RegisterLocalActorApplicationService
|
||||||
import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous
|
import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous
|
||||||
import dev.usbharu.hideout.core.infrastructure.springframework.SpringMvcCommandExecutorFactory
|
|
||||||
import jakarta.servlet.http.HttpServletRequest
|
import jakarta.servlet.http.HttpServletRequest
|
||||||
import org.springframework.stereotype.Controller
|
import org.springframework.stereotype.Controller
|
||||||
import org.springframework.validation.annotation.Validated
|
import org.springframework.validation.annotation.Validated
|
||||||
|
@ -30,7 +29,6 @@ import org.springframework.web.bind.annotation.PostMapping
|
||||||
@Controller
|
@Controller
|
||||||
class AuthController(
|
class AuthController(
|
||||||
private val registerLocalActorApplicationService: RegisterLocalActorApplicationService,
|
private val registerLocalActorApplicationService: RegisterLocalActorApplicationService,
|
||||||
private val springMvcCommandExecutorFactory: SpringMvcCommandExecutorFactory,
|
|
||||||
) {
|
) {
|
||||||
@GetMapping("/auth/sign_up")
|
@GetMapping("/auth/sign_up")
|
||||||
@Suppress("FunctionOnlyReturningConstant")
|
@Suppress("FunctionOnlyReturningConstant")
|
||||||
|
|
|
@ -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)
|
|
@ -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
|
||||||
|
}
|
|
@ -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.unfollow.UserUnfollowApplicationService
|
||||||
import dev.usbharu.hideout.core.application.relationship.unmute.Unmute
|
import dev.usbharu.hideout.core.application.relationship.unmute.Unmute
|
||||||
import dev.usbharu.hideout.core.application.relationship.unmute.UserUnmuteApplicationService
|
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.SpringSecurityOauth2PrincipalContextHolder
|
||||||
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.Oauth2CommandExecutorFactory
|
|
||||||
import dev.usbharu.hideout.mastodon.application.accounts.GetAccount
|
import dev.usbharu.hideout.mastodon.application.accounts.GetAccount
|
||||||
import dev.usbharu.hideout.mastodon.application.accounts.GetAccountApplicationService
|
import dev.usbharu.hideout.mastodon.application.accounts.GetAccountApplicationService
|
||||||
import dev.usbharu.hideout.mastodon.interfaces.api.generated.AccountApi
|
import dev.usbharu.hideout.mastodon.interfaces.api.generated.AccountApi
|
||||||
|
@ -49,7 +48,6 @@ import org.springframework.stereotype.Controller
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
class SpringAccountApi(
|
class SpringAccountApi(
|
||||||
private val oauth2CommandExecutorFactory: Oauth2CommandExecutorFactory,
|
|
||||||
private val getUserDetailApplicationService: GetUserDetailApplicationService,
|
private val getUserDetailApplicationService: GetUserDetailApplicationService,
|
||||||
private val getAccountApplicationService: GetAccountApplicationService,
|
private val getAccountApplicationService: GetAccountApplicationService,
|
||||||
private val userFollowRequestApplicationService: UserFollowRequestApplicationService,
|
private val userFollowRequestApplicationService: UserFollowRequestApplicationService,
|
||||||
|
@ -62,31 +60,33 @@ class SpringAccountApi(
|
||||||
private val userRejectFollowRequestApplicationService: UserRejectFollowRequestApplicationService,
|
private val userRejectFollowRequestApplicationService: UserRejectFollowRequestApplicationService,
|
||||||
private val userRemoveFromFollowersApplicationService: UserRemoveFromFollowersApplicationService,
|
private val userRemoveFromFollowersApplicationService: UserRemoveFromFollowersApplicationService,
|
||||||
private val userUnfollowApplicationService: UserUnfollowApplicationService,
|
private val userUnfollowApplicationService: UserUnfollowApplicationService,
|
||||||
|
private val principalContextHolder: SpringSecurityOauth2PrincipalContextHolder
|
||||||
) : AccountApi {
|
) : AccountApi {
|
||||||
|
|
||||||
|
|
||||||
override suspend fun apiV1AccountsIdBlockPost(id: String): ResponseEntity<Relationship> {
|
override suspend fun apiV1AccountsIdBlockPost(id: String): ResponseEntity<Relationship> {
|
||||||
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
|
userBlockApplicationService.execute(Block(id.toLong()), principalContextHolder.getPrincipal())
|
||||||
userBlockApplicationService.execute(Block(id.toLong()))
|
return fetchRelationship(id)
|
||||||
return fetchRelationship(id, executor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV1AccountsIdFollowPost(
|
override suspend fun apiV1AccountsIdFollowPost(
|
||||||
id: String,
|
id: String,
|
||||||
followRequestBody: FollowRequestBody?,
|
followRequestBody: FollowRequestBody?,
|
||||||
): ResponseEntity<Relationship> {
|
): ResponseEntity<Relationship> {
|
||||||
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
|
|
||||||
userFollowRequestApplicationService.execute(
|
userFollowRequestApplicationService.execute(
|
||||||
FollowRequest(id.toLong())
|
FollowRequest(id.toLong()), principalContextHolder.getPrincipal()
|
||||||
)
|
)
|
||||||
return fetchRelationship(id, executor)
|
return fetchRelationship(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun fetchRelationship(
|
private suspend fun fetchRelationship(
|
||||||
id: String,
|
id: String,
|
||||||
executor: Oauth2CommandExecutor,
|
|
||||||
): ResponseEntity<Relationship> {
|
): ResponseEntity<Relationship> {
|
||||||
val relationship = getRelationshipApplicationService.execute(GetRelationship(id.toLong()))
|
val relationship = getRelationshipApplicationService.execute(
|
||||||
|
GetRelationship(id.toLong()),
|
||||||
|
principalContextHolder.getPrincipal()
|
||||||
|
)
|
||||||
return ResponseEntity.ok(
|
return ResponseEntity.ok(
|
||||||
Relationship(
|
Relationship(
|
||||||
id = relationship.targetId.toString(),
|
id = relationship.targetId.toString(),
|
||||||
|
@ -109,49 +109,44 @@ class SpringAccountApi(
|
||||||
override suspend fun apiV1AccountsIdGet(id: String): ResponseEntity<Account> {
|
override suspend fun apiV1AccountsIdGet(id: String): ResponseEntity<Account> {
|
||||||
return ResponseEntity.ok(
|
return ResponseEntity.ok(
|
||||||
getAccountApplicationService.execute(
|
getAccountApplicationService.execute(
|
||||||
GetAccount(id)
|
GetAccount(id), principalContextHolder.getPrincipal()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV1AccountsIdMutePost(id: String): ResponseEntity<Relationship> {
|
override suspend fun apiV1AccountsIdMutePost(id: String): ResponseEntity<Relationship> {
|
||||||
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
|
|
||||||
userMuteApplicationService.execute(
|
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> {
|
override suspend fun apiV1AccountsIdRemoveFromFollowersPost(id: String): ResponseEntity<Relationship> {
|
||||||
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
|
|
||||||
userRemoveFromFollowersApplicationService.execute(
|
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> {
|
override suspend fun apiV1AccountsIdUnblockPost(id: String): ResponseEntity<Relationship> {
|
||||||
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
|
|
||||||
userUnblockApplicationService.execute(
|
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> {
|
override suspend fun apiV1AccountsIdUnfollowPost(id: String): ResponseEntity<Relationship> {
|
||||||
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
|
|
||||||
userUnfollowApplicationService.execute(
|
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> {
|
override suspend fun apiV1AccountsIdUnmutePost(id: String): ResponseEntity<Relationship> {
|
||||||
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
|
|
||||||
userUnmuteApplicationService.execute(
|
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> {
|
override suspend fun apiV1AccountsPost(accountsCreateRequest: AccountsCreateRequest): ResponseEntity<Unit> {
|
||||||
|
@ -163,9 +158,9 @@ class SpringAccountApi(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV1AccountsVerifyCredentialsGet(): ResponseEntity<CredentialAccount> {
|
override suspend fun apiV1AccountsVerifyCredentialsGet(): ResponseEntity<CredentialAccount> {
|
||||||
val commandExecutor = oauth2CommandExecutorFactory.getCommandExecutor()
|
val principal = principalContextHolder.getPrincipal()
|
||||||
val localActor =
|
val localActor =
|
||||||
getUserDetailApplicationService.execute(GetUserDetail(commandExecutor.userDetailId))
|
getUserDetailApplicationService.execute(GetUserDetail(principal.userDetailId.id), principal)
|
||||||
|
|
||||||
return ResponseEntity.ok(
|
return ResponseEntity.ok(
|
||||||
CredentialAccount(
|
CredentialAccount(
|
||||||
|
@ -215,19 +210,19 @@ class SpringAccountApi(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV1FollowRequestsAccountIdAuthorizePost(accountId: String): ResponseEntity<Relationship> {
|
override suspend fun apiV1FollowRequestsAccountIdAuthorizePost(accountId: String): ResponseEntity<Relationship> {
|
||||||
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
|
|
||||||
userAcceptFollowRequestApplicationService.execute(
|
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> {
|
override suspend fun apiV1FollowRequestsAccountIdRejectPost(accountId: String): ResponseEntity<Relationship> {
|
||||||
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
|
|
||||||
userRejectFollowRequestApplicationService.execute(
|
userRejectFollowRequestApplicationService.execute(
|
||||||
RejectFollowRequest(accountId.toLong())
|
RejectFollowRequest(accountId.toLong()), principalContextHolder.getPrincipal()
|
||||||
)
|
)
|
||||||
return fetchRelationship(accountId, executor)
|
return fetchRelationship(accountId)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -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.FilterAction
|
||||||
import dev.usbharu.hideout.core.domain.model.filter.FilterContext
|
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.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.DeleteFilterV1
|
||||||
import dev.usbharu.hideout.mastodon.application.filter.DeleteFilterV1ApplicationService
|
import dev.usbharu.hideout.mastodon.application.filter.DeleteFilterV1ApplicationService
|
||||||
import dev.usbharu.hideout.mastodon.application.filter.GetFilterV1
|
import dev.usbharu.hideout.mastodon.application.filter.GetFilterV1
|
||||||
|
@ -36,18 +36,18 @@ import org.springframework.stereotype.Controller
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
class SpringFilterApi(
|
class SpringFilterApi(
|
||||||
private val oauth2CommandExecutorFactory: Oauth2CommandExecutorFactory,
|
|
||||||
private val userRegisterFilterApplicationService: UserRegisterFilterApplicationService,
|
private val userRegisterFilterApplicationService: UserRegisterFilterApplicationService,
|
||||||
private val getFilterV1ApplicationService: GetFilterV1ApplicationService,
|
private val getFilterV1ApplicationService: GetFilterV1ApplicationService,
|
||||||
private val deleteFilterV1ApplicationService: DeleteFilterV1ApplicationService,
|
private val deleteFilterV1ApplicationService: DeleteFilterV1ApplicationService,
|
||||||
private val userDeleteFilterApplicationService: UserDeleteFilterApplicationService,
|
private val userDeleteFilterApplicationService: UserDeleteFilterApplicationService,
|
||||||
private val userGetFilterApplicationService: UserGetFilterApplicationService,
|
private val userGetFilterApplicationService: UserGetFilterApplicationService,
|
||||||
|
private val principalContextHolder: PrincipalContextHolder
|
||||||
) : FilterApi {
|
) : FilterApi {
|
||||||
|
|
||||||
override suspend fun apiV1FiltersIdDelete(id: String): ResponseEntity<Any> {
|
override suspend fun apiV1FiltersIdDelete(id: String): ResponseEntity<Any> {
|
||||||
return ResponseEntity.ok(
|
return ResponseEntity.ok(
|
||||||
deleteFilterV1ApplicationService.execute(
|
deleteFilterV1ApplicationService.execute(
|
||||||
DeleteFilterV1(id.toLong())
|
DeleteFilterV1(id.toLong()), principalContextHolder.getPrincipal()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ class SpringFilterApi(
|
||||||
override suspend fun apiV1FiltersIdGet(id: String): ResponseEntity<V1Filter> {
|
override suspend fun apiV1FiltersIdGet(id: String): ResponseEntity<V1Filter> {
|
||||||
return ResponseEntity.ok(
|
return ResponseEntity.ok(
|
||||||
getFilterV1ApplicationService.execute(
|
getFilterV1ApplicationService.execute(
|
||||||
GetFilterV1(id.toLong())
|
GetFilterV1(id.toLong()), principalContextHolder.getPrincipal()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ class SpringFilterApi(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV1FiltersPost(v1FilterPostRequest: V1FilterPostRequest): ResponseEntity<V1Filter> {
|
override suspend fun apiV1FiltersPost(v1FilterPostRequest: V1FilterPostRequest): ResponseEntity<V1Filter> {
|
||||||
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
|
|
||||||
val filterMode = if (v1FilterPostRequest.wholeWord == true) {
|
val filterMode = if (v1FilterPostRequest.wholeWord == true) {
|
||||||
FilterMode.WHOLE_WORD
|
FilterMode.WHOLE_WORD
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,11 +91,11 @@ class SpringFilterApi(
|
||||||
RegisterFilter(
|
RegisterFilter(
|
||||||
v1FilterPostRequest.phrase, filterContext, FilterAction.WARN,
|
v1FilterPostRequest.phrase, filterContext, FilterAction.WARN,
|
||||||
setOf(RegisterFilterKeyword(v1FilterPostRequest.phrase, filterMode))
|
setOf(RegisterFilterKeyword(v1FilterPostRequest.phrase, filterMode))
|
||||||
)
|
), principalContextHolder.getPrincipal()
|
||||||
)
|
)
|
||||||
return ResponseEntity.ok(
|
return ResponseEntity.ok(
|
||||||
getFilterV1ApplicationService.execute(
|
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> {
|
override suspend fun apiV2FiltersIdDelete(id: String): ResponseEntity<Any> {
|
||||||
userDeleteFilterApplicationService.execute(
|
userDeleteFilterApplicationService.execute(
|
||||||
DeleteFilter(id.toLong())
|
DeleteFilter(id.toLong()), principalContextHolder.getPrincipal()
|
||||||
)
|
)
|
||||||
return ResponseEntity.ok(Unit)
|
return ResponseEntity.ok(Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV2FiltersIdGet(id: String): ResponseEntity<Filter> {
|
override suspend fun apiV2FiltersIdGet(id: String): ResponseEntity<Filter> {
|
||||||
val filter = userGetFilterApplicationService.execute(
|
val filter = userGetFilterApplicationService.execute(
|
||||||
GetFilter(id.toLong())
|
GetFilter(id.toLong()), principalContextHolder.getPrincipal()
|
||||||
)
|
)
|
||||||
return ResponseEntity.ok(
|
return ResponseEntity.ok(
|
||||||
filter(filter)
|
filter(filter)
|
||||||
|
@ -186,7 +186,7 @@ class SpringFilterApi(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV2FiltersPost(filterPostRequest: FilterPostRequest): ResponseEntity<Filter> {
|
override suspend fun apiV2FiltersPost(filterPostRequest: FilterPostRequest): ResponseEntity<Filter> {
|
||||||
val executor = oauth2CommandExecutorFactory.getCommandExecutor()
|
|
||||||
val filter = userRegisterFilterApplicationService.execute(
|
val filter = userRegisterFilterApplicationService.execute(
|
||||||
RegisterFilter(
|
RegisterFilter(
|
||||||
filterName = filterPostRequest.title,
|
filterName = filterPostRequest.title,
|
||||||
|
@ -216,7 +216,7 @@ class SpringFilterApi(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}.toSet()
|
}.toSet()
|
||||||
)
|
), principalContextHolder.getPrincipal()
|
||||||
)
|
)
|
||||||
return ResponseEntity.ok(filter(filter))
|
return ResponseEntity.ok(filter(filter))
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.UploadMedia
|
||||||
import dev.usbharu.hideout.core.application.media.UploadMediaApplicationService
|
import dev.usbharu.hideout.core.application.media.UploadMediaApplicationService
|
||||||
import dev.usbharu.hideout.core.domain.model.media.FileType.*
|
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.MediaApi
|
||||||
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.MediaAttachment
|
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.MediaAttachment
|
||||||
import org.springframework.http.ResponseEntity
|
import org.springframework.http.ResponseEntity
|
||||||
|
@ -30,7 +30,7 @@ import java.nio.file.Files
|
||||||
@Controller
|
@Controller
|
||||||
class SpringMediaApi(
|
class SpringMediaApi(
|
||||||
private val uploadMediaApplicationService: UploadMediaApplicationService,
|
private val uploadMediaApplicationService: UploadMediaApplicationService,
|
||||||
private val oauth2CommandExecutorFactory: Oauth2CommandExecutorFactory
|
private val principalContextHolder: PrincipalContextHolder
|
||||||
) : MediaApi {
|
) : MediaApi {
|
||||||
override suspend fun apiV1MediaPost(
|
override suspend fun apiV1MediaPost(
|
||||||
file: MultipartFile,
|
file: MultipartFile,
|
||||||
|
@ -52,7 +52,7 @@ class SpringMediaApi(
|
||||||
file.originalFilename ?: file.name,
|
file.originalFilename ?: file.name,
|
||||||
null,
|
null,
|
||||||
description
|
description
|
||||||
)
|
), principalContextHolder.getPrincipal()
|
||||||
)
|
)
|
||||||
|
|
||||||
return ResponseEntity.ok(
|
return ResponseEntity.ok(
|
||||||
|
|
|
@ -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.RegisterLocalPost
|
||||||
import dev.usbharu.hideout.core.application.post.RegisterLocalPostApplicationService
|
import dev.usbharu.hideout.core.application.post.RegisterLocalPostApplicationService
|
||||||
import dev.usbharu.hideout.core.domain.model.post.Visibility
|
import dev.usbharu.hideout.core.domain.model.post.Visibility
|
||||||
import dev.usbharu.hideout.core.infrastructure.springframework.DelegateCommandExecutorFactory
|
import dev.usbharu.hideout.core.domain.model.support.principal.PrincipalContextHolder
|
||||||
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.Oauth2CommandExecutor
|
|
||||||
import dev.usbharu.hideout.mastodon.application.status.GetStatus
|
import dev.usbharu.hideout.mastodon.application.status.GetStatus
|
||||||
import dev.usbharu.hideout.mastodon.application.status.GetStatusApplicationService
|
import dev.usbharu.hideout.mastodon.application.status.GetStatusApplicationService
|
||||||
import dev.usbharu.hideout.mastodon.interfaces.api.generated.StatusApi
|
import dev.usbharu.hideout.mastodon.interfaces.api.generated.StatusApi
|
||||||
|
@ -32,9 +31,9 @@ import org.springframework.stereotype.Controller
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
class SpringStatusApi(
|
class SpringStatusApi(
|
||||||
private val delegateCommandExecutorFactory: DelegateCommandExecutorFactory,
|
|
||||||
private val registerLocalPostApplicationService: RegisterLocalPostApplicationService,
|
private val registerLocalPostApplicationService: RegisterLocalPostApplicationService,
|
||||||
private val getStatusApplicationService: GetStatusApplicationService,
|
private val getStatusApplicationService: GetStatusApplicationService,
|
||||||
|
private val principalContextHolder: PrincipalContextHolder
|
||||||
) : StatusApi {
|
) : StatusApi {
|
||||||
override suspend fun apiV1StatusesIdEmojiReactionsEmojiDelete(id: String, emoji: String): ResponseEntity<Status> {
|
override suspend fun apiV1StatusesIdEmojiReactionsEmojiDelete(id: String, emoji: String): ResponseEntity<Status> {
|
||||||
return super.apiV1StatusesIdEmojiReactionsEmojiDelete(id, emoji)
|
return super.apiV1StatusesIdEmojiReactionsEmojiDelete(id, emoji)
|
||||||
|
@ -48,16 +47,15 @@ class SpringStatusApi(
|
||||||
|
|
||||||
return ResponseEntity.ok(
|
return ResponseEntity.ok(
|
||||||
getStatusApplicationService.execute(
|
getStatusApplicationService.execute(
|
||||||
GetStatus(id)
|
GetStatus(id), principalContextHolder.getPrincipal()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV1StatusesPost(statusesRequest: StatusesRequest): ResponseEntity<Status> {
|
override suspend fun apiV1StatusesPost(statusesRequest: StatusesRequest): ResponseEntity<Status> {
|
||||||
val executor = delegateCommandExecutorFactory.getCommandExecutor() as Oauth2CommandExecutor
|
|
||||||
val execute = registerLocalPostApplicationService.execute(
|
val execute = registerLocalPostApplicationService.execute(
|
||||||
RegisterLocalPost(
|
RegisterLocalPost(
|
||||||
userDetailId = executor.userDetailId,
|
|
||||||
content = statusesRequest.status.orEmpty(),
|
content = statusesRequest.status.orEmpty(),
|
||||||
overview = statusesRequest.spoilerText,
|
overview = statusesRequest.spoilerText,
|
||||||
visibility = when (statusesRequest.visibility) {
|
visibility = when (statusesRequest.visibility) {
|
||||||
|
@ -71,11 +69,12 @@ class SpringStatusApi(
|
||||||
replyId = statusesRequest.inReplyToId?.toLong(),
|
replyId = statusesRequest.inReplyToId?.toLong(),
|
||||||
sensitive = statusesRequest.sensitive == true,
|
sensitive = statusesRequest.sensitive == true,
|
||||||
mediaIds = statusesRequest.mediaIds.orEmpty().map { it.toLong() }
|
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(
|
return ResponseEntity.ok(
|
||||||
status
|
status
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue