From a4a3f4c0c45210392e2f65130874f6c0b7627b06 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 6 Jul 2024 16:41:47 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=E3=82=BF=E3=82=A4=E3=83=A0?= =?UTF-8?q?=E3=83=A9=E3=82=A4=E3=83=B3=E3=81=AE=E5=AE=9F=E8=A3=85=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/core/domain/model/post/Post.kt | 6 ++++ .../relationship/RelationshipRepository.kt | 10 +++++++ .../model/timeline/TimelineRepository.kt | 2 ++ .../model/timelinebuilder/TimelineBuilder.kt | 4 --- .../timelinebuilder/TimelineBuilderId.kt | 4 --- .../timelinebuilder/TimelineBuilderName.kt | 4 --- .../TimelineBuilderRepository.kt | 6 ---- .../TimelineRelationship.kt | 10 ------- .../TimelineRelationshipId.kt | 4 --- .../TimelineRelationshipRepository.kt | 6 ---- .../core/external/timeline/TimelineStore.kt | 7 +++++ .../ExposedRelationshipRepository.kt | 28 +++++++++++++++++++ .../infrastructure/factory/PostFactoryImpl.kt | 1 + .../timeline/AbstractTimelineStore.kt | 19 +++++++++++++ .../core/domain/model/post/PostTest.kt | 10 ++++++- 15 files changed, 82 insertions(+), 39 deletions(-) delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilder.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilderId.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilderName.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilderRepository.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationship.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipId.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipRepository.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/timeline/TimelineStore.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/AbstractTimelineStore.kt diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt index d48b557e..9bab7777 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt @@ -22,6 +22,7 @@ import dev.usbharu.hideout.core.domain.model.actor.Actor import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.actor.Role import dev.usbharu.hideout.core.domain.model.emoji.EmojiId +import dev.usbharu.hideout.core.domain.model.instance.InstanceId import dev.usbharu.hideout.core.domain.model.media.MediaId import dev.usbharu.hideout.core.domain.model.post.Post.Companion.Action.* import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventStorable @@ -32,6 +33,7 @@ import java.time.Instant class Post( val id: PostId, actorId: ActorId, + val instanceId: InstanceId, overview: PostOverview?, content: PostContent, val createdAt: Instant, @@ -48,6 +50,7 @@ class Post( moveTo: PostId?, ) : DomainEventStorable() { + val actorId = actorId get() { if (deleted) { @@ -227,6 +230,7 @@ class Post( return Post( id = id, actorId = actorId, + instanceId = instanceId, overview = overview, content = PostContent(this.content.text, this.content.content, emojis), createdAt = createdAt, @@ -273,6 +277,7 @@ class Post( fun create( id: PostId, actorId: ActorId, + instanceId: InstanceId, overview: PostOverview? = null, content: PostContent, createdAt: Instant, @@ -301,6 +306,7 @@ class Post( val post = Post( id = id, actorId = actorId, + instanceId = instanceId, overview = overview, content = content, createdAt = createdAt, 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 d74884af..e147222f 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 @@ -22,4 +22,14 @@ interface RelationshipRepository { suspend fun save(relationship: Relationship): Relationship suspend fun delete(relationship: Relationship) suspend fun findByActorIdAndTargetId(actorId: ActorId, targetId: ActorId): Relationship? + suspend fun findByTargetId(targetId: ActorId, option: 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 +) \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/TimelineRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/TimelineRepository.kt index eff0a9b3..823a0c68 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/TimelineRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/TimelineRepository.kt @@ -3,4 +3,6 @@ package dev.usbharu.hideout.core.domain.model.timeline interface TimelineRepository { suspend fun save(timeline: Timeline): Timeline suspend fun delete(timeline: Timeline) + + suspend fun findByIds(ids: List): List } \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilder.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilder.kt deleted file mode 100644 index 7b722342..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilder.kt +++ /dev/null @@ -1,4 +0,0 @@ -package dev.usbharu.hideout.core.domain.model.timelinebuilder - -class TimelineBuilder(val id: TimelineBuilderId, val timelineBuilderName: TimelineBuilderName) { -} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilderId.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilderId.kt deleted file mode 100644 index e54b4ab2..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilderId.kt +++ /dev/null @@ -1,4 +0,0 @@ -package dev.usbharu.hideout.core.domain.model.timelinebuilder - -@JvmInline -value class TimelineBuilderId(val value: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilderName.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilderName.kt deleted file mode 100644 index bde5563d..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilderName.kt +++ /dev/null @@ -1,4 +0,0 @@ -package dev.usbharu.hideout.core.domain.model.timelinebuilder - -@JvmInline -value class TimelineBuilderName(val value: String) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilderRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilderRepository.kt deleted file mode 100644 index 97e0eda5..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinebuilder/TimelineBuilderRepository.kt +++ /dev/null @@ -1,6 +0,0 @@ -package dev.usbharu.hideout.core.domain.model.timelinebuilder - -interface TimelineBuilderRepository { - suspend fun save(timelineBuilder: TimelineBuilder): TimelineBuilder - suspend fun delete(timelineBuilder: TimelineBuilder) -} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationship.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationship.kt deleted file mode 100644 index ade7974b..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationship.kt +++ /dev/null @@ -1,10 +0,0 @@ -package dev.usbharu.hideout.core.domain.model.timelinerelationship - -import dev.usbharu.hideout.core.domain.model.actor.ActorId -import dev.usbharu.hideout.core.domain.model.instance.InstanceId - -class TimelineRelationship( - val timelineRelationshipId: TimelineRelationshipId, - val actorId: ActorId?, - val instanceId: InstanceId? -) \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipId.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipId.kt deleted file mode 100644 index 5de526a7..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipId.kt +++ /dev/null @@ -1,4 +0,0 @@ -package dev.usbharu.hideout.core.domain.model.timelinerelationship - -@JvmInline -value class TimelineRelationshipId(val value: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipRepository.kt deleted file mode 100644 index 520d6e88..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipRepository.kt +++ /dev/null @@ -1,6 +0,0 @@ -package dev.usbharu.hideout.core.domain.model.timelinerelationship - -interface TimelineRelationshipRepository { - suspend fun save(timelineRelationship: TimelineRelationship): TimelineRelationship - suspend fun delete(timelineRelationship: TimelineRelationship) -} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/timeline/TimelineStore.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/timeline/TimelineStore.kt new file mode 100644 index 00000000..4656d30a --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/timeline/TimelineStore.kt @@ -0,0 +1,7 @@ +package dev.usbharu.hideout.core.external.timeline + +import dev.usbharu.hideout.core.domain.model.post.Post + +interface TimelineStore { + suspend fun newPost(post: Post) +} \ No newline at end of file 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 c658754c..ab1349f6 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,6 +17,7 @@ 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 @@ -66,11 +67,38 @@ class ExposedRelationshipRepository(override val domainEventPublisher: DomainEve }.singleOrNull()?.toRelationships() } + override suspend fun findByTargetId(targetId: ActorId, option: FindRelationshipOption?): List { + val query = Relationships.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]), diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt index 08678b32..d831b5be 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt @@ -52,6 +52,7 @@ class PostFactoryImpl( return Post.create( id = PostId(id), actorId = actor.id, + instanceId = actor.instance, overview = overview, content = postContentFactoryImpl.create(content), createdAt = Instant.now(), diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/AbstractTimelineStore.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/AbstractTimelineStore.kt new file mode 100644 index 00000000..f9ff780c --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/AbstractTimelineStore.kt @@ -0,0 +1,19 @@ +package dev.usbharu.hideout.core.infrastructure.timeline + +import dev.usbharu.hideout.core.domain.model.post.Post +import dev.usbharu.hideout.core.domain.model.relationship.FindRelationshipOption +import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository +import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository +import dev.usbharu.hideout.core.external.timeline.TimelineStore + +abstract class AbstractTimelineStore( + private val timelineRepository: TimelineRepository, + private val relationshipRepository: RelationshipRepository +) : + TimelineStore { + override suspend fun newPost(post: Post) { + relationshipRepository.findByTargetId(post.actorId, FindRelationshipOption(follow = true, mute = false)) + } + + +} \ No newline at end of file diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostTest.kt index 7c7be023..69fb7cca 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostTest.kt @@ -312,6 +312,7 @@ class PostTest { Post.create( id = PostId(1), actorId = actor.id, + instanceId = actor.instance, overview = null, content = PostContent.empty, createdAt = Instant.now(), @@ -327,7 +328,6 @@ class PostTest { hide = false, moveTo = null, actor = actor - ) } } @@ -339,6 +339,7 @@ class PostTest { val post = Post.create( id = PostId(1), actorId = actor.id, + instanceId = actor.instance, overview = null, content = PostContent.empty, createdAt = Instant.now(), @@ -366,6 +367,7 @@ class PostTest { val post = Post.create( id = PostId(1), actorId = actor.id, + instanceId = actor.instance, overview = null, content = PostContent.empty, createdAt = Instant.now(), @@ -396,6 +398,7 @@ class PostTest { Post.create( id = PostId(1), actorId = actor.id, + instanceId = actor.instance, overview = null, content = PostContent.empty, createdAt = Instant.now(), @@ -425,6 +428,7 @@ class PostTest { Post.create( id = PostId(1), actorId = actor.id, + instanceId = actor.instance, content = PostContent.empty, createdAt = Instant.now(), visibility = Visibility.PUBLIC, @@ -447,6 +451,7 @@ class PostTest { val post = Post.create( id = PostId(1), actorId = actor.id, + instanceId = actor.instance, content = PostContent("aaa", "aaa", emojiIds), createdAt = Instant.now(), visibility = Visibility.PUBLIC, @@ -472,6 +477,7 @@ class PostTest { val post = Post.create( id = PostId(1), actorId = actor.id, + instanceId = actor.instance, content = PostContent("aaa", "aaa", emojiIds), createdAt = Instant.now(), visibility = Visibility.PUBLIC, @@ -510,6 +516,7 @@ class PostTest { val post = Post.create( id = PostId(1), actorId = actor.id, + instanceId = actor.instance, content = PostContent("aaa", "aaa", emojiIds), createdAt = Instant.now(), visibility = Visibility.PUBLIC, @@ -536,6 +543,7 @@ class PostTest { val post = Post.create( id = PostId(1), actorId = actor.id, + instanceId = actor.instance, content = PostContent("aaa", "aaa", emojiIds), createdAt = Instant.now(), visibility = Visibility.PUBLIC,