feat: フォロー等の事前状態チェックをドメインサービスで詳細に行うように

This commit is contained in:
usbharu 2024-09-18 23:26:03 +09:00
parent 6d233a1d39
commit 9677b11f5c
Signed by: usbharu
GPG Key ID: 95CBCF7046307B77
2 changed files with 25 additions and 4 deletions

View File

@ -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,

View File

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