From 9677b11f5c7dce83572126b421c94119f11d8b6c Mon Sep 17 00:00:00 2001 From: usbharu Date: Wed, 18 Sep 2024 23:26:03 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=95=E3=82=A9=E3=83=AD=E3=83=BC?= =?UTF-8?q?=E7=AD=89=E3=81=AE=E4=BA=8B=E5=89=8D=E7=8A=B6=E6=85=8B=E3=83=81?= =?UTF-8?q?=E3=82=A7=E3=83=83=E3=82=AF=E3=82=92=E3=83=89=E3=83=A1=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=82=B5=E3=83=BC=E3=83=93=E3=82=B9=E3=81=A7=E8=A9=B3?= =?UTF-8?q?=E7=B4=B0=E3=81=AB=E8=A1=8C=E3=81=86=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/model/relationship/Relationship.kt | 14 ++++++++++++-- .../relationship/RelationshipDomainService.kt | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt index 87bccaea..813294f7 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt @@ -52,7 +52,7 @@ class Relationship( addDomainEvent(relationshipEventFactory.createEvent(RelationshipEvent.UNFOLLOW_REQUEST)) } - fun block() { + private fun block() { unfollow() blocking = true addDomainEvent(RelationshipEventFactory(this).createEvent(RelationshipEvent.BLOCK)) @@ -81,7 +81,7 @@ class Relationship( mutingFollowRequest = false } - fun followRequest() { + private fun followRequest() { require(blocking.not()) followRequesting = true addDomainEvent(RelationshipEventFactory(this).createEvent(RelationshipEvent.FOLLOW_REQUEST)) @@ -123,6 +123,16 @@ class Relationship( return result } + abstract class InternalRelationshipDomainService { + protected fun block(relationship: Relationship) { + relationship.block() + } + + protected fun followRequest(relationship: Relationship) { + relationship.followRequest() + } + } + companion object { fun default(actorId: ActorId, targetActorId: ActorId): Relationship = Relationship( actorId = actorId, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/relationship/RelationshipDomainService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/relationship/RelationshipDomainService.kt index b59c0319..7c35d6c0 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/relationship/RelationshipDomainService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/relationship/RelationshipDomainService.kt @@ -17,17 +17,28 @@ package dev.usbharu.hideout.core.domain.service.relationship import dev.usbharu.hideout.core.domain.model.relationship.Relationship +import dev.usbharu.hideout.core.domain.model.relationship.Relationship.InternalRelationshipDomainService import org.springframework.stereotype.Service @Service -class RelationshipDomainService { +class RelationshipDomainService : InternalRelationshipDomainService() { fun block(relationship: Relationship, inverseRelationship: Relationship) { require(relationship != inverseRelationship) require(relationship.actorId == inverseRelationship.targetActorId) require(relationship.targetActorId == inverseRelationship.actorId) - relationship.block() + block(relationship) inverseRelationship.unfollow() inverseRelationship.unfollowRequest() } + + fun followRequest(relationship: Relationship, inverseRelationship: Relationship) { + require(relationship != inverseRelationship) + require(relationship.actorId == inverseRelationship.targetActorId) + require(relationship.targetActorId == inverseRelationship.actorId) + require(inverseRelationship.blocking.not()) + require(relationship.blocking.not()) + + followRequest(relationship) + } }