From 5f01ccab634e43f586d404f3ad389770d05b2bbf Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 20 May 2023 18:10:09 +0900 Subject: [PATCH] =?UTF-8?q?style:=20=E3=82=B9=E3=82=BF=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/usbharu/hideout/domain/model/ap/Key.kt | 1 - .../dev/usbharu/hideout/domain/model/ap/Object.kt | 1 - .../hideout/routing/api/internal/v1/Posts.kt | 13 ++++++++----- .../hideout/routing/api/internal/v1/Users.kt | 15 ++++++++------- .../usbharu/hideout/service/impl/UserService.kt | 2 +- .../kotlin/dev/usbharu/hideout/util/AcctUtil.kt | 3 ++- 6 files changed, 19 insertions(+), 16 deletions(-) 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 63986e4c..f9b772ff 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 @@ -20,7 +20,6 @@ open class Key : Object { this.publicKeyPem = publicKeyPem } - override fun equals(other: Any?): Boolean { if (this === other) return true if (other !is Key) return false 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 1adcb211..ef51aa7f 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 @@ -20,7 +20,6 @@ open class Object : JsonLd { this.id = id } - override fun equals(other: Any?): Boolean { if (this === other) return true if (other !is Object) return false 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 772ad8cf..b858a41b 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 @@ -52,8 +52,10 @@ fun Route.posts(postService: IPostService) { val userId = call.principal()?.payload?.getClaim("uid")?.asLong() val id = call.parameters["id"]?.toLong() ?: throw ParameterNotExistException("Parameter(id='postsId') does not exist.") - val post = (postService.findByIdForUser(id, userId) - ?: throw PostNotFoundException("$id was not found or is not authorized.")) + val post = ( + postService.findByIdForUser(id, userId) + ?: throw PostNotFoundException("$id was not found or is not authorized.") + ) call.respond(post) } } @@ -76,14 +78,15 @@ fun Route.posts(postService: IPostService) { postService.findByUserIdForUser(targetUserId, forUserId = userId) } call.respond(posts) - } get("/{id}") { val userId = call.principal()?.payload?.getClaim("uid")?.asLong() val id = call.parameters["id"]?.toLong() ?: throw ParameterNotExistException("Parameter(name='postsId' does not exist.") - val post = (postService.findByIdForUser(id, userId) - ?: throw PostNotFoundException("$id was not found or is not authorized.")) + val post = ( + postService.findByIdForUser(id, userId) + ?: throw PostNotFoundException("$id was not found or is not authorized.") + ) call.respond(post) } } 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 92297e11..38efa48a 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 @@ -38,11 +38,12 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) { call.respond(HttpStatusCode.Created) } route("/{name}") { - authenticate(TOKEN_AUTH, optional = true) { get { - val userParameter = (call.parameters["name"] - ?: throw ParameterNotExistException("Parameter(name='userName@domain') does not exist.")) + val userParameter = ( + call.parameters["name"] + ?: throw ParameterNotExistException("Parameter(name='userName@domain') does not exist.") + ) if (userParameter.toLongOrNull() != null) { return@get call.respond(userApiService.findById(userParameter.toLong())) } else { @@ -63,7 +64,6 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) { return@get call.respond(userApiService.findFollowersByAcct(acct)) } authenticate(TOKEN_AUTH) { - post { val userId = call.principal()?.payload?.getClaim("uid")?.asLong() ?: throw IllegalStateException("no principal") @@ -88,8 +88,10 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) { } route("/following") { get { - val userParameter = (call.parameters["name"] - ?: throw ParameterNotExistException("Parameter(name='userName@domain') does not exist.")) + val userParameter = ( + call.parameters["name"] + ?: throw ParameterNotExistException("Parameter(name='userName@domain') does not exist.") + ) if (userParameter.toLongOrNull() != null) { return@get call.respond(userApiService.findFollowings(userParameter.toLong())) } @@ -98,6 +100,5 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) { } } } - } } 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 748dc49f..7e336fd9 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/impl/UserService.kt @@ -109,7 +109,7 @@ class UserService(private val userRepository: IUserRepository, private val userA TODO("Not yet implemented") } - //TODO APのフォロー処理を作る + // TODO APのフォロー処理を作る override suspend fun addFollowers(id: Long, follower: Long): Boolean { userRepository.createFollower(id, follower) return false diff --git a/src/main/kotlin/dev/usbharu/hideout/util/AcctUtil.kt b/src/main/kotlin/dev/usbharu/hideout/util/AcctUtil.kt index 70ce1ff2..34ab88ba 100644 --- a/src/main/kotlin/dev/usbharu/hideout/util/AcctUtil.kt +++ b/src/main/kotlin/dev/usbharu/hideout/util/AcctUtil.kt @@ -26,7 +26,8 @@ object AcctUtil { val userName = substring.substringBefore("@") val domain = substring.substringAfter("@") Acct( - userName, domain.ifBlank { null } + userName, + domain.ifBlank { null } ) } else { throw IllegalArgumentException("Invalid acct.(@ are in the wrong position)")