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) + } }