style: fix lint

This commit is contained in:
usbharu 2024-07-20 16:23:59 +09:00
parent edae599978
commit 8e84c8e59c
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
31 changed files with 80 additions and 70 deletions

View File

@ -1,4 +1,3 @@
package dev.usbharu.hideout.core.application.domainevent.subscribers package dev.usbharu.hideout.core.application.domainevent.subscribers
interface Subscriber { interface Subscriber
}

View File

@ -5,8 +5,7 @@ import org.springframework.boot.ApplicationRunner
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
@Component @Component
class SubscriberRunner(subscribers:List<Subscriber>) : ApplicationRunner { class SubscriberRunner(subscribers: List<Subscriber>) : ApplicationRunner {
override fun run(args: ApplicationArguments?) { override fun run(args: ApplicationArguments?) {
} }
} }

View File

@ -3,22 +3,20 @@ package dev.usbharu.hideout.core.application.domainevent.subscribers
import dev.usbharu.hideout.core.domain.event.post.PostEvent import dev.usbharu.hideout.core.domain.event.post.PostEvent
import dev.usbharu.hideout.core.domain.event.post.PostEventBody import dev.usbharu.hideout.core.domain.event.post.PostEventBody
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
@Component @Component
class TimelinePostCreateSubscriber(domainEventSubscriber: DomainEventSubscriber) :Subscriber{ class TimelinePostCreateSubscriber(domainEventSubscriber: DomainEventSubscriber) : Subscriber {
init { init {
domainEventSubscriber.subscribe<PostEventBody>(PostEvent.CREATE.eventName) { domainEventSubscriber.subscribe<PostEventBody>(PostEvent.CREATE.eventName) {
val post = it.body.getPost() val post = it.body.getPost()
val actor = it.body.getActor() val actor = it.body.getActor()
logger.info("New Post! : {}",post) logger.info("New Post! : {}", post)
} }
} }
companion object{ companion object {
private val logger = LoggerFactory.getLogger(TimelinePostCreateSubscriber::class.java) private val logger = LoggerFactory.getLogger(TimelinePostCreateSubscriber::class.java)
} }
} }

View File

@ -13,4 +13,4 @@ class FlywayConfig {
migrate.migrate() migrate.migrate()
} }
} }
} }

View File

@ -21,7 +21,9 @@ import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEvent
import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventBody import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventBody
class ActorInstanceRelationshipDomainEventFactory(private val actorInstanceRelationship: ActorInstanceRelationship) { class ActorInstanceRelationshipDomainEventFactory(private val actorInstanceRelationship: ActorInstanceRelationship) {
fun createEvent(actorInstanceRelationshipEvent: ActorInstanceRelationshipEvent): DomainEvent<ActorInstanceRelationshipEventBody> { fun createEvent(
actorInstanceRelationshipEvent: ActorInstanceRelationshipEvent
): DomainEvent<ActorInstanceRelationshipEventBody> {
return DomainEvent.create( return DomainEvent.create(
actorInstanceRelationshipEvent.eventName, actorInstanceRelationshipEvent.eventName,
ActorInstanceRelationshipEventBody(actorInstanceRelationship) ActorInstanceRelationshipEventBody(actorInstanceRelationship)

View File

@ -13,4 +13,4 @@ class TimelineEventBody(timeline: Timeline) : DomainEventBody(mapOf("timeline" t
enum class TimelineEvent(val eventName: String) { enum class TimelineEvent(val eventName: String) {
CHANGE_VISIBILITY("ChangeVisibility") CHANGE_VISIBILITY("ChangeVisibility")
} }

View File

@ -3,4 +3,4 @@ package dev.usbharu.hideout.core.domain.model.followtimeline
import dev.usbharu.hideout.core.domain.model.timeline.TimelineId import dev.usbharu.hideout.core.domain.model.timeline.TimelineId
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
class FollowTimeline(val userDetailId: UserDetailId, val timelineId: TimelineId) class FollowTimeline(val userDetailId: UserDetailId, val timelineId: TimelineId)

View File

@ -3,4 +3,4 @@ package dev.usbharu.hideout.core.domain.model.followtimeline
interface FollowTimelineRepository { interface FollowTimelineRepository {
suspend fun save(followTimeline: FollowTimeline): FollowTimeline suspend fun save(followTimeline: FollowTimeline): FollowTimeline
suspend fun delete(followTimeline: FollowTimeline) suspend fun delete(followTimeline: FollowTimeline)
} }

View File

@ -50,7 +50,6 @@ class Post(
moveTo: PostId?, moveTo: PostId?,
) : DomainEventStorable() { ) : DomainEventStorable() {
val actorId = actorId val actorId = actorId
get() { get() {
if (deleted) { if (deleted) {
@ -271,7 +270,6 @@ class Post(
")" ")"
} }
companion object { companion object {
@Suppress("LongParameterList") @Suppress("LongParameterList")
fun create( fun create(

View File

@ -29,11 +29,10 @@ interface RelationshipRepository {
): List<Relationship> ): List<Relationship>
} }
data class FindRelationshipOption( data class FindRelationshipOption(
val follow: Boolean? = null, val follow: Boolean? = null,
val block: Boolean? = null, val block: Boolean? = null,
val mute: Boolean? = null, val mute: Boolean? = null,
val followRequest: Boolean? = null, val followRequest: Boolean? = null,
val muteFollowRequest: Boolean? = null val muteFollowRequest: Boolean? = null
) )

View File

@ -43,4 +43,4 @@ sealed class Page {
) )
} }
} }
} }

View File

@ -1,3 +1,3 @@
package dev.usbharu.hideout.core.domain.model.support.page package dev.usbharu.hideout.core.domain.model.support.page
class PaginationList<T, ID>(list: List<T>, val next: ID?, val prev: ID?) : List<T> by list class PaginationList<T, ID>(list: List<T>, val next: ID?, val prev: ID?) : List<T> by list

View File

@ -19,4 +19,4 @@ data class PostDetail(
require(reply?.actorId == replyActor?.id) require(reply?.actorId == replyActor?.id)
require(repost?.actorId == repostActor?.id) require(repost?.actorId == repostActor?.id)
} }
} }

View File

@ -50,4 +50,4 @@ data class TimelineObjectDetail(
) )
} }
} }
} }

View File

@ -25,4 +25,4 @@ class Timeline(
var name = name var name = name
private set private set
} }

View File

@ -7,4 +7,4 @@ interface TimelineRepository {
suspend fun findByIds(ids: List<TimelineId>): List<Timeline> suspend fun findByIds(ids: List<TimelineId>): List<Timeline>
suspend fun findById(id: TimelineId): Timeline? suspend fun findById(id: TimelineId): Timeline?
} }

View File

@ -4,4 +4,4 @@ enum class TimelineVisibility {
PRIVATE, PRIVATE,
UNLISTED, UNLISTED,
PUBLIC PUBLIC
} }

View File

@ -110,7 +110,6 @@ class TimelineObject(
repost: Post, repost: Post,
filterResults: List<FilterResult> filterResults: List<FilterResult>
): TimelineObject { ): TimelineObject {
require(post.repostId == repost.id) require(post.repostId == repost.id)
return TimelineObject( return TimelineObject(
@ -138,4 +137,4 @@ class TimelineObject(
) )
} }
} }
} }

View File

@ -2,6 +2,4 @@ package dev.usbharu.hideout.core.domain.model.timelineobject
import dev.usbharu.hideout.core.domain.model.filter.FilterId import dev.usbharu.hideout.core.domain.model.filter.FilterId
class TimelineObjectWarnFilter(val filterId: FilterId, val matchedKeyword: String) { class TimelineObjectWarnFilter(val filterId: FilterId, val matchedKeyword: String)
}

View File

@ -15,4 +15,4 @@ enum class Visible {
UNLISTED, UNLISTED,
FOLLOWERS, FOLLOWERS,
DIRECT DIRECT
} }

View File

@ -7,4 +7,4 @@ interface TimelineRelationshipRepository {
suspend fun delete(timelineRelationship: TimelineRelationship) suspend fun delete(timelineRelationship: TimelineRelationship)
suspend fun findByActorId(actorId: ActorId): List<TimelineRelationship> suspend fun findByActorId(actorId: ActorId): List<TimelineRelationship>
} }

View File

@ -17,4 +17,4 @@ interface TimelineStore {
suspend fun removeTimeline(timeline: Timeline) suspend fun removeTimeline(timeline: Timeline)
suspend fun readTimeline(timeline: Timeline): List<TimelineObjectDetail> suspend fun readTimeline(timeline: Timeline): List<TimelineObjectDetail>
} }

View File

@ -171,17 +171,20 @@ class ExposedPostRepository(
} }
.let(postQueryMapper::map) .let(postQueryMapper::map)
} }
} }
override suspend fun findByActorId(id: ActorId, page: Page?): PaginationList<Post, PostId> = PaginationList(query { override suspend fun findByActorId(id: ActorId, page: Page?): PaginationList<Post, PostId> = PaginationList(
Posts query {
.selectAll() Posts
.where { .selectAll()
actorId eq actorId .where {
} actorId eq actorId
.let(postQueryMapper::map) }
}, null, null) .let(postQueryMapper::map)
},
null,
null
)
override suspend fun delete(post: Post) { override suspend fun delete(post: Post) {
query { query {
@ -197,14 +200,18 @@ class ExposedPostRepository(
visibilityList: List<Visibility>, visibilityList: List<Visibility>,
of: Page? of: Page?
): PaginationList<Post, PostId> { ): PaginationList<Post, PostId> {
return PaginationList(query { return PaginationList(
Posts query {
.selectAll() Posts
.where { .selectAll()
Posts.actorId eq actorId.id and (visibility inList visibilityList.map { it.name }) .where {
} Posts.actorId eq actorId.id and (visibility inList visibilityList.map { it.name })
.let(postQueryMapper::map) }
}, null, null) .let(postQueryMapper::map)
},
null,
null
)
} }
companion object { companion object {

View File

@ -74,7 +74,7 @@ class ExposedRelationshipRepository(override val domainEventPublisher: DomainEve
): List<Relationship> { ): List<Relationship> {
val query1 = Relationships.selectAll().where { Relationships.actorId eq targetId.id } val query1 = Relationships.selectAll().where { Relationships.actorId eq targetId.id }
inverseOption.apply(query1) inverseOption.apply(query1)
//todo 逆のほうがいいかも // todo 逆のほうがいいかも
val query = query1.alias("INV").selectAll().where { val query = query1.alias("INV").selectAll().where {
Relationships.targetActorId eq targetId.id Relationships.targetActorId eq targetId.id
} }
@ -89,7 +89,6 @@ class ExposedRelationshipRepository(override val domainEventPublisher: DomainEve
} }
fun FindRelationshipOption?.apply(query: Query) { fun FindRelationshipOption?.apply(query: Query) {
if (this?.follow != null) { if (this?.follow != null) {
query.andWhere { Relationships.following eq this@apply.follow } query.andWhere { Relationships.following eq this@apply.follow }
} }

View File

@ -65,4 +65,4 @@ object TimelineRelationships : Table("timeline_relationships") {
val actorId = long("actor_id").references(Actors.id) val actorId = long("actor_id").references(Actors.id)
val visible = varchar("visible", 100) val visible = varchar("visible", 100)
override val primaryKey: PrimaryKey = PrimaryKey(id) override val primaryKey: PrimaryKey = PrimaryKey(id)
} }

View File

@ -11,8 +11,10 @@ import org.slf4j.LoggerFactory
import org.springframework.stereotype.Repository import org.springframework.stereotype.Repository
@Repository @Repository
class ExposedTimelineRepository(override val domainEventPublisher: DomainEventPublisher) : TimelineRepository, class ExposedTimelineRepository(override val domainEventPublisher: DomainEventPublisher) :
AbstractRepository(), DomainEventPublishableRepository<Timeline> { TimelineRepository,
AbstractRepository(),
DomainEventPublishableRepository<Timeline> {
override suspend fun save(timeline: Timeline): Timeline { override suspend fun save(timeline: Timeline): Timeline {
query { query {
Timelines.insert { Timelines.insert {
@ -54,7 +56,6 @@ class ExposedTimelineRepository(override val domainEventPublisher: DomainEventPu
override val logger: Logger override val logger: Logger
get() = Companion.logger get() = Companion.logger
} }
fun ResultRow.toTimeline(): Timeline { fun ResultRow.toTimeline(): Timeline {
@ -75,4 +76,4 @@ object Timelines : Table("timelines") {
val isSystem = bool("is_system") val isSystem = bool("is_system")
override val primaryKey: PrimaryKey = PrimaryKey(id) override val primaryKey: PrimaryKey = PrimaryKey(id)
} }

View File

@ -22,7 +22,9 @@ import org.springframework.stereotype.Repository
import java.time.Instant import java.time.Instant
@Repository @Repository
class MongoInternalTimelineObjectRepository(private val springDataMongoTimelineObjectRepository: SpringDataMongoTimelineObjectRepository) : class MongoInternalTimelineObjectRepository(
private val springDataMongoTimelineObjectRepository: SpringDataMongoTimelineObjectRepository
) :
InternalTimelineObjectRepository { InternalTimelineObjectRepository {
override suspend fun save(timelineObject: TimelineObject): TimelineObject { override suspend fun save(timelineObject: TimelineObject): TimelineObject {
springDataMongoTimelineObjectRepository.save(SpringDataMongoTimelineObject.of(timelineObject)) springDataMongoTimelineObjectRepository.save(SpringDataMongoTimelineObject.of(timelineObject))
@ -55,8 +57,6 @@ class MongoInternalTimelineObjectRepository(private val springDataMongoTimelineO
return springDataMongoTimelineObjectRepository.findByTimelineId(timelineId).map { it.toTimelineObject() } return springDataMongoTimelineObjectRepository.findByTimelineId(timelineId).map { it.toTimelineObject() }
.toList() .toList()
} }
} }
@Document @Document
@ -162,4 +162,4 @@ interface SpringDataMongoTimelineObjectRepository : CoroutineCrudRepository<Spri
suspend fun deleteByTimelineId(timelineId: Long) suspend fun deleteByTimelineId(timelineId: Long)
suspend fun findByTimelineId(timelineId: TimelineId): Flow<SpringDataMongoTimelineObject> suspend fun findByTimelineId(timelineId: TimelineId): Flow<SpringDataMongoTimelineObject>
} }

View File

@ -21,8 +21,7 @@ class SpringFrameworkDomainEventSubscriber : DomainEventSubscriber {
map[domainEvent.name]?.forEach { map[domainEvent.name]?.forEach {
try { try {
it.invoke(domainEvent) it.invoke(domainEvent)
} } catch (e: Exception) {
catch (e: Exception) {
} }
} }
} }

View File

@ -72,7 +72,11 @@ abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateSe
} }
return TimelineObject.create( return TimelineObject.create(
TimelineObjectId(idGenerateService.generateId()), timeline, post, replyActorId, applyFilters.filterResults TimelineObjectId(idGenerateService.generateId()),
timeline,
post,
replyActorId,
applyFilters.filterResults
) )
} }
@ -198,12 +202,20 @@ abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateSe
val newerFilters = getNewerFilters(timeline.userDetailId, lastUpdatedAt) val newerFilters = getNewerFilters(timeline.userDetailId, lastUpdatedAt)
val posts = val posts =
getPostsByPostId(timelineObjectList.map { it.postId } + timelineObjectList.mapNotNull { it.repostId } + timelineObjectList.mapNotNull { it.replyId }) getPostsByPostId(
timelineObjectList.map {
it.postId
} + timelineObjectList.mapNotNull { it.repostId } + timelineObjectList.mapNotNull { it.replyId }
)
val userDetails = getUserDetails(timelineObjectList.map { it.userDetailId }) val userDetails = getUserDetails(timelineObjectList.map { it.userDetailId })
val actors = val actors =
getActors(timelineObjectList.map { it.postActorId } + timelineObjectList.mapNotNull { it.repostActorId } + timelineObjectList.mapNotNull { it.replyActorId }) getActors(
timelineObjectList.map {
it.postActorId
} + timelineObjectList.mapNotNull { it.repostActorId } + timelineObjectList.mapNotNull { it.replyActorId }
)
val postMap = posts.associate { post -> val postMap = posts.associate { post ->
post.id to applyFilters(post, newerFilters) post.id to applyFilters(post, newerFilters)
@ -239,4 +251,4 @@ abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateSe
abstract suspend fun getActors(actorIds: List<ActorId>): Map<ActorId, Actor> abstract suspend fun getActors(actorIds: List<ActorId>): Map<ActorId, Actor>
abstract suspend fun getUserDetails(userDetailIdList: List<UserDetailId>): Map<UserDetailId, UserDetail> abstract suspend fun getUserDetails(userDetailIdList: List<UserDetailId>): Map<UserDetailId, UserDetail>
} }

View File

@ -120,4 +120,4 @@ open class DefaultTimelineStore(
override suspend fun getUserDetails(userDetailIdList: List<UserDetailId>): Map<UserDetailId, UserDetail> { override suspend fun getUserDetails(userDetailIdList: List<UserDetailId>): Map<UserDetailId, UserDetail> {
return userDetailRepository.findAllById(userDetailIdList).associateBy { it.id } return userDetailRepository.findAllById(userDetailIdList).associateBy { it.id }
} }
} }

View File

@ -18,4 +18,4 @@ interface InternalTimelineObjectRepository {
suspend fun deleteByTimelineId(timelineId: TimelineId) suspend fun deleteByTimelineId(timelineId: TimelineId)
suspend fun findByTimelineId(timelineId: TimelineId): List<TimelineObject> suspend fun findByTimelineId(timelineId: TimelineId): List<TimelineObject>
} }