feat: 多少の改善にはなっただろうか

This commit is contained in:
usbharu 2024-08-06 00:04:32 +09:00
parent 884983f3e4
commit f5fc4fd0ee
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
37 changed files with 118 additions and 36 deletions

View File

@ -20,6 +20,7 @@ import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.emoji.CustomEmojiRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
@ -33,7 +34,7 @@ class GetUserDetailApplicationService(
transaction: Transaction,
) :
AbstractApplicationService<GetUserDetail, UserDetail>(transaction, Companion.logger) {
override suspend fun internalExecute(command: GetUserDetail): UserDetail {
override suspend fun internalExecute(command: GetUserDetail, principal: Principal): UserDetail {
val userDetail = userDetailRepository.findById(UserDetailId(command.id))
?: throw IllegalArgumentException("actor does not exist")
val actor = actorRepository.findById(userDetail.actorId)!!

View File

@ -21,6 +21,7 @@ import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.config.ApplicationConfig
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.instance.InstanceRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetail
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
@ -45,7 +46,7 @@ class RegisterLocalActorApplicationService(
private val idGenerateService: IdGenerateService,
) : AbstractApplicationService<RegisterLocalActor, URI>(transaction, Companion.logger) {
override suspend fun internalExecute(command: RegisterLocalActor): URI {
override suspend fun internalExecute(command: RegisterLocalActor, principal: Principal): URI {
if (actorDomainService.usernameAlreadyUse(command.name)) {
// todo 適切な例外を考える
throw Exception("Username already exists")

View File

@ -36,7 +36,7 @@ class TimelineRelationshipFollowSubscriber(
relationship.targetActorId,
Visible.FOLLOWERS
)
)
), it.body.principal
)

View File

@ -20,6 +20,7 @@ import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.filter.FilterId
import dev.usbharu.hideout.core.domain.model.filter.FilterRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -29,7 +30,7 @@ class UserDeleteFilterApplicationService(private val filterRepository: FilterRep
transaction,
logger
) {
override suspend fun internalExecute(command: DeleteFilter) {
override suspend fun internalExecute(command: DeleteFilter, principal: Principal) {
val filter = filterRepository.findByFilterId(FilterId(command.filterId)) ?: throw Exception("not found")
filterRepository.delete(filter)
}

View File

@ -20,6 +20,7 @@ import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.filter.FilterId
import dev.usbharu.hideout.core.domain.model.filter.FilterRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -29,7 +30,7 @@ class UserGetFilterApplicationService(private val filterRepository: FilterReposi
transaction,
logger
) {
override suspend fun internalExecute(command: GetFilter): Filter {
override suspend fun internalExecute(command: GetFilter, principal: Principal): Filter {
val filter = filterRepository.findByFilterId(FilterId(command.filterId)) ?: throw Exception("Not Found")
return Filter.of(filter)

View File

@ -20,6 +20,7 @@ import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
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.shared.id.IdGenerateService
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -35,7 +36,7 @@ class UserRegisterFilterApplicationService(
logger
) {
override suspend fun internalExecute(command: RegisterFilter): Filter {
override suspend fun internalExecute(command: RegisterFilter, principal: Principal): Filter {
val filter = dev.usbharu.hideout.core.domain.model.filter.Filter.create(
id = FilterId(idGenerateService.generateId()),

View File

@ -19,6 +19,7 @@ package dev.usbharu.hideout.core.application.media
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.media.*
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.shared.id.IdGenerateService
import dev.usbharu.hideout.core.external.media.MediaProcessor
import dev.usbharu.hideout.core.external.mediastore.MediaStore
@ -38,7 +39,7 @@ class UploadMediaApplicationService(
transaction,
logger
) {
override suspend fun internalExecute(command: UploadMedia): Media {
override suspend fun internalExecute(command: UploadMedia, principal: Principal): Media {
val process = mediaProcessor.process(command.path, command.name, null)
val id = idGenerateService.generateId()
val thumbnailUri = if (process.thumbnailPath != null) {

View File

@ -20,6 +20,7 @@ import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -27,7 +28,7 @@ import org.springframework.stereotype.Service
class GetPostApplicationService(private val postRepository: PostRepository, transaction: Transaction) :
AbstractApplicationService<GetPost, Post>(transaction, logger) {
override suspend fun internalExecute(command: GetPost): Post {
override suspend fun internalExecute(command: GetPost, principal: Principal): Post {
val post = postRepository.findById(PostId(command.postId)) ?: throw Exception("Post not found")
return Post.of(post)

View File

@ -23,6 +23,7 @@ import dev.usbharu.hideout.core.domain.model.media.MediaId
import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.post.PostOverview
import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import dev.usbharu.hideout.core.infrastructure.factory.PostFactoryImpl
@ -39,7 +40,7 @@ class RegisterLocalPostApplicationService(
transaction: Transaction,
) : AbstractApplicationService<RegisterLocalPost, Long>(transaction, Companion.logger) {
override suspend fun internalExecute(command: RegisterLocalPost): Long {
override suspend fun internalExecute(command: RegisterLocalPost, principal: Principal): Long {
val actorId = (
userDetailRepository.findById(UserDetailId(command.userDetailId))
?: throw IllegalStateException("actor not found")

View File

@ -23,6 +23,7 @@ import dev.usbharu.hideout.core.domain.model.media.MediaId
import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.post.PostOverview
import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import dev.usbharu.hideout.core.infrastructure.factory.PostContentFactoryImpl
import org.slf4j.LoggerFactory
@ -37,7 +38,7 @@ class UpdateLocalNoteApplicationService(
private val actorRepository: ActorRepository,
) : AbstractApplicationService<UpdateLocalNote, Unit>(transaction, logger) {
override suspend fun internalExecute(command: UpdateLocalNote) {
override suspend fun internalExecute(command: UpdateLocalNote, principal: Principal) {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!

View File

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

View File

@ -22,6 +22,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import dev.usbharu.hideout.core.domain.service.relationship.RelationshipDomainService
import org.slf4j.LoggerFactory
@ -36,7 +37,7 @@ class UserBlockApplicationService(
private val relationshipDomainService: RelationshipDomainService,
) :
AbstractApplicationService<Block, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Block) {
override suspend fun internalExecute(command: Block, principal: Principal) {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!

View File

@ -22,6 +22,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -37,7 +38,7 @@ class UserFollowRequestApplicationService(
logger
) {
override suspend fun internalExecute(command: FollowRequest) {
override suspend fun internalExecute(command: FollowRequest, principal: Principal) {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!

View File

@ -23,6 +23,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.actorinstancerelationship.ActorInstanceRelationship
import dev.usbharu.hideout.core.domain.model.actorinstancerelationship.ActorInstanceRelationshipRepository
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -39,7 +40,7 @@ class GetRelationshipApplicationService(
transaction,
logger
) {
override suspend fun internalExecute(command: GetRelationship): Relationship {
override suspend fun internalExecute(command: GetRelationship, principal: Principal): Relationship {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!
val targetId = ActorId(command.targetActorId)

View File

@ -23,6 +23,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -35,7 +36,7 @@ class UserMuteApplicationService(
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<Mute, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Mute) {
override suspend fun internalExecute(command: Mute, principal: Principal) {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!

View File

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

View File

@ -23,6 +23,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
@ -36,7 +37,7 @@ class UserRemoveFromFollowersApplicationService(
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<RemoveFromFollowers, Unit>(transaction, logger) {
override suspend fun internalExecute(command: RemoveFromFollowers) {
override suspend fun internalExecute(command: RemoveFromFollowers, principal: Principal) {
val userDetail = userDetailRepository.findById(UserDetailId(command.userDetailId))!!
val actor = actorRepository.findById(userDetail.actorId)!!

View File

@ -23,6 +23,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -35,7 +36,7 @@ class UserUnblockApplicationService(
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<Unblock, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Unblock) {
override suspend fun internalExecute(command: Unblock, principal: Principal) {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!

View File

@ -23,6 +23,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -35,7 +36,7 @@ class UserUnfollowApplicationService(
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<Unfollow, Unit>(transaction, logger) {
override suspend fun internalExecute(command: Unfollow) {
override suspend fun internalExecute(command: Unfollow, principal: Principal) {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!

View File

@ -23,6 +23,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -39,7 +40,7 @@ class UserUnmuteApplicationService(
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
override suspend fun internalExecute(command: Unmute) {
override suspend fun internalExecute(command: Unmute, principal: Principal) {
val userDetail = userDetailRepository.findById(command.userDetailId)!!
val actor = actorRepository.findById(userDetail.actorId)!!

View File

@ -16,6 +16,7 @@
package dev.usbharu.hideout.core.application.shared
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import kotlinx.coroutines.CancellationException
import org.slf4j.Logger
@ -23,11 +24,11 @@ abstract class AbstractApplicationService<T : Any, R>(
protected val transaction: Transaction,
protected val logger: Logger,
) : ApplicationService<T, R> {
override suspend fun execute(command: T): R {
override suspend fun execute(command: T, principal: Principal): R {
return try {
logger.debug("START {}", command::class.simpleName)
val response = transaction.transaction<R> {
internalExecute(command)
internalExecute(command, principal)
}
logger.info("SUCCESS ${command::class.simpleName}")
response
@ -40,5 +41,5 @@ abstract class AbstractApplicationService<T : Any, R>(
}
}
protected abstract suspend fun internalExecute(command: T): R
protected abstract suspend fun internalExecute(command: T, principal: Principal): R
}

View File

@ -16,6 +16,8 @@
package dev.usbharu.hideout.core.application.shared
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
interface ApplicationService<T : Any, R> {
suspend fun execute(command: T): R
suspend fun execute(command: T, principal: Principal): R
}

View File

@ -0,0 +1,15 @@
package dev.usbharu.hideout.core.application.shared
import dev.usbharu.hideout.core.domain.model.support.principal.FromApi
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import org.slf4j.Logger
abstract class LocalUserAbstractApplicationService<T : Any, R>(transaction: Transaction, logger: Logger) :
AbstractApplicationService<T, R>(transaction, logger) {
override suspend fun internalExecute(command: T, principal: Principal): R {
require(principal is FromApi)
return internalExecute(command, principal)
}
abstract suspend fun internalExecute(command: T, principal: FromApi): R
}

View File

@ -2,6 +2,7 @@ package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationshipRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -14,7 +15,7 @@ class UserAddTimelineRelationshipApplicationService(
AbstractApplicationService<AddTimelineRelationship, Unit>(
transaction, logger
) {
override suspend fun internalExecute(command: AddTimelineRelationship) {
override suspend fun internalExecute(command: AddTimelineRelationship, principal: Principal) {
timelineRelationshipRepository.save(command.timelineRelationship)
}

View File

@ -33,7 +33,7 @@ class ActorDomainEventFactory(private val actor: Actor) {
class ActorEventBody(actor: Actor) : DomainEventBody(
mapOf(
"actor" to actor
)
),
)
enum class ActorEvent(val eventName: String, val collectable: Boolean = true) {

View File

@ -39,7 +39,7 @@ class ActorInstanceRelationshipEventBody(actorInstanceRelationship: ActorInstanc
"muting" to actorInstanceRelationship.muting,
"blocking" to actorInstanceRelationship.blocking,
"doNotSendPrivate" to actorInstanceRelationship.doNotSendPrivate,
)
),
)
enum class ActorInstanceRelationshipEvent(val eventName: String) {

View File

@ -17,15 +17,20 @@
package dev.usbharu.hideout.core.domain.event.relationship
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEvent
import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventBody
class RelationshipEventFactory(private val relationship: Relationship) {
class RelationshipEventFactory(private val relationship: Relationship, private val principal: Principal = Anonymous) {
fun createEvent(relationshipEvent: RelationshipEvent): DomainEvent<RelationshipEventBody> =
DomainEvent.create(relationshipEvent.eventName, RelationshipEventBody(relationship))
DomainEvent.create(relationshipEvent.eventName, RelationshipEventBody(relationship, principal))
}
class RelationshipEventBody(relationship: Relationship) : DomainEventBody(mapOf("relationship" to relationship)) {
class RelationshipEventBody(
relationship: Relationship,
override val principal: Principal
) : DomainEventBody(mapOf("relationship" to relationship), principal) {
fun getRelationship(): Relationship {
return toMap()["relationship"] as Relationship
}

View File

@ -0,0 +1,10 @@
package dev.usbharu.hideout.core.domain.model.support.acct
data class Acct(
val userpart: String,
val host: String
) {
override fun toString(): String {
return "acct:$userpart@$host"
}
}

View File

@ -0,0 +1,5 @@
package dev.usbharu.hideout.core.domain.model.support.principal
import dev.usbharu.hideout.core.domain.model.actor.ActorId
data object Anonymous : Principal(ActorId.ghost, null, null)

View File

@ -0,0 +1,10 @@
package dev.usbharu.hideout.core.domain.model.support.principal
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,
acct
)

View File

@ -0,0 +1,7 @@
package dev.usbharu.hideout.core.domain.model.support.principal
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
sealed class Principal(open val actorId: ActorId, open val userDetailId: UserDetailId?, open val acct: Acct?)

View File

@ -16,7 +16,9 @@
package dev.usbharu.hideout.core.domain.shared.domainevent
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
@Suppress("UnnecessaryAbstractClass")
abstract class DomainEventBody(private val map: Map<String, Any?>) {
abstract class DomainEventBody(private val map: Map<String, Any?>, open val principal: Principal? = null) {
fun toMap(): Map<String, Any?> = map
}

View File

@ -18,6 +18,7 @@ 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
@ -39,7 +40,7 @@ class AuthController(
suspend fun signUp(@Validated @ModelAttribute signUpForm: SignUpForm, request: HttpServletRequest): String {
val registerLocalActor = RegisterLocalActor(signUpForm.username, signUpForm.password)
val uri = registerLocalActorApplicationService.execute(
registerLocalActor
registerLocalActor, Anonymous
)
request.login(signUpForm.username, signUpForm.password)
return "redirect:$uri"

View File

@ -18,6 +18,7 @@ package dev.usbharu.hideout.mastodon.application.accounts
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.Account
import dev.usbharu.hideout.mastodon.query.AccountQueryService
import org.slf4j.LoggerFactory
@ -29,7 +30,7 @@ class GetAccountApplicationService(private val accountQueryService: AccountQuery
transaction,
logger
) {
override suspend fun internalExecute(command: GetAccount): Account {
override suspend fun internalExecute(command: GetAccount, principal: Principal): Account {
return accountQueryService.findById(command.accountId.toLong()) ?: throw Exception("Account not found")
}

View File

@ -20,6 +20,7 @@ import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.filter.FilterKeywordId
import dev.usbharu.hideout.core.domain.model.filter.FilterRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -32,7 +33,7 @@ class DeleteFilterV1ApplicationService(private val filterRepository: FilterRepos
private val logger = LoggerFactory.getLogger(DeleteFilterV1ApplicationService::class.java)
}
override suspend fun internalExecute(command: DeleteFilterV1) {
override suspend fun internalExecute(command: DeleteFilterV1, principal: Principal) {
val filter = filterRepository.findByFilterKeywordId(FilterKeywordId(command.filterKeywordId))
?: throw Exception("Not Found")
filterRepository.delete(filter)

View File

@ -22,6 +22,7 @@ import dev.usbharu.hideout.core.domain.model.filter.FilterContext.*
import dev.usbharu.hideout.core.domain.model.filter.FilterKeywordId
import dev.usbharu.hideout.core.domain.model.filter.FilterMode
import dev.usbharu.hideout.core.domain.model.filter.FilterRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.V1Filter
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Repository
@ -31,7 +32,7 @@ class GetFilterV1ApplicationService(private val filterRepository: FilterReposito
AbstractApplicationService<GetFilterV1, V1Filter>(
transaction, logger
) {
override suspend fun internalExecute(command: GetFilterV1): V1Filter {
override suspend fun internalExecute(command: GetFilterV1, principal: Principal): V1Filter {
val filter = filterRepository.findByFilterKeywordId(FilterKeywordId(command.filterKeywordId))
?: throw Exception("Not Found")

View File

@ -18,6 +18,7 @@ package dev.usbharu.hideout.mastodon.application.status
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.Status
import dev.usbharu.hideout.mastodon.query.StatusQueryService
import org.slf4j.LoggerFactory
@ -35,7 +36,7 @@ class GetStatusApplicationService(
val logger = LoggerFactory.getLogger(GetStatusApplicationService::class.java)!!
}
override suspend fun internalExecute(command: GetStatus): Status {
override suspend fun internalExecute(command: GetStatus, principal: Principal): Status {
return statusQueryService.findByPostId(command.id.toLong()) ?: throw Exception("Not fount")
}
}