mirror of https://github.com/usbharu/Hideout.git
refactor: 使用されてない関数を削除
This commit is contained in:
parent
900ed51d09
commit
1503ee1844
|
@ -35,17 +35,5 @@ interface RelationshipRepository {
|
|||
following: Boolean
|
||||
): List<Relationship>
|
||||
|
||||
suspend fun findByTargetId(
|
||||
targetId: ActorId,
|
||||
option: FindRelationshipOption? = null,
|
||||
inverseOption: FindRelationshipOption? = null
|
||||
): List<Relationship>
|
||||
}
|
||||
|
||||
data class FindRelationshipOption(
|
||||
val follow: Boolean? = null,
|
||||
val block: Boolean? = null,
|
||||
val mute: Boolean? = null,
|
||||
val followRequest: Boolean? = null,
|
||||
val muteFollowRequest: Boolean? = null
|
||||
)
|
||||
|
|
|
@ -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<Relationship> = 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<Relationship> = 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<Relationship> {
|
||||
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]),
|
||||
|
|
Loading…
Reference in New Issue