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))
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue