mirror of https://github.com/usbharu/Hideout.git
feat: DefaultTimelineStore
This commit is contained in:
parent
b4c62fbd43
commit
3057d9cc5a
|
@ -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
|
||||
)
|
|
@ -5,4 +5,6 @@ interface TimelineRepository {
|
|||
suspend fun delete(timeline: Timeline)
|
||||
|
||||
suspend fun findByIds(ids: List<TimelineId>): List<Timeline>
|
||||
|
||||
suspend fun findById(id: TimelineId): Timeline?
|
||||
}
|
|
@ -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<Timeline>
|
||||
protected abstract suspend fun getTimelines(actorId: ActorId): List<Timeline>
|
||||
|
||||
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<TimelineRelationship>): List<Post>
|
||||
|
||||
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<Post>
|
||||
|
||||
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<TimelineRelationship>) {
|
||||
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)
|
||||
}
|
||||
}
|
|
@ -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<Timeline> {
|
||||
override suspend fun getTimelines(actorId: ActorId): List<Timeline> {
|
||||
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<Filter> {
|
||||
return filterRepository.findByUserDetailId(userDetailId)
|
||||
}
|
||||
|
@ -50,4 +58,28 @@ open class DefaultTimelineStore(
|
|||
override suspend fun insertTimelineObject(timelineObjectList: List<TimelineObject>) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun getTimelineObjectByPostId(postId: PostId): List<TimelineObject> {
|
||||
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<TimelineRelationship>): List<Post> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun getActorPost(actorId: ActorId): List<Post> {
|
||||
postRepository.findByActorId()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue