style: スタイルを修正

This commit is contained in:
usbharu 2023-05-20 18:10:09 +09:00
parent e2150c3a07
commit 5f01ccab63
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
6 changed files with 19 additions and 16 deletions

View File

@ -20,7 +20,6 @@ open class Key : Object {
this.publicKeyPem = publicKeyPem this.publicKeyPem = publicKeyPem
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other !is Key) return false if (other !is Key) return false

View File

@ -20,7 +20,6 @@ open class Object : JsonLd {
this.id = id this.id = id
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other !is Object) return false if (other !is Object) return false

View File

@ -52,8 +52,10 @@ fun Route.posts(postService: IPostService) {
val userId = call.principal<JWTPrincipal>()?.payload?.getClaim("uid")?.asLong() val userId = call.principal<JWTPrincipal>()?.payload?.getClaim("uid")?.asLong()
val id = call.parameters["id"]?.toLong() val id = call.parameters["id"]?.toLong()
?: throw ParameterNotExistException("Parameter(id='postsId') does not exist.") ?: throw ParameterNotExistException("Parameter(id='postsId') does not exist.")
val post = (postService.findByIdForUser(id, userId) val post = (
?: throw PostNotFoundException("$id was not found or is not authorized.")) postService.findByIdForUser(id, userId)
?: throw PostNotFoundException("$id was not found or is not authorized.")
)
call.respond(post) call.respond(post)
} }
} }
@ -76,14 +78,15 @@ fun Route.posts(postService: IPostService) {
postService.findByUserIdForUser(targetUserId, forUserId = userId) postService.findByUserIdForUser(targetUserId, forUserId = userId)
} }
call.respond(posts) call.respond(posts)
} }
get("/{id}") { get("/{id}") {
val userId = call.principal<JWTPrincipal>()?.payload?.getClaim("uid")?.asLong() val userId = call.principal<JWTPrincipal>()?.payload?.getClaim("uid")?.asLong()
val id = call.parameters["id"]?.toLong() val id = call.parameters["id"]?.toLong()
?: throw ParameterNotExistException("Parameter(name='postsId' does not exist.") ?: throw ParameterNotExistException("Parameter(name='postsId' does not exist.")
val post = (postService.findByIdForUser(id, userId) val post = (
?: throw PostNotFoundException("$id was not found or is not authorized.")) postService.findByIdForUser(id, userId)
?: throw PostNotFoundException("$id was not found or is not authorized.")
)
call.respond(post) call.respond(post)
} }
} }

View File

@ -38,11 +38,12 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) {
call.respond(HttpStatusCode.Created) call.respond(HttpStatusCode.Created)
} }
route("/{name}") { route("/{name}") {
authenticate(TOKEN_AUTH, optional = true) { authenticate(TOKEN_AUTH, optional = true) {
get { get {
val userParameter = (call.parameters["name"] val userParameter = (
?: throw ParameterNotExistException("Parameter(name='userName@domain') does not exist.")) call.parameters["name"]
?: throw ParameterNotExistException("Parameter(name='userName@domain') does not exist.")
)
if (userParameter.toLongOrNull() != null) { if (userParameter.toLongOrNull() != null) {
return@get call.respond(userApiService.findById(userParameter.toLong())) return@get call.respond(userApiService.findById(userParameter.toLong()))
} else { } else {
@ -63,7 +64,6 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) {
return@get call.respond(userApiService.findFollowersByAcct(acct)) return@get call.respond(userApiService.findFollowersByAcct(acct))
} }
authenticate(TOKEN_AUTH) { authenticate(TOKEN_AUTH) {
post { post {
val userId = call.principal<JWTPrincipal>()?.payload?.getClaim("uid")?.asLong() val userId = call.principal<JWTPrincipal>()?.payload?.getClaim("uid")?.asLong()
?: throw IllegalStateException("no principal") ?: throw IllegalStateException("no principal")
@ -88,8 +88,10 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) {
} }
route("/following") { route("/following") {
get { get {
val userParameter = (call.parameters["name"] val userParameter = (
?: throw ParameterNotExistException("Parameter(name='userName@domain') does not exist.")) call.parameters["name"]
?: throw ParameterNotExistException("Parameter(name='userName@domain') does not exist.")
)
if (userParameter.toLongOrNull() != null) { if (userParameter.toLongOrNull() != null) {
return@get call.respond(userApiService.findFollowings(userParameter.toLong())) return@get call.respond(userApiService.findFollowings(userParameter.toLong()))
} }
@ -98,6 +100,5 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) {
} }
} }
} }
} }
} }

View File

@ -26,7 +26,8 @@ object AcctUtil {
val userName = substring.substringBefore("@") val userName = substring.substringBefore("@")
val domain = substring.substringAfter("@") val domain = substring.substringAfter("@")
Acct( Acct(
userName, domain.ifBlank { null } userName,
domain.ifBlank { null }
) )
} else { } else {
throw IllegalArgumentException("Invalid acct.(@ are in the wrong position)") throw IllegalArgumentException("Invalid acct.(@ are in the wrong position)")