diff --git a/detekt.yml b/detekt.yml index 73a9d00a..436ffa18 100644 --- a/detekt.yml +++ b/detekt.yml @@ -32,6 +32,15 @@ style: ForbiddenComment: active: false + ThrowsCount: + active: false + + UseCheckOrError: + active: false + + UseRequire: + active: false + complexity: CognitiveComplexMethod: active: true diff --git a/src/main/kotlin/dev/usbharu/hideout/Application.kt b/src/main/kotlin/dev/usbharu/hideout/Application.kt index 58f587df..6b0b8c90 100644 --- a/src/main/kotlin/dev/usbharu/hideout/Application.kt +++ b/src/main/kotlin/dev/usbharu/hideout/Application.kt @@ -100,12 +100,12 @@ fun Application.parent() { inject().value, ) configureRouting( - inject().value, - inject().value, - inject().value, - inject().value, - inject().value, - inject().value, + httpSignatureVerifyService = inject().value, + activityPubService = inject().value, + userService = inject().value, + activityPubUserService = inject().value, + postService = inject().value, + userApiService = inject().value, ) } diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Key.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Key.kt index f9b772ff..b5fd3529 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Key.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Key.kt @@ -36,7 +36,5 @@ open class Key : Object { return result } - override fun toString(): String { - return "Key(owner=$owner, publicKeyPem=$publicKeyPem) ${super.toString()}" - } + override fun toString(): String = "Key(owner=$owner, publicKeyPem=$publicKeyPem) ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Object.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Object.kt index ef51aa7f..5d673244 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Object.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Object.kt @@ -40,9 +40,7 @@ open class Object : JsonLd { return result } - override fun toString(): String { - return "Object(type=$type, name=$name, actor=$actor, id=$id) ${super.toString()}" - } + override fun toString(): String = "Object(type=$type, name=$name, actor=$actor, id=$id) ${super.toString()}" companion object { @JvmStatic diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/UserResponse.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/UserResponse.kt index e74a4a72..ab8c1829 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/UserResponse.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/UserResponse.kt @@ -14,13 +14,13 @@ data class UserResponse( companion object { fun from(user: User): UserResponse { return UserResponse( - user.id, - user.name, - user.domain, - user.screenName, - user.description, - user.url, - user.createdAt.toEpochMilli() + id = user.id, + name = user.name, + domain = user.domain, + screenName = user.screenName, + description = user.description, + url = user.url, + createdAt = user.createdAt.toEpochMilli() ) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/plugins/Routing.kt b/src/main/kotlin/dev/usbharu/hideout/plugins/Routing.kt index 3661fcb9..2e0c6b1a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/plugins/Routing.kt +++ b/src/main/kotlin/dev/usbharu/hideout/plugins/Routing.kt @@ -17,6 +17,7 @@ import io.ktor.server.application.* import io.ktor.server.plugins.autohead.* import io.ktor.server.routing.* +@Suppress("LongParameterList") fun Application.configureRouting( httpSignatureVerifyService: HttpSignatureVerifyService, activityPubService: ActivityPubService, diff --git a/src/main/kotlin/dev/usbharu/hideout/plugins/Security.kt b/src/main/kotlin/dev/usbharu/hideout/plugins/Security.kt index bf5c95f2..b6170270 100644 --- a/src/main/kotlin/dev/usbharu/hideout/plugins/Security.kt +++ b/src/main/kotlin/dev/usbharu/hideout/plugins/Security.kt @@ -76,8 +76,8 @@ fun Application.configureSecurity( } authenticate(TOKEN_AUTH) { get("/auth-check") { - val principal = call.principal() - val username = principal!!.payload.getClaim("uid") + val principal = call.principal() ?: throw IllegalStateException("no principal") + val username = principal.payload.getClaim("uid") call.respondText("Hello $username") } } diff --git a/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt b/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt index 1814c62e..a22dc3cc 100644 --- a/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt +++ b/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt @@ -26,7 +26,9 @@ fun Routing.usersAP(activityPubUserService: ActivityPubUserService, userService: ) } get { - val userEntity = userService.findByNameLocalUser(call.parameters["name"]!!) + val userEntity = userService.findByNameLocalUser( + call.parameters["name"] ?: throw ParameterNotExistException("Parameter(name='name') does not exist.") + ) call.respondText(userEntity.toString() + "\n" + userService.findFollowersById(userEntity.id)) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Posts.kt b/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Posts.kt index b858a41b..e91c5b93 100644 --- a/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Posts.kt +++ b/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Posts.kt @@ -17,21 +17,22 @@ import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* +@Suppress("LongMethod") fun Route.posts(postService: IPostService) { route("/posts") { authenticate(TOKEN_AUTH) { post { - val principal = call.principal() ?: throw RuntimeException("no principal") + val principal = call.principal() ?: throw IllegalStateException("no principal") val userId = principal.payload.getClaim("uid").asLong() val receive = call.receive() val postCreateDto = PostCreateDto( - receive.text, - receive.overview, - receive.visibility, - receive.repostId, - receive.replyId, - userId + text = receive.text, + overview = receive.overview, + visibility = receive.visibility, + repostId = receive.repostId, + repolyId = receive.replyId, + userId = userId ) val create = postService.create(postCreateDto) call.response.header("Location", create.url) diff --git a/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Users.kt b/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Users.kt index 38efa48a..5a51c4c2 100644 --- a/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Users.kt +++ b/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Users.kt @@ -16,6 +16,7 @@ import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* +@Suppress("LongMethod") fun Route.users(userService: IUserService, userApiService: IUserApiService) { route("/users") { get { diff --git a/src/main/kotlin/dev/usbharu/hideout/routing/api/mastodon/v1/Statuses.kt b/src/main/kotlin/dev/usbharu/hideout/routing/api/mastodon/v1/Statuses.kt index 9b5c5fa8..2bd31725 100644 --- a/src/main/kotlin/dev/usbharu/hideout/routing/api/mastodon/v1/Statuses.kt +++ b/src/main/kotlin/dev/usbharu/hideout/routing/api/mastodon/v1/Statuses.kt @@ -3,6 +3,7 @@ package dev.usbharu.hideout.routing.api.mastodon.v1 import dev.usbharu.hideout.service.IPostService import io.ktor.server.routing.* +@Suppress("UnusedPrivateMember") fun Route.statuses(postService: IPostService) { // route("/statuses") { // post { diff --git a/src/main/kotlin/dev/usbharu/hideout/service/IPostService.kt b/src/main/kotlin/dev/usbharu/hideout/service/IPostService.kt index f2da7a53..e4a33550 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/IPostService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/IPostService.kt @@ -5,6 +5,7 @@ import dev.usbharu.hideout.domain.model.hideout.dto.PostCreateDto import dev.usbharu.hideout.domain.model.hideout.entity.Post import java.time.Instant +@Suppress("LongParameterList") interface IPostService { suspend fun create(post: Post): Post suspend fun create(post: PostCreateDto): Post diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ServerInitialiseServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ServerInitialiseServiceImpl.kt index 78bc0192..13fabeaf 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ServerInitialiseServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ServerInitialiseServiceImpl.kt @@ -25,7 +25,7 @@ class ServerInitialiseServiceImpl(private val metaRepository: IMetaRepository) : return } - if (isVersionChanged(savedMeta!!)) { + if (isVersionChanged(requireNotNull(savedMeta))) { logger.info("Version changed!! (${savedMeta.version} -> $implementationVersion)") updateVersion(savedMeta, implementationVersion) } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/impl/PostService.kt b/src/main/kotlin/dev/usbharu/hideout/service/impl/PostService.kt index 28fa7c9c..cbb7a3bb 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/impl/PostService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/impl/PostService.kt @@ -41,8 +41,15 @@ class PostService( val user = userService.findById(post.userId) val id = postRepository.generateId() val postEntity = Post( - id, user.id, null, post.text, - Instant.now().toEpochMilli(), Visibility.PUBLIC, "${user.url}/posts/$id", null, null + id = id, + userId = user.id, + overview = null, + text = post.text, + createdAt = Instant.now().toEpochMilli(), + visibility = Visibility.PUBLIC, + url = "${user.url}/posts/$id", + repostId = null, + replyId = null ) postRepository.save(postEntity) return postEntity diff --git a/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt index 7e336fd9..14f7b04b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt @@ -3,7 +3,6 @@ package dev.usbharu.hideout.service.impl import dev.usbharu.hideout.config.Config import dev.usbharu.hideout.domain.model.hideout.dto.RemoteUserCreateDto import dev.usbharu.hideout.domain.model.hideout.dto.UserCreateDto -import dev.usbharu.hideout.domain.model.hideout.dto.UserResponse import dev.usbharu.hideout.domain.model.hideout.entity.User import dev.usbharu.hideout.exception.UserNotFoundException import dev.usbharu.hideout.repository.IUserRepository @@ -24,10 +23,6 @@ class UserService(private val userRepository: IUserRepository, private val userA ) } - suspend fun findAllForUser(limit: Int?, offset: Long?): List { - TODO("Not yet implemented") - } - override suspend fun findById(id: Long): User = userRepository.findById(id) ?: throw UserNotFoundException("$id was not found.")