feat: タイムラインを実装

This commit is contained in:
usbharu 2024-07-14 21:11:22 +09:00
parent a550ddd5c3
commit 5303b13b08
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
6 changed files with 145 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.timeline.TimelineId import dev.usbharu.hideout.core.domain.model.timeline.TimelineId
class TimelineRelationship( class TimelineRelationship(
val timelineRelationshipId: TimelineRelationshipId, val id: TimelineRelationshipId,
val timelineId: TimelineId, val timelineId: TimelineId,
val actorId: ActorId val actorId: ActorId
) )

View File

@ -17,6 +17,7 @@
package dev.usbharu.hideout.core.infrastructure.exposed package dev.usbharu.hideout.core.infrastructure.exposed
import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.instance.InstanceId
import dev.usbharu.hideout.core.domain.model.post.* import dev.usbharu.hideout.core.domain.model.post.*
import dev.usbharu.hideout.core.infrastructure.exposedrepository.Posts import dev.usbharu.hideout.core.infrastructure.exposedrepository.Posts
import org.jetbrains.exposed.sql.ResultRow import org.jetbrains.exposed.sql.ResultRow
@ -29,6 +30,7 @@ class PostResultRowMapper : ResultRowMapper<Post> {
return Post( return Post(
id = PostId(resultRow[Posts.id]), id = PostId(resultRow[Posts.id]),
actorId = ActorId(resultRow[Posts.actorId]), actorId = ActorId(resultRow[Posts.actorId]),
instanceId = InstanceId(resultRow[Posts.instanceId]),
overview = resultRow[Posts.overview]?.let { PostOverview(it) }, overview = resultRow[Posts.overview]?.let { PostOverview(it) },
content = PostContent(resultRow[Posts.text], resultRow[Posts.content], emptyList()), content = PostContent(resultRow[Posts.text], resultRow[Posts.content], emptyList()),
createdAt = resultRow[Posts.createdAt], createdAt = resultRow[Posts.createdAt],

View File

@ -20,6 +20,7 @@ import dev.usbharu.hideout.core.domain.model.filter.Filter
import dev.usbharu.hideout.core.domain.model.filter.FilterId import dev.usbharu.hideout.core.domain.model.filter.FilterId
import dev.usbharu.hideout.core.domain.model.filter.FilterKeywordId import dev.usbharu.hideout.core.domain.model.filter.FilterKeywordId
import dev.usbharu.hideout.core.domain.model.filter.FilterRepository import dev.usbharu.hideout.core.domain.model.filter.FilterRepository
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import dev.usbharu.hideout.core.infrastructure.exposed.QueryMapper import dev.usbharu.hideout.core.infrastructure.exposed.QueryMapper
import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
@ -72,6 +73,10 @@ class ExposedFilterRepository(private val filterQueryMapper: QueryMapper<Filter>
return filterQueryMapper.map(where).firstOrNull() return filterQueryMapper.map(where).firstOrNull()
} }
override suspend fun findByUserDetailId(userDetailId: UserDetailId): List<Filter> {
return Filters.selectAll().where { Filters.userId eq userDetailId.id }.let(filterQueryMapper::map)
}
companion object { companion object {
private val logger = LoggerFactory.getLogger(ExposedFilterRepository::class.java) private val logger = LoggerFactory.getLogger(ExposedFilterRepository::class.java)
} }

View File

@ -186,6 +186,7 @@ class ExposedPostRepository(
object Posts : Table("posts") { object Posts : Table("posts") {
val id = long("id") val id = long("id")
val actorId = long("actor_id").references(Actors.id) val actorId = long("actor_id").references(Actors.id)
val instanceId = long("instance_id").references(Instance.id)
val overview = varchar("overview", PostOverview.LENGTH).nullable() val overview = varchar("overview", PostOverview.LENGTH).nullable()
val content = varchar("content", PostContent.CONTENT_LENGTH) val content = varchar("content", PostContent.CONTENT_LENGTH)
val text = varchar("text", PostContent.TEXT_LENGTH) val text = varchar("text", PostContent.TEXT_LENGTH)

View File

@ -0,0 +1,64 @@
package dev.usbharu.hideout.core.infrastructure.exposedrepository
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.timeline.TimelineId
import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationship
import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationshipId
import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationshipRepository
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Repository
@Repository
class ExposedTimelineRelationshipRepository : AbstractRepository(), TimelineRelationshipRepository {
override val logger: Logger
get() = Companion.logger
override suspend fun save(timelineRelationship: TimelineRelationship): TimelineRelationship {
query {
TimelineRelationships.insert {
it[id] = timelineRelationship.id.value
it[timelineId] = timelineRelationship.timelineId.value
it[actorId] = timelineRelationship.actorId.id
}
}
return timelineRelationship
}
override suspend fun delete(timelineRelationship: TimelineRelationship) {
query {
TimelineRelationships.deleteWhere {
TimelineRelationships.id eq timelineRelationship.id.value
}
}
}
override suspend fun findByActorId(actorId: ActorId): List<TimelineRelationship> {
return query {
TimelineRelationships.selectAll().where {
TimelineRelationships.actorId eq actorId.id
}.map { it.toTimelineRelationship() }
}
}
companion object {
private val logger = LoggerFactory.getLogger(ExposedTimelineRelationshipRepository::class.java)
}
}
fun ResultRow.toTimelineRelationship(): TimelineRelationship {
return TimelineRelationship(
TimelineRelationshipId(this[TimelineRelationships.id]),
TimelineId(this[TimelineRelationships.timelineId]),
ActorId(this[TimelineRelationships.actorId]),
)
}
object TimelineRelationships : Table("timeline_relationships") {
val id = long("id")
val timelineId = long("timeline_id").references(Timelines.id)
val actorId = long("actor_id").references(Actors.id)
override val primaryKey: PrimaryKey = PrimaryKey(id)
}

View File

@ -0,0 +1,72 @@
package dev.usbharu.hideout.core.infrastructure.exposedrepository
import dev.usbharu.hideout.core.domain.model.timeline.*
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventPublisher
import dev.usbharu.hideout.core.domain.shared.repository.DomainEventPublishableRepository
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Repository
@Repository
class ExposedTimelineRepository(override val domainEventPublisher: DomainEventPublisher) : TimelineRepository,
AbstractRepository(), DomainEventPublishableRepository<Timeline> {
override suspend fun save(timeline: Timeline): Timeline {
query {
Timelines.insert {
it[id] = timeline.id.value
it[userDetailId] = timeline.userDetailId.id
it[name] = timeline.name.value
it[visibility] = timeline.visibility.name
it[isSystem] = timeline.isSystem
}
}
update(timeline)
return timeline
}
override suspend fun delete(timeline: Timeline) {
query {
Timelines.deleteWhere {
Timelines.id eq timeline.id.value
}
}
update(timeline)
}
override suspend fun findByIds(ids: List<TimelineId>): List<Timeline> {
return query {
Timelines.selectAll().where { Timelines.id inList ids.map { it.value } }.map { it.toTimeline() }
}
}
companion object {
private val logger = LoggerFactory.getLogger(ExposedTimelineRepository::class.java.name)
}
override val logger: Logger
get() = Companion.logger
}
fun ResultRow.toTimeline(): Timeline {
return Timeline(
TimelineId(this[Timelines.id]),
UserDetailId(this[Timelines.userDetailId]),
TimelineName(this[Timelines.name]),
TimelineVisibility.valueOf(this[Timelines.visibility]),
this[Timelines.isSystem]
)
}
object Timelines : Table("timelines") {
val id = long("id")
val userDetailId = long("user_detail_id").references(UserDetails.id)
val name = varchar("name", 300)
val visibility = varchar("visibility", 100)
val isSystem = bool("is_system")
override val primaryKey: PrimaryKey = PrimaryKey(id)
}