diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt index ca6cebcd..3110d9d0 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt @@ -35,17 +35,5 @@ interface RelationshipRepository { following: Boolean ): List - suspend fun findByTargetId( - targetId: ActorId, - option: FindRelationshipOption? = null, - inverseOption: FindRelationshipOption? = null - ): List } -data class FindRelationshipOption( - val follow: Boolean? = null, - val block: Boolean? = null, - val mute: Boolean? = null, - val followRequest: Boolean? = null, - val muteFollowRequest: Boolean? = null -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedRelationshipRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedRelationshipRepository.kt index 73675308..2cdc4c8c 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedRelationshipRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedRelationshipRepository.kt @@ -17,7 +17,6 @@ package dev.usbharu.hideout.core.infrastructure.exposedrepository import dev.usbharu.hideout.core.domain.model.actor.ActorId -import dev.usbharu.hideout.core.domain.model.relationship.FindRelationshipOption import dev.usbharu.hideout.core.domain.model.relationship.Relationship import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventPublisher @@ -69,7 +68,7 @@ class ExposedRelationshipRepository(override val domainEventPublisher: DomainEve override suspend fun findByActorIdAndTargetId(actorId: ActorId, targetId: ActorId): Relationship? = query { Relationships.selectAll().where { Relationships.actorId eq actorId.id and (Relationships.targetActorId eq targetId.id) - }.singleOrNull()?.toRelationships() + }.limit(1).singleOrNull()?.toRelationships() } override suspend fun findByActorIdsAndTargetIdAndBlocking( @@ -78,7 +77,7 @@ class ExposedRelationshipRepository(override val domainEventPublisher: DomainEve blocking: Boolean ): List = query { Relationships.selectAll().where { - Relationships.actorId inList actorIds.map { it.id } and (Relationships.targetActorId eq targetId.id) + Relationships.actorId inList actorIds.map { it.id } and (Relationships.targetActorId eq targetId.id) and (Relationships.blocking eq blocking) }.map { it.toRelationships() } } @@ -88,49 +87,15 @@ class ExposedRelationshipRepository(override val domainEventPublisher: DomainEve following: Boolean ): List = query { Relationships.selectAll().where { - Relationships.actorId eq actorId.id and (Relationships.targetActorId inList targetIds.map { it.id }) + Relationships.actorId eq actorId.id and (Relationships.targetActorId inList targetIds.map { it.id }) and (Relationships.following eq following) }.map { it.toRelationships() } } - override suspend fun findByTargetId( - targetId: ActorId, - option: FindRelationshipOption?, - inverseOption: FindRelationshipOption? - ): List { - val query1 = Relationships.selectAll().where { Relationships.actorId eq targetId.id } - inverseOption.apply(query1) - // todo 逆のほうがいいかも - val query = query1.alias("INV").selectAll().where { - Relationships.targetActorId eq targetId.id - } - option.apply(query) - - return query.map(ResultRow::toRelationships) - } - companion object { private val logger = LoggerFactory.getLogger(ExposedRelationshipRepository::class.java) } } -fun FindRelationshipOption?.apply(query: Query) { - if (this?.follow != null) { - query.andWhere { Relationships.following eq this@apply.follow } - } - if (this?.mute != null) { - query.andWhere { Relationships.muting eq this@apply.mute } - } - if (this?.block != null) { - query.andWhere { Relationships.blocking eq this@apply.block } - } - if (this?.followRequest != null) { - query.andWhere { Relationships.followRequesting eq this@apply.followRequest } - } - if (this?.muteFollowRequest != null) { - query.andWhere { Relationships.mutingFollowRequest eq this@apply.muteFollowRequest } - } -} - fun ResultRow.toRelationships(): Relationship = Relationship( actorId = ActorId(this[Relationships.actorId]), targetActorId = ActorId(this[Relationships.targetActorId]),