From bf2d7986cc015c724d6f4926dd06c2fedde13a3b Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 27 Jun 2024 01:00:13 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=89=E3=83=A1=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=82=A4=E3=83=99=E3=83=B3=E3=83=88=E3=82=92=E5=8F=97=E3=81=91?= =?UTF-8?q?=E5=8F=96=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subscribers/DomainEventSubscriber.kt | 10 +++++++ .../TimelinePostCreateSubscriber.kt | 17 +++++++++++ .../RegisterLocalPostApplicationService.kt | 6 ++-- .../get/GetRelationshipApplicationService.kt | 12 ++++---- .../core/domain/event/actor/ActorEvent.kt | 2 +- .../ActorInstanceRelationshipEvent.kt | 2 +- .../domain/event/instance/InstanceEvent.kt | 2 +- .../core/domain/event/post/PostEvent.kt | 7 +++-- .../event/relationship/RelationshipEvent.kt | 2 +- .../domain/model/actor/ActorPrivateKey.kt | 12 ++++---- .../core/domain/model/actor/ActorPublicKey.kt | 12 ++++---- .../hideout/core/domain/model/actor/Role.kt | 2 +- .../ActorInstanceRelationship.kt | 12 ++++---- .../model/application/ApplicationName.kt | 2 +- .../core/domain/model/filter/FilterName.kt | 2 -- .../hideout/core/domain/model/media/Media.kt | 20 ++++++------- .../domain/shared/domainevent/DomainEvent.kt | 14 ++++----- .../shared/domainevent/DomainEventBody.kt | 2 +- .../domainevent/DomainEventPublisher.kt | 2 +- .../shared/domainevent/DomainEventStorable.kt | 6 ++-- .../domainevent/DomainEventSubscriber.kt | 7 ----- ...osedActorInstanceRelationshipRepository.kt | 4 +-- .../SpringFrameworkDomainEventPublisher.kt | 2 +- .../SpringFrameworkDomainEventSubscriber.kt | 29 +++++++++++++++++++ .../oauth2/HideoutUserDetails.kt | 10 +++---- 25 files changed, 124 insertions(+), 74 deletions(-) create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/DomainEventSubscriber.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelinePostCreateSubscriber.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventSubscriber.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/domainevent/SpringFrameworkDomainEventSubscriber.kt diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/DomainEventSubscriber.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/DomainEventSubscriber.kt new file mode 100644 index 00000000..19146b4f --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/DomainEventSubscriber.kt @@ -0,0 +1,10 @@ +package dev.usbharu.hideout.core.application.domainevent.subscribers + +import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEvent +import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventBody + +interface DomainEventSubscriber { + fun subscribe(eventName: String, domainEventConsumer: DomainEventConsumer) +} + +typealias DomainEventConsumer = (DomainEvent) -> Unit diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelinePostCreateSubscriber.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelinePostCreateSubscriber.kt new file mode 100644 index 00000000..e6d7ba41 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelinePostCreateSubscriber.kt @@ -0,0 +1,17 @@ +package dev.usbharu.hideout.core.application.domainevent.subscribers + +import dev.usbharu.hideout.core.domain.event.post.PostEvent +import dev.usbharu.hideout.core.domain.event.post.PostEventBody +import org.springframework.stereotype.Component + +@Component +class TimelinePostCreateSubscriber(domainEventSubscriber: DomainEventSubscriber) { + init { + domainEventSubscriber.subscribe(PostEvent.CREATE.eventName) { + val post = it.body.getPost() + val actor = it.body.getActor() + + println(post.toString()) + } + } +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationService.kt index bc38e59a..40e2b435 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationService.kt @@ -41,9 +41,9 @@ class RegisterLocalPostApplicationService( override suspend fun internalExecute(command: RegisterLocalPost, executor: CommandExecutor): Long { val actorId = ( - userDetailRepository.findById(command.userDetailId) - ?: throw IllegalStateException("actor not found") - ).actorId + userDetailRepository.findById(command.userDetailId) + ?: throw IllegalStateException("actor not found") + ).actorId val actor = actorRepository.findById(actorId)!! diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationshipApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationshipApplicationService.kt index 1a0261f7..5cf997c1 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationshipApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationshipApplicationService.kt @@ -48,14 +48,14 @@ class GetRelationshipApplicationService( val targetId = ActorId(command.targetActorId) val target = actorRepository.findById(targetId)!! val relationship = ( - relationshipRepository.findByActorIdAndTargetId(actor.id, targetId) - ?: dev.usbharu.hideout.core.domain.model.relationship.Relationship.default(actor.id, targetId) - ) + relationshipRepository.findByActorIdAndTargetId(actor.id, targetId) + ?: dev.usbharu.hideout.core.domain.model.relationship.Relationship.default(actor.id, targetId) + ) val relationship1 = ( - relationshipRepository.findByActorIdAndTargetId(targetId, actor.id) - ?: dev.usbharu.hideout.core.domain.model.relationship.Relationship.default(targetId, actor.id) - ) + relationshipRepository.findByActorIdAndTargetId(targetId, actor.id) + ?: dev.usbharu.hideout.core.domain.model.relationship.Relationship.default(targetId, actor.id) + ) val actorInstanceRelationship = actorInstanceRelationshipRepository.findByActorIdAndInstanceId(actor.id, target.instance) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actor/ActorEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actor/ActorEvent.kt index 69e154eb..fb2343e3 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actor/ActorEvent.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actor/ActorEvent.kt @@ -21,7 +21,7 @@ import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEvent import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventBody class ActorDomainEventFactory(private val actor: Actor) { - fun createEvent(actorEvent: ActorEvent): DomainEvent { + fun createEvent(actorEvent: ActorEvent): DomainEvent { return DomainEvent.create( actorEvent.eventName, ActorEventBody(actor), diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actorinstancerelationship/ActorInstanceRelationshipEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actorinstancerelationship/ActorInstanceRelationshipEvent.kt index bf332080..ada2287e 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actorinstancerelationship/ActorInstanceRelationshipEvent.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/actorinstancerelationship/ActorInstanceRelationshipEvent.kt @@ -21,7 +21,7 @@ import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEvent import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventBody class ActorInstanceRelationshipDomainEventFactory(private val actorInstanceRelationship: ActorInstanceRelationship) { - fun createEvent(actorInstanceRelationshipEvent: ActorInstanceRelationshipEvent): DomainEvent { + fun createEvent(actorInstanceRelationshipEvent: ActorInstanceRelationshipEvent): DomainEvent { return DomainEvent.create( actorInstanceRelationshipEvent.eventName, ActorInstanceRelationshipEventBody(actorInstanceRelationship) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/instance/InstanceEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/instance/InstanceEvent.kt index 72f0941a..3f09a2c7 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/instance/InstanceEvent.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/instance/InstanceEvent.kt @@ -21,7 +21,7 @@ import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEvent import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventBody class InstanceEventFactory(private val instance: Instance) { - fun createEvent(event: InstanceEvent): DomainEvent { + fun createEvent(event: InstanceEvent): DomainEvent { return DomainEvent.create( event.eventName, InstanceEventBody(instance) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/post/PostEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/post/PostEvent.kt index 5020d056..52423afd 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/post/PostEvent.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/post/PostEvent.kt @@ -22,7 +22,7 @@ import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEvent import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventBody class PostDomainEventFactory(private val post: Post, private val actor: Actor? = null) { - fun createEvent(postEvent: PostEvent): DomainEvent { + fun createEvent(postEvent: PostEvent): DomainEvent { return DomainEvent.create( postEvent.eventName, PostEventBody(post, actor) @@ -30,7 +30,10 @@ class PostDomainEventFactory(private val post: Post, private val actor: Actor? = } } -class PostEventBody(post: Post, actor: Actor?) : DomainEventBody(mapOf("post" to post, "actor" to actor)) +class PostEventBody(post: Post, actor: Actor?) : DomainEventBody(mapOf("post" to post, "actor" to actor)) { + fun getPost(): Post = toMap()["post"] as Post + fun getActor(): Actor? = toMap()["actor"] as Actor? +} enum class PostEvent(val eventName: String) { DELETE("PostDelete"), diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/relationship/RelationshipEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/relationship/RelationshipEvent.kt index da9345b1..c388d592 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/relationship/RelationshipEvent.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/relationship/RelationshipEvent.kt @@ -21,7 +21,7 @@ import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEvent import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventBody class RelationshipEventFactory(private val relationship: Relationship) { - fun createEvent(relationshipEvent: RelationshipEvent): DomainEvent = + fun createEvent(relationshipEvent: RelationshipEvent): DomainEvent = DomainEvent.create(relationshipEvent.eventName, RelationshipEventBody(relationship)) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPrivateKey.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPrivateKey.kt index bb507885..fd683f2b 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPrivateKey.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPrivateKey.kt @@ -25,12 +25,12 @@ value class ActorPrivateKey(val privateKey: String) { fun create(privateKey: PrivateKey): ActorPrivateKey { return ActorPrivateKey( "-----BEGIN PRIVATE KEY-----\n" + - Base64 - .getEncoder() - .encodeToString(privateKey.encoded) - .chunked(64) - .joinToString("\n") + - "\n-----END PRIVATE KEY-----" + Base64 + .getEncoder() + .encodeToString(privateKey.encoded) + .chunked(64) + .joinToString("\n") + + "\n-----END PRIVATE KEY-----" ) } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPublicKey.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPublicKey.kt index 5dd982f1..f3419d91 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPublicKey.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorPublicKey.kt @@ -25,12 +25,12 @@ value class ActorPublicKey(val publicKey: String) { fun create(publicKey: PublicKey): ActorPublicKey { return ActorPublicKey( "-----BEGIN PUBLIC KEY-----\n" + - Base64 - .getEncoder() - .encodeToString(publicKey.encoded) - .chunked(64) - .joinToString("\n") + - "\n-----END PUBLIC KEY-----" + Base64 + .getEncoder() + .encodeToString(publicKey.encoded) + .chunked(64) + .joinToString("\n") + + "\n-----END PUBLIC KEY-----" ) } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Role.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Role.kt index 083ffc20..7c697abf 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Role.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Role.kt @@ -20,5 +20,5 @@ enum class Role { LOCAL, MODERATOR, ADMINISTRATOR, - REMOTE; + REMOTE } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt index 90c7b529..4585ddc0 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actorinstancerelationship/ActorInstanceRelationship.kt @@ -89,12 +89,12 @@ class ActorInstanceRelationship( override fun toString(): String { return "ActorInstanceRelationship(" + - "actorId=$actorId, " + - "instanceId=$instanceId, " + - "blocking=$blocking, " + - "muting=$muting, " + - "doNotSendPrivate=$doNotSendPrivate" + - ")" + "actorId=$actorId, " + + "instanceId=$instanceId, " + + "blocking=$blocking, " + + "muting=$muting, " + + "doNotSendPrivate=$doNotSendPrivate" + + ")" } companion object { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/application/ApplicationName.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/application/ApplicationName.kt index c57f4755..37007ecd 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/application/ApplicationName.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/application/ApplicationName.kt @@ -25,4 +25,4 @@ value class ApplicationName(val name: String) { companion object { const val LENGTH = 300 } -} \ No newline at end of file +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterName.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterName.kt index 4f398bd3..bd6596f3 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterName.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterName.kt @@ -1,9 +1,7 @@ package dev.usbharu.hideout.core.domain.model.filter - class FilterName(name: String) { - val name = name.take(LENGTH) companion object { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt index 1d2823c4..44c75088 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt @@ -37,15 +37,15 @@ class Media( } override fun toString(): String { return "Media(" + - "id=$id, " + - "name=$name, " + - "url=$url, " + - "remoteUrl=$remoteUrl, " + - "thumbnailUrl=$thumbnailUrl, " + - "type=$type, " + - "mimeType=$mimeType, " + - "blurHash=$blurHash, " + - "description=$description" + - ")" + "id=$id, " + + "name=$name, " + + "url=$url, " + + "remoteUrl=$remoteUrl, " + + "thumbnailUrl=$thumbnailUrl, " + + "type=$type, " + + "mimeType=$mimeType, " + + "blurHash=$blurHash, " + + "description=$description" + + ")" } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEvent.kt index d4379335..0b5f77fc 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEvent.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEvent.kt @@ -28,23 +28,23 @@ import java.util.* * @property body ドメインイベントのボディ * @property collectable trueで同じドメインイベント名でをまとめる */ -data class DomainEvent( +data class DomainEvent( val id: String, val name: String, val occurredOn: Instant, - val body: DomainEventBody, + val body: T, val collectable: Boolean = false ) { companion object { - fun create(name: String, body: DomainEventBody, collectable: Boolean = false): DomainEvent = - DomainEvent(UUID.randomUUID().toString(), name, Instant.now(), body, collectable) + fun create(name: String, body: T, collectable: Boolean = false): DomainEvent = + DomainEvent(UUID.randomUUID().toString(), name, Instant.now(), body, collectable) - fun reconstruct( + fun reconstruct( id: String, name: String, occurredOn: Instant, - body: DomainEventBody, + body: T, collectable: Boolean - ): DomainEvent = DomainEvent(id, name, occurredOn, body, collectable) + ): DomainEvent = DomainEvent(id, name, occurredOn, body, collectable) } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventBody.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventBody.kt index f4cd139d..7c57d32c 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventBody.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventBody.kt @@ -17,6 +17,6 @@ package dev.usbharu.hideout.core.domain.shared.domainevent @Suppress("UnnecessaryAbstractClass") -abstract class DomainEventBody(val map: Map) { +abstract class DomainEventBody(private val map: Map) { fun toMap(): Map = map } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventPublisher.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventPublisher.kt index 7f7cd592..cf784458 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventPublisher.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventPublisher.kt @@ -1,5 +1,5 @@ package dev.usbharu.hideout.core.domain.shared.domainevent interface DomainEventPublisher { - suspend fun publishEvent(domainEvent: DomainEvent) + suspend fun publishEvent(domainEvent: DomainEvent<*>) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventStorable.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventStorable.kt index 6e6b83b7..849267b0 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventStorable.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventStorable.kt @@ -18,13 +18,13 @@ package dev.usbharu.hideout.core.domain.shared.domainevent @Suppress("UnnecessaryAbstractClass") abstract class DomainEventStorable { - private val domainEvents: MutableList = mutableListOf() + private val domainEvents: MutableList> = mutableListOf() - protected fun addDomainEvent(domainEvent: DomainEvent) { + protected fun addDomainEvent(domainEvent: DomainEvent<*>) { domainEvents.add(domainEvent) } fun clearDomainEvents() = domainEvents.clear() - fun getDomainEvents(): List = domainEvents.toList() + fun getDomainEvents(): List> = domainEvents.toList() } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventSubscriber.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventSubscriber.kt deleted file mode 100644 index 5d24a1b7..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/shared/domainevent/DomainEventSubscriber.kt +++ /dev/null @@ -1,7 +0,0 @@ -package dev.usbharu.hideout.core.domain.shared.domainevent - -interface DomainEventSubscriber { - fun subscribe(eventName: String, domainEventConsumer: DomainEventConsumer) -} - -typealias DomainEventConsumer = (DomainEvent) -> Unit diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorInstanceRelationshipRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorInstanceRelationshipRepository.kt index 1843c88a..61bccf73 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorInstanceRelationshipRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorInstanceRelationshipRepository.kt @@ -54,7 +54,7 @@ class ExposedActorInstanceRelationshipRepository(override val domainEventPublish query { ActorInstanceRelationships.deleteWhere { actorId eq actorInstanceRelationship.actorId.id and - (instanceId eq actorInstanceRelationship.instanceId.instanceId) + (instanceId eq actorInstanceRelationship.instanceId.instanceId) } } update(actorInstanceRelationship) @@ -68,7 +68,7 @@ class ExposedActorInstanceRelationshipRepository(override val domainEventPublish .selectAll() .where { ActorInstanceRelationships.actorId eq actorId.id and - (ActorInstanceRelationships.instanceId eq instanceId.instanceId) + (ActorInstanceRelationships.instanceId eq instanceId.instanceId) } .singleOrNull() ?.toActorInstanceRelationship() diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/domainevent/SpringFrameworkDomainEventPublisher.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/domainevent/SpringFrameworkDomainEventPublisher.kt index ecbe2c2b..40794c1e 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/domainevent/SpringFrameworkDomainEventPublisher.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/domainevent/SpringFrameworkDomainEventPublisher.kt @@ -24,7 +24,7 @@ import org.springframework.stereotype.Component @Component class SpringFrameworkDomainEventPublisher(private val applicationEventPublisher: ApplicationEventPublisher) : DomainEventPublisher { - override suspend fun publishEvent(domainEvent: DomainEvent) { + override suspend fun publishEvent(domainEvent: DomainEvent<*>) { applicationEventPublisher.publishEvent(domainEvent) } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/domainevent/SpringFrameworkDomainEventSubscriber.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/domainevent/SpringFrameworkDomainEventSubscriber.kt new file mode 100644 index 00000000..a3cd4f2d --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/domainevent/SpringFrameworkDomainEventSubscriber.kt @@ -0,0 +1,29 @@ +package dev.usbharu.hideout.core.infrastructure.springframework.domainevent + +import dev.usbharu.hideout.core.application.domainevent.subscribers.DomainEventConsumer +import dev.usbharu.hideout.core.application.domainevent.subscribers.DomainEventSubscriber +import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEvent +import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventBody +import org.springframework.context.event.EventListener +import org.springframework.stereotype.Component + +@Component +class SpringFrameworkDomainEventSubscriber : DomainEventSubscriber { + + val map = mutableMapOf>>() + + override fun subscribe(eventName: String, domainEventConsumer: DomainEventConsumer) { + map.getOrPut(eventName) { mutableListOf() }.add(domainEventConsumer as DomainEventConsumer<*>) + } + + @EventListener + fun onDomainEventPublished(domainEvent: DomainEvent<*>) { + map[domainEvent.name]?.forEach { + try { + it.invoke(domainEvent) + } + catch (e: Exception) { + } + } + } +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/HideoutUserDetails.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/HideoutUserDetails.kt index 616868fe..cbaf2540 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/HideoutUserDetails.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/HideoutUserDetails.kt @@ -70,11 +70,11 @@ class HideoutUserDetails( override fun toString(): String { return "HideoutUserDetails(" + - "password='$password', " + - "username='$username', " + - "userDetailsId=$userDetailsId, " + - "authorities=$authorities" + - ")" + "password='$password', " + + "username='$username', " + + "userDetailsId=$userDetailsId, " + + "authorities=$authorities" + + ")" } companion object {