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 index 39e3eae6..316292c9 100644 --- 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 @@ -4,7 +4,7 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.timeline.TimelineId class TimelineRelationship( - val timelineRelationshipId: TimelineRelationshipId, + val id: TimelineRelationshipId, val timelineId: TimelineId, val actorId: ActorId ) \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt index 0fb4c803..fccc7166 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt @@ -17,6 +17,7 @@ package dev.usbharu.hideout.core.infrastructure.exposed 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.infrastructure.exposedrepository.Posts import org.jetbrains.exposed.sql.ResultRow @@ -29,6 +30,7 @@ class PostResultRowMapper : ResultRowMapper { return Post( id = PostId(resultRow[Posts.id]), actorId = ActorId(resultRow[Posts.actorId]), + instanceId = InstanceId(resultRow[Posts.instanceId]), overview = resultRow[Posts.overview]?.let { PostOverview(it) }, content = PostContent(resultRow[Posts.text], resultRow[Posts.content], emptyList()), createdAt = resultRow[Posts.createdAt], diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedFilterRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedFilterRepository.kt index 11e8bee1..ae06094f 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedFilterRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedFilterRepository.kt @@ -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.FilterKeywordId 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 org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq @@ -72,6 +73,10 @@ class ExposedFilterRepository(private val filterQueryMapper: QueryMapper return filterQueryMapper.map(where).firstOrNull() } + override suspend fun findByUserDetailId(userDetailId: UserDetailId): List { + return Filters.selectAll().where { Filters.userId eq userDetailId.id }.let(filterQueryMapper::map) + } + companion object { private val logger = LoggerFactory.getLogger(ExposedFilterRepository::class.java) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt index 43d63e27..d21900d6 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt @@ -186,6 +186,7 @@ class ExposedPostRepository( object Posts : Table("posts") { val id = long("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 content = varchar("content", PostContent.CONTENT_LENGTH) val text = varchar("text", PostContent.TEXT_LENGTH) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRelationshipRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRelationshipRepository.kt new file mode 100644 index 00000000..681593ae --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRelationshipRepository.kt @@ -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 { + 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) +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt new file mode 100644 index 00000000..0647d3ea --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt @@ -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 { + 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): List { + 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) +} \ No newline at end of file