mirror of https://github.com/usbharu/Hideout.git
feat: フォロー等の事前状態チェックをドメインサービスで詳細に行うように
This commit is contained in:
parent
6d233a1d39
commit
9677b11f5c
|
@ -52,7 +52,7 @@ class Relationship(
|
||||||
addDomainEvent(relationshipEventFactory.createEvent(RelationshipEvent.UNFOLLOW_REQUEST))
|
addDomainEvent(relationshipEventFactory.createEvent(RelationshipEvent.UNFOLLOW_REQUEST))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun block() {
|
private fun block() {
|
||||||
unfollow()
|
unfollow()
|
||||||
blocking = true
|
blocking = true
|
||||||
addDomainEvent(RelationshipEventFactory(this).createEvent(RelationshipEvent.BLOCK))
|
addDomainEvent(RelationshipEventFactory(this).createEvent(RelationshipEvent.BLOCK))
|
||||||
|
@ -81,7 +81,7 @@ class Relationship(
|
||||||
mutingFollowRequest = false
|
mutingFollowRequest = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun followRequest() {
|
private fun followRequest() {
|
||||||
require(blocking.not())
|
require(blocking.not())
|
||||||
followRequesting = true
|
followRequesting = true
|
||||||
addDomainEvent(RelationshipEventFactory(this).createEvent(RelationshipEvent.FOLLOW_REQUEST))
|
addDomainEvent(RelationshipEventFactory(this).createEvent(RelationshipEvent.FOLLOW_REQUEST))
|
||||||
|
@ -123,6 +123,16 @@ class Relationship(
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract class InternalRelationshipDomainService {
|
||||||
|
protected fun block(relationship: Relationship) {
|
||||||
|
relationship.block()
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun followRequest(relationship: Relationship) {
|
||||||
|
relationship.followRequest()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun default(actorId: ActorId, targetActorId: ActorId): Relationship = Relationship(
|
fun default(actorId: ActorId, targetActorId: ActorId): Relationship = Relationship(
|
||||||
actorId = actorId,
|
actorId = actorId,
|
||||||
|
|
|
@ -17,17 +17,28 @@
|
||||||
package dev.usbharu.hideout.core.domain.service.relationship
|
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
|
||||||
|
import dev.usbharu.hideout.core.domain.model.relationship.Relationship.InternalRelationshipDomainService
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class RelationshipDomainService {
|
class RelationshipDomainService : InternalRelationshipDomainService() {
|
||||||
fun block(relationship: Relationship, inverseRelationship: Relationship) {
|
fun block(relationship: Relationship, inverseRelationship: Relationship) {
|
||||||
require(relationship != inverseRelationship)
|
require(relationship != inverseRelationship)
|
||||||
require(relationship.actorId == inverseRelationship.targetActorId)
|
require(relationship.actorId == inverseRelationship.targetActorId)
|
||||||
require(relationship.targetActorId == inverseRelationship.actorId)
|
require(relationship.targetActorId == inverseRelationship.actorId)
|
||||||
|
|
||||||
relationship.block()
|
block(relationship)
|
||||||
inverseRelationship.unfollow()
|
inverseRelationship.unfollow()
|
||||||
inverseRelationship.unfollowRequest()
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue