From c866705b926c1bc57e40ca9a041a7ada2597766c Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Mon, 17 Jun 2024 22:47:36 +0900 Subject: [PATCH] style: fix lint --- detekt.yml | 2 + .../actor/GetUserDetailApplicationService.kt | 8 ++-- .../UserDeleteFilterApplicationService.kt | 8 ++-- .../UserRegisterFilterApplicationService.kt | 8 ++-- .../media/UploadMediaApplicationService.kt | 8 ++-- .../RegisterLocalPostApplicationService.kt | 8 ++-- ...erAcceptFollowRequestApplicationService.kt | 8 ++-- .../block/UserBlockApplicationService.kt | 8 ++-- .../get/GetRelationshipApplicationService.kt | 8 ++-- .../mute/UserMuteApplicationService.kt | 8 ++-- ...erRejectFollowRequestApplicationService.kt | 8 ++-- ...erRemoveFromFollowersApplicationService.kt | 8 ++-- .../unblock/UserUnblockApplicationService.kt | 8 ++-- .../UserUnfollowApplicationService.kt | 8 ++-- .../hideout/core/config/SecurityConfig.kt | 15 +++---- .../event/relationship/RelationshipEvent.kt | 5 +-- .../hideout/core/domain/model/actor/Actor.kt | 4 +- .../domain/model/actor/ActorDescription.kt | 4 +- .../core/domain/model/actor/ActorName.kt | 6 +-- .../domain/model/actor/ActorScreenName.kt | 4 +- .../core/domain/model/filter/FilterKeyword.kt | 12 +----- .../core/domain/model/instance/Instance.kt | 4 +- .../hideout/core/domain/model/post/Post.kt | 2 +- .../domain/model/relationship/Relationship.kt | 1 + .../exposed/ActorQueryMapper.kt | 21 +++++----- .../exposed/FilterResultRowMapper.kt | 14 ++++--- .../infrastructure/exposed/PostQueryMapper.kt | 40 ++++++++++--------- .../ExposedActorRepository.kt | 6 +-- .../ExposedFilterRepository.kt | 12 +++--- .../infrastructure/factory/PostFactoryImpl.kt | 1 + .../media/video/FFmpegVideoProcessor.kt | 1 + .../domain/model/actor/ActorScreenNameTest.kt | 2 +- 32 files changed, 129 insertions(+), 131 deletions(-) diff --git a/detekt.yml b/detekt.yml index cb59ca02..1f64f96f 100644 --- a/detekt.yml +++ b/detekt.yml @@ -133,6 +133,8 @@ naming: - "**/test/**" FunctionMinLength: + ignoreFunction: + - of active: true LambdaParameterNaming: diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/GetUserDetailApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/GetUserDetailApplicationService.kt index e3b3b3d8..b53c99d5 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/GetUserDetailApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/GetUserDetailApplicationService.kt @@ -33,10 +33,6 @@ class GetUserDetailApplicationService( transaction: Transaction, ) : AbstractApplicationService(transaction, Companion.logger) { - companion object { - val logger = LoggerFactory.getLogger(GetUserDetailApplicationService::class.java) - } - override suspend fun internalExecute(command: GetUserDetail, executor: CommandExecutor): UserDetail { val userDetail = userDetailRepository.findById(command.id) ?: throw IllegalArgumentException("actor does not exist") @@ -46,4 +42,8 @@ class GetUserDetailApplicationService( return UserDetail.of(actor, userDetail, emojis) } + + companion object { + val logger = LoggerFactory.getLogger(GetUserDetailApplicationService::class.java) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserDeleteFilterApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserDeleteFilterApplicationService.kt index 2e28d5d0..a32cd686 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserDeleteFilterApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserDeleteFilterApplicationService.kt @@ -30,12 +30,12 @@ class UserDeleteFilterApplicationService(private val filterRepository: FilterRep transaction, logger ) { - companion object { - private val logger = LoggerFactory.getLogger(UserDeleteFilterApplicationService::class.java) - } - override suspend fun internalExecute(command: DeleteFilter, executor: CommandExecutor) { val filter = filterRepository.findByFilterId(FilterId(command.filterId)) ?: throw Exception("not found") filterRepository.delete(filter) } + + companion object { + private val logger = LoggerFactory.getLogger(UserDeleteFilterApplicationService::class.java) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserRegisterFilterApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserRegisterFilterApplicationService.kt index ac7a1309..4a71681a 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserRegisterFilterApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/filter/UserRegisterFilterApplicationService.kt @@ -38,10 +38,6 @@ class UserRegisterFilterApplicationService( logger ) { - companion object { - private val logger = LoggerFactory.getLogger(UserRegisterFilterApplicationService::class.java) - } - override suspend fun internalExecute(command: RegisterFilter, executor: CommandExecutor): Filter { require(executor is UserDetailGettableCommandExecutor) @@ -64,4 +60,8 @@ class UserRegisterFilterApplicationService( filterRepository.save(filter) return Filter.of(filter) } + + companion object { + private val logger = LoggerFactory.getLogger(UserRegisterFilterApplicationService::class.java) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/media/UploadMediaApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/media/UploadMediaApplicationService.kt index e3ba618e..22c0bc67 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/media/UploadMediaApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/media/UploadMediaApplicationService.kt @@ -39,10 +39,6 @@ class UploadMediaApplicationService( transaction, logger ) { - companion object { - private val logger = LoggerFactory.getLogger(UploadMediaApplicationService::class.java) - } - override suspend fun internalExecute(command: UploadMedia, executor: CommandExecutor): Media { val process = mediaProcessor.process(command.path, command.name, null) val id = idGenerateService.generateId() @@ -69,4 +65,8 @@ class UploadMediaApplicationService( return Media.of(media) } + + companion object { + private val logger = LoggerFactory.getLogger(UploadMediaApplicationService::class.java) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationService.kt index 181951b6..bc38e59a 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/RegisterLocalPostApplicationService.kt @@ -39,10 +39,6 @@ class RegisterLocalPostApplicationService( transaction: Transaction, ) : AbstractApplicationService(transaction, Companion.logger) { - companion object { - val logger: Logger = LoggerFactory.getLogger(RegisterLocalPostApplicationService::class.java) - } - override suspend fun internalExecute(command: RegisterLocalPost, executor: CommandExecutor): Long { val actorId = ( userDetailRepository.findById(command.userDetailId) @@ -67,4 +63,8 @@ class RegisterLocalPostApplicationService( return post.id.id } + + companion object { + val logger: Logger = LoggerFactory.getLogger(RegisterLocalPostApplicationService::class.java) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/UserAcceptFollowRequestApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/UserAcceptFollowRequestApplicationService.kt index 1d4a3569..e5f51fc4 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/UserAcceptFollowRequestApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/acceptfollowrequest/UserAcceptFollowRequestApplicationService.kt @@ -36,10 +36,6 @@ class UserAcceptFollowRequestApplicationService( private val userDetailRepository: UserDetailRepository, ) : AbstractApplicationService(transaction, logger) { - companion object { - private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) - } - override suspend fun internalExecute(command: AcceptFollowRequest, executor: CommandExecutor) { require(executor is UserDetailGettableCommandExecutor) @@ -55,4 +51,8 @@ class UserAcceptFollowRequestApplicationService( relationshipRepository.save(relationship) } + + companion object { + private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/block/UserBlockApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/block/UserBlockApplicationService.kt index e6d7e416..ee1dc7a9 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/block/UserBlockApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/block/UserBlockApplicationService.kt @@ -38,10 +38,6 @@ class UserBlockApplicationService( private val relationshipDomainService: RelationshipDomainService, ) : AbstractApplicationService(transaction, logger) { - companion object { - private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) - } - override suspend fun internalExecute(command: Block, executor: CommandExecutor) { require(executor is UserDetailGettableCommandExecutor) @@ -65,4 +61,8 @@ class UserBlockApplicationService( relationshipRepository.save(relationship) relationshipRepository.save(inverseRelationship) } + + companion object { + private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationshipApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationshipApplicationService.kt index 809f15b2..1a0261f7 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationshipApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/get/GetRelationshipApplicationService.kt @@ -41,10 +41,6 @@ class GetRelationshipApplicationService( transaction, logger ) { - companion object { - private val logger = LoggerFactory.getLogger(GetRelationshipApplicationService::class.java) - } - override suspend fun internalExecute(command: GetRelationship, executor: CommandExecutor): Relationship { require(executor is UserDetailGettableCommandExecutor) val userDetail = userDetailRepository.findById(executor.userDetailId)!! @@ -70,4 +66,8 @@ class GetRelationshipApplicationService( return Relationship.of(relationship, relationship1, actorInstanceRelationship) } + + companion object { + private val logger = LoggerFactory.getLogger(GetRelationshipApplicationService::class.java) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/mute/UserMuteApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/mute/UserMuteApplicationService.kt index c3cafb42..5716181f 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/mute/UserMuteApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/mute/UserMuteApplicationService.kt @@ -37,10 +37,6 @@ class UserMuteApplicationService( private val userDetailRepository: UserDetailRepository, ) : AbstractApplicationService(transaction, logger) { - companion object { - private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) - } - override suspend fun internalExecute(command: Mute, executor: CommandExecutor) { require(executor is UserDetailGettableCommandExecutor) @@ -57,4 +53,8 @@ class UserMuteApplicationService( relationshipRepository.save(relationship) } + + companion object { + private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/UserRejectFollowRequestApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/UserRejectFollowRequestApplicationService.kt index dd597e39..fd30b2f0 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/UserRejectFollowRequestApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/UserRejectFollowRequestApplicationService.kt @@ -36,10 +36,6 @@ class UserRejectFollowRequestApplicationService( private val userDetailRepository: UserDetailRepository, ) : AbstractApplicationService(transaction, logger) { - companion object { - private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) - } - override suspend fun internalExecute(command: RejectFollowRequest, executor: CommandExecutor) { require(executor is UserDetailGettableCommandExecutor) @@ -55,4 +51,8 @@ class UserRejectFollowRequestApplicationService( relationshipRepository.save(relationship) } + + companion object { + private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/removefromfollowers/UserRemoveFromFollowersApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/removefromfollowers/UserRemoveFromFollowersApplicationService.kt index 122e6a59..56f4efe7 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/removefromfollowers/UserRemoveFromFollowersApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/removefromfollowers/UserRemoveFromFollowersApplicationService.kt @@ -37,10 +37,6 @@ class UserRemoveFromFollowersApplicationService( private val userDetailRepository: UserDetailRepository, ) : AbstractApplicationService(transaction, logger) { - companion object { - private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) - } - override suspend fun internalExecute(command: RemoveFromFollowers, executor: CommandExecutor) { require(executor is UserDetailGettableCommandExecutor) @@ -57,4 +53,8 @@ class UserRemoveFromFollowersApplicationService( relationshipRepository.save(relationship) } + + companion object { + private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unblock/UserUnblockApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unblock/UserUnblockApplicationService.kt index 9de1ea7a..529b0c16 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unblock/UserUnblockApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unblock/UserUnblockApplicationService.kt @@ -37,10 +37,6 @@ class UserUnblockApplicationService( private val userDetailRepository: UserDetailRepository, ) : AbstractApplicationService(transaction, logger) { - companion object { - private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) - } - override suspend fun internalExecute(command: Unblock, executor: CommandExecutor) { require(executor is UserDetailGettableCommandExecutor) @@ -57,4 +53,8 @@ class UserUnblockApplicationService( relationshipRepository.save(relationship) } + + companion object { + private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unfollow/UserUnfollowApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unfollow/UserUnfollowApplicationService.kt index 4228b293..32db9448 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unfollow/UserUnfollowApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unfollow/UserUnfollowApplicationService.kt @@ -37,10 +37,6 @@ class UserUnfollowApplicationService( private val userDetailRepository: UserDetailRepository, ) : AbstractApplicationService(transaction, logger) { - companion object { - private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) - } - override suspend fun internalExecute(command: Unfollow, executor: CommandExecutor) { require(executor is UserDetailGettableCommandExecutor) @@ -57,4 +53,8 @@ class UserUnfollowApplicationService( relationshipRepository.save(relationship) } + + companion object { + private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt index f32b4d9d..17320fb8 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt @@ -55,9 +55,7 @@ import org.springframework.security.web.authentication.LoginUrlAuthenticationEnt @EnableWebSecurity(debug = true) class SecurityConfig { @Bean - fun passwordEncoder(): PasswordEncoder { - return BCryptPasswordEncoder() - } + fun passwordEncoder(): PasswordEncoder = BCryptPasswordEncoder() @Bean @Order(1) @@ -93,17 +91,16 @@ class SecurityConfig { } @Bean - fun registeredClientRepository(jdbcOperations: JdbcOperations): RegisteredClientRepository { - return JdbcRegisteredClientRepository(jdbcOperations) - } + fun registeredClientRepository(jdbcOperations: JdbcOperations): RegisteredClientRepository = + JdbcRegisteredClientRepository(jdbcOperations) @Bean + @Suppress("FunctionMaxLength") fun oauth2AuthorizationConsentService( jdbcOperations: JdbcOperations, registeredClientRepository: RegisteredClientRepository, - ): OAuth2AuthorizationConsentService { - return JdbcOAuth2AuthorizationConsentService(jdbcOperations, registeredClientRepository) - } + ): OAuth2AuthorizationConsentService = + JdbcOAuth2AuthorizationConsentService(jdbcOperations, registeredClientRepository) @Bean fun authorizationServerSettings(): AuthorizationServerSettings { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/relationship/RelationshipEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/relationship/RelationshipEvent.kt index 89adf3e8..da9345b1 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/relationship/RelationshipEvent.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/relationship/RelationshipEvent.kt @@ -21,9 +21,8 @@ import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEvent import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventBody class RelationshipEventFactory(private val relationship: Relationship) { - fun createEvent(relationshipEvent: RelationshipEvent): DomainEvent { - return DomainEvent.create(relationshipEvent.eventName, RelationshipEventBody(relationship)) - } + fun createEvent(relationshipEvent: RelationshipEvent): DomainEvent = + DomainEvent.create(relationshipEvent.eventName, RelationshipEventBody(relationship)) } class RelationshipEventBody(relationship: Relationship) : DomainEventBody(mapOf("relationship" to relationship)) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt index 45d34c4d..283972de 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt @@ -26,7 +26,7 @@ import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventStorable import java.net.URI import java.time.Instant -@Suppress("LongParameterList") +@Suppress("LongParameterList", "ClassOrdering") class Actor( val id: ActorId, val name: ActorName, @@ -96,7 +96,7 @@ class Actor( var alsoKnownAs = alsoKnownAs set(value) { - require(value.find { it == id } == null) + require(value.any { it == id }) field = value } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorDescription.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorDescription.kt index 740e34d5..84c60eff 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorDescription.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorDescription.kt @@ -17,10 +17,10 @@ package dev.usbharu.hideout.core.domain.model.actor class ActorDescription(description: String) { - val description: String = description.take(length) + val description: String = description.take(LENGTH) companion object { - val length = 10000 + const val LENGTH = 10000 val empty = ActorDescription("") } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorName.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorName.kt index 6819fc8e..a2e6697e 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorName.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorName.kt @@ -20,12 +20,12 @@ package dev.usbharu.hideout.core.domain.model.actor value class ActorName(val name: String) { init { require(name.isNotBlank()) - require(name.length <= length) + require(name.length <= LENGTH) require(regex.matches(name)) } companion object { - val length = 300 - private val regex = Regex("^[a-zA-Z0-9_-]{1,$length}\$") + const val LENGTH = 300 + private val regex = Regex("^[a-zA-Z0-9_-]{1,$LENGTH}\$") } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorScreenName.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorScreenName.kt index 30b4aff3..57866d77 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorScreenName.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorScreenName.kt @@ -18,10 +18,10 @@ package dev.usbharu.hideout.core.domain.model.actor class ActorScreenName(screenName: String) { - val screenName: String = screenName.take(length) + val screenName: String = screenName.take(LENGTH) companion object { - val length = 300 + const val LENGTH = 300 val empty = ActorScreenName("") } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterKeyword.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterKeyword.kt index 0e8774ba..333eb8ae 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterKeyword.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/FilterKeyword.kt @@ -1,17 +1,7 @@ package dev.usbharu.hideout.core.domain.model.filter -import dev.usbharu.hideout.core.domain.model.filter.FilterMode.* - class FilterKeyword( val id: FilterKeywordId, var keyword: FilterKeywordKeyword, val mode: FilterMode -) { - fun match(string: String): Boolean { - when (mode) { - WHOLE_WORD -> TODO() - REGEX -> TODO() - NONE -> TODO() - } - } -} +) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Instance.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Instance.kt index 4bda1989..2d3a6dbd 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Instance.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Instance.kt @@ -53,7 +53,5 @@ class Instance( return id == other.id } - override fun hashCode(): Int { - return id.hashCode() - } + override fun hashCode(): Int = id.hashCode() } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt index 9bf9211c..396bff5d 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt @@ -28,7 +28,7 @@ import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventStorable import java.net.URI import java.time.Instant -@Suppress("LongParameterList", "TooManyFunctions") +@Suppress("LongParameterList", "TooManyFunctions", "ClassOrdering") class Post( val id: PostId, actorId: ActorId, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt index 068de901..af32b48d 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/Relationship.kt @@ -21,6 +21,7 @@ import dev.usbharu.hideout.core.domain.event.relationship.RelationshipEventFacto import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventStorable +@Suppress("TooManyFunctions") class Relationship( val actorId: ActorId, val targetActorId: ActorId, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/ActorQueryMapper.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/ActorQueryMapper.kt index 8b8e46e8..e3bcab78 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/ActorQueryMapper.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/ActorQueryMapper.kt @@ -35,17 +35,20 @@ class ActorQueryMapper(private val actorResultRowMapper: ResultRowMapper) .first() .let(actorResultRowMapper::map) .apply { - alsoKnownAs = it.mapNotNull { resultRow: ResultRow -> - resultRow.getOrNull( - ActorsAlsoKnownAs.alsoKnownAs - )?.let { actorId -> - ActorId( - actorId - ) - } - }.toSet() + alsoKnownAs = buildAlsoKnownAs(it) clearDomainEvents() } } } + + private fun buildAlsoKnownAs(it: List) = + it.mapNotNull { resultRow: ResultRow -> + resultRow.getOrNull( + ActorsAlsoKnownAs.alsoKnownAs + )?.let { actorId -> + ActorId( + actorId + ) + } + }.toSet() } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/FilterResultRowMapper.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/FilterResultRowMapper.kt index e668f045..5b18bb91 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/FilterResultRowMapper.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/FilterResultRowMapper.kt @@ -25,11 +25,13 @@ import org.springframework.stereotype.Component @Component class FilterResultRowMapper : ResultRowMapper { override fun map(resultRow: ResultRow): Filter = Filter( - FilterId(resultRow[Filters.id]), - UserDetailId(resultRow[Filters.userId]), - FilterName(resultRow[Filters.name]), - resultRow[Filters.context].split(",").filter { it.isNotEmpty() }.map { FilterContext.valueOf(it) }.toSet(), - FilterAction.valueOf(resultRow[Filters.filterAction]), - emptySet() + id = FilterId(resultRow[Filters.id]), + userDetailId = UserDetailId(resultRow[Filters.userId]), + name = FilterName(resultRow[Filters.name]), + filterContext = resultRow[Filters.context].split(",").filter { + it.isNotEmpty() + }.map { FilterContext.valueOf(it) }.toSet(), + filterAction = FilterAction.valueOf(resultRow[Filters.filterAction]), + filterKeywords = emptySet() ) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostQueryMapper.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostQueryMapper.kt index 1ea7e1b8..f3cf3407 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostQueryMapper.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostQueryMapper.kt @@ -39,25 +39,29 @@ class PostQueryMapper(private val postResultRowMapper: ResultRowMapper) : .first() .let(postResultRowMapper::map) .apply { - reconstructWith( - mediaIds = it.mapNotNull { resultRow: ResultRow -> - resultRow - .getOrNull(PostsMedia.mediaId) - ?.let { mediaId -> MediaId(mediaId) } - }, - emojis = it - .mapNotNull { resultRow: ResultRow -> - resultRow - .getOrNull(PostsEmojis.emojiId) - ?.let { emojiId -> EmojiId(emojiId) } - }, - visibleActors = it.mapNotNull { resultRow: ResultRow -> - resultRow - .getOrNull(PostsVisibleActors.actorId) - ?.let { actorId -> ActorId(actorId) } - }.toSet() - ) + buildPost(it) } } } + + private fun Post.buildPost(it: List) { + reconstructWith( + mediaIds = it.mapNotNull { resultRow: ResultRow -> + resultRow + .getOrNull(PostsMedia.mediaId) + ?.let { mediaId -> MediaId(mediaId) } + }, + emojis = it + .mapNotNull { resultRow: ResultRow -> + resultRow + .getOrNull(PostsEmojis.emojiId) + ?.let { emojiId -> EmojiId(emojiId) } + }, + visibleActors = it.mapNotNull { resultRow: ResultRow -> + resultRow + .getOrNull(PostsVisibleActors.actorId) + ?.let { actorId -> ActorId(actorId) } + }.toSet() + ) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt index 8e184021..e9c25f19 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt @@ -105,10 +105,10 @@ class ExposedActorRepository( object Actors : Table("actors") { val id = long("id") - val name = varchar("name", ActorName.length) + val name = varchar("name", ActorName.LENGTH) val domain = varchar("domain", Domain.LENGTH) - val screenName = varchar("screen_name", ActorScreenName.length) - val description = varchar("description", ActorDescription.length) + val screenName = varchar("screen_name", ActorScreenName.LENGTH) + val description = varchar("description", ActorDescription.LENGTH) val inbox = varchar("inbox", 1000).uniqueIndex() val outbox = varchar("outbox", 1000).uniqueIndex() val url = varchar("url", 1000).uniqueIndex() 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 9db15afb..11e8bee1 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 @@ -34,12 +34,12 @@ class ExposedFilterRepository(private val filterQueryMapper: QueryMapper get() = Companion.logger override suspend fun save(filter: Filter): Filter = query { - Filters.upsert { - it[id] = filter.id.id - it[userId] = filter.userDetailId.id - it[name] = filter.name.name - it[context] = filter.filterContext.joinToString(",") { it.name } - it[filterAction] = filter.filterAction.name + Filters.upsert { upsertStatement -> + upsertStatement[id] = filter.id.id + upsertStatement[userId] = filter.userDetailId.id + upsertStatement[name] = filter.name.name + upsertStatement[context] = filter.filterContext.joinToString(",") { it.name } + upsertStatement[filterAction] = filter.filterAction.name } FilterKeywords.deleteWhere { filterId eq filter.id.id diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt index 4b1d4b29..08678b32 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt @@ -35,6 +35,7 @@ class PostFactoryImpl( private val postContentFactoryImpl: PostContentFactoryImpl, private val applicationConfig: ApplicationConfig, ) { + @Suppress("LongParameterList") suspend fun createLocal( actor: Actor, actorName: ActorName, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/media/video/FFmpegVideoProcessor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/media/video/FFmpegVideoProcessor.kt index 22417894..9625c2c1 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/media/video/FFmpegVideoProcessor.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/media/video/FFmpegVideoProcessor.kt @@ -28,6 +28,7 @@ class FFmpegVideoProcessor( override fun isSupported(mimeType: MimeType): Boolean = mimeType.fileType == FileType.Video || mimeType.type == "video" + @Suppress("LongMethod", "CyclomaticComplexMethod", "CognitiveComplexMethod", "NestedBlockDepth") override suspend fun process(path: Path, filename: String, mimeType: MimeType?): ProcessedMedia { val tempFile = Files.createTempFile("hideout-movie-processor-", ".tmp") val thumbnailFile = Files.createTempFile("hideout-movie-thumbnail-generate-", ".tmp") diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorScreenNameTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorScreenNameTest.kt index 163dbaf3..4c4fa1f2 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorScreenNameTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorScreenNameTest.kt @@ -8,6 +8,6 @@ class ActorScreenNameTest { fun screenNameがlengthを超えると無視される() { val actorScreenName = ActorScreenName("a".repeat(1000)) - assertEquals(ActorScreenName.length, actorScreenName.screenName.length) + assertEquals(ActorScreenName.LENGTH, actorScreenName.screenName.length) } } \ No newline at end of file