From 3057d9cc5af092e9f7c70181002aed94d82c2a36 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 19 Jul 2024 23:49:14 +0900 Subject: [PATCH] feat: DefaultTimelineStore --- .../core/config/DefaultTimelineStoreConfig.kt | 8 +++ .../model/timeline/TimelineRepository.kt | 2 + .../timeline/AbstractTimelineStore.kt | 50 +++++++++++++------ .../timeline/DefaultTimelineStore.kt | 36 ++++++++++++- 4 files changed, 78 insertions(+), 18 deletions(-) create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/DefaultTimelineStoreConfig.kt diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/DefaultTimelineStoreConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/DefaultTimelineStoreConfig.kt new file mode 100644 index 00000000..a6db6b29 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/DefaultTimelineStoreConfig.kt @@ -0,0 +1,8 @@ +package dev.usbharu.hideout.core.config + +import org.springframework.boot.context.properties.ConfigurationProperties + +@ConfigurationProperties("hideout.timeline.default") +data class DefaultTimelineStoreConfig( + val actorPostsCount: Int = 500 +) 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 823a0c68..a2d484b6 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 @@ -5,4 +5,6 @@ interface TimelineRepository { suspend fun delete(timeline: Timeline) suspend fun findByIds(ids: List): List + + suspend fun findById(id: TimelineId): Timeline? } \ No newline at end of file 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 index 00ac8985..273d993d 100644 --- 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 @@ -6,6 +6,7 @@ import dev.usbharu.hideout.core.domain.model.filter.FilteredPost import dev.usbharu.hideout.core.domain.model.post.Post import dev.usbharu.hideout.core.domain.model.post.PostId import dev.usbharu.hideout.core.domain.model.timeline.Timeline +import dev.usbharu.hideout.core.domain.model.timeline.TimelineId import dev.usbharu.hideout.core.domain.model.timelineobject.TimelineObject import dev.usbharu.hideout.core.domain.model.timelineobject.TimelineObjectId import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationship @@ -15,7 +16,7 @@ import dev.usbharu.hideout.core.external.timeline.TimelineStore abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateService) : TimelineStore { override suspend fun addPost(post: Post) { - val timelineList = getTimeline(post.actorId) + val timelineList = getTimelines(post.actorId) val repost = post.repostId?.let { getPost(it) } @@ -26,7 +27,9 @@ abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateSe insertTimelineObject(timelineObjectList) } - protected abstract suspend fun getTimeline(actorId: ActorId): List + protected abstract suspend fun getTimelines(actorId: ActorId): List + + protected abstract suspend fun getTimeline(timelineId: TimelineId): Timeline? protected suspend fun createTimelineObject(post: Post, repost: Post?, timeline: Timeline): TimelineObject { val filters = getFilters(timeline.userDetailId) @@ -35,19 +38,12 @@ abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateSe if (repost != null) { return TimelineObject.create( - TimelineObjectId(idGenerateService.generateId()), - timeline, - post, - repost, - applyFilters.filterResults + TimelineObjectId(idGenerateService.generateId()), timeline, post, repost, applyFilters.filterResults ) } return TimelineObject.create( - TimelineObjectId(idGenerateService.generateId()), - timeline, - post, - applyFilters.filterResults + TimelineObjectId(idGenerateService.generateId()), timeline, post, applyFilters.filterResults ) } @@ -63,6 +59,12 @@ abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateSe protected abstract suspend fun removeTimelineObject(postId: PostId) + protected abstract suspend fun removeTimelineObject(timelineId: TimelineId, actorId: ActorId) + + protected abstract suspend fun removeTimelineObject(timelineId: TimelineId) + + protected abstract suspend fun getPosts(timelineRelationshipList: List): List + override suspend fun updatePost(post: Post) { @@ -79,23 +81,39 @@ abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateSe } } + protected abstract suspend fun getActorPost(actorId: ActorId): List + override suspend fun removePost(post: Post) { - TODO("Not yet implemented") + removeTimelineObject(post.id) } override suspend fun addTimelineRelationship(timelineRelationship: TimelineRelationship) { - TODO("Not yet implemented") + val postList = getActorPost(timelineRelationship.actorId) + val timeline = getTimeline(timelineRelationship.timelineId) ?: return + val timelineObjects = postList.map { post -> + val repost = post.repostId?.let { getPost(it) } + createTimelineObject(post, repost, timeline) + } + + insertTimelineObject(timelineObjects) } override suspend fun removeTimelineRelationship(timelineRelationship: TimelineRelationship) { - TODO("Not yet implemented") + removeTimelineObject(timelineRelationship.timelineId, timelineRelationship.actorId) } override suspend fun addTimeline(timeline: Timeline, timelineRelationshipList: List) { - TODO("Not yet implemented") + val postList = getPosts(timelineRelationshipList) + + val timelineObjectList = postList.map { post -> + val repost = post.repostId?.let { getPost(it) } + createTimelineObject(post, repost, timeline) + } + + insertTimelineObject(timelineObjectList) } override suspend fun removeTimeline(timeline: Timeline) { - TODO("Not yet implemented") + removeTimelineObject(timeline.id) } } \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/DefaultTimelineStore.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/DefaultTimelineStore.kt index d0a2188e..e8c542ed 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/DefaultTimelineStore.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/DefaultTimelineStore.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.core.infrastructure.timeline +import dev.usbharu.hideout.core.config.DefaultTimelineStoreConfig import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.filter.Filter import dev.usbharu.hideout.core.domain.model.filter.FilterContext @@ -9,8 +10,10 @@ import dev.usbharu.hideout.core.domain.model.post.Post import dev.usbharu.hideout.core.domain.model.post.PostId import dev.usbharu.hideout.core.domain.model.post.PostRepository import dev.usbharu.hideout.core.domain.model.timeline.Timeline +import dev.usbharu.hideout.core.domain.model.timeline.TimelineId import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository import dev.usbharu.hideout.core.domain.model.timelineobject.TimelineObject +import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationship import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationshipRepository import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId import dev.usbharu.hideout.core.domain.service.filter.FilterDomainService @@ -24,9 +27,10 @@ open class DefaultTimelineStore( private val filterRepository: FilterRepository, private val postRepository: PostRepository, private val filterDomainService: FilterDomainService, - idGenerateService: IdGenerateService + idGenerateService: IdGenerateService, + private val defaultTimelineStoreConfig: DefaultTimelineStoreConfig ) : AbstractTimelineStore(idGenerateService) { - override suspend fun getTimeline(actorId: ActorId): List { + override suspend fun getTimelines(actorId: ActorId): List { return timelineRepository.findByIds( timelineRelationshipRepository .findByActorId( @@ -35,6 +39,10 @@ open class DefaultTimelineStore( ) } + override suspend fun getTimeline(timelineId: TimelineId): Timeline? { + return timelineRepository.findById(timelineId) + } + override suspend fun getFilters(userDetailId: UserDetailId): List { return filterRepository.findByUserDetailId(userDetailId) } @@ -50,4 +58,28 @@ open class DefaultTimelineStore( override suspend fun insertTimelineObject(timelineObjectList: List) { TODO("Not yet implemented") } + + override suspend fun getTimelineObjectByPostId(postId: PostId): List { + TODO("Not yet implemented") + } + + override suspend fun removeTimelineObject(postId: PostId) { + TODO("Not yet implemented") + } + + override suspend fun removeTimelineObject(timelineId: TimelineId, actorId: ActorId) { + TODO("Not yet implemented") + } + + override suspend fun removeTimelineObject(timelineId: TimelineId) { + TODO("Not yet implemented") + } + + override suspend fun getPosts(timelineRelationshipList: List): List { + TODO("Not yet implemented") + } + + override suspend fun getActorPost(actorId: ActorId): List { + postRepository.findByActorId() + } } \ No newline at end of file