From 1503ee1844af01fc4350851a3b9b2c16e5701d88 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 14 Sep 2024 13:56:24 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BD=BF=E7=94=A8=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=A6=E3=81=AA=E3=81=84=E9=96=A2=E6=95=B0=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../relationship/RelationshipRepository.kt | 12 ------ .../ExposedRelationshipRepository.kt | 41 ++----------------- 2 files changed, 3 insertions(+), 50 deletions(-) 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]),