style: スタイルを修正

This commit is contained in:
usbharu 2023-05-20 19:11:14 +09:00
parent 27b561976a
commit 67610f2c02
15 changed files with 51 additions and 37 deletions

View File

@ -32,6 +32,15 @@ style:
ForbiddenComment:
active: false
ThrowsCount:
active: false
UseCheckOrError:
active: false
UseRequire:
active: false
complexity:
CognitiveComplexMethod:
active: true

View File

@ -100,12 +100,12 @@ fun Application.parent() {
inject<JwkProvider>().value,
)
configureRouting(
inject<HttpSignatureVerifyService>().value,
inject<ActivityPubService>().value,
inject<IUserService>().value,
inject<ActivityPubUserService>().value,
inject<IPostService>().value,
inject<IUserApiService>().value,
httpSignatureVerifyService = inject<HttpSignatureVerifyService>().value,
activityPubService = inject<ActivityPubService>().value,
userService = inject<IUserService>().value,
activityPubUserService = inject<ActivityPubUserService>().value,
postService = inject<IPostService>().value,
userApiService = inject<IUserApiService>().value,
)
}

View File

@ -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()}"
}

View File

@ -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

View File

@ -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()
)
}
}

View File

@ -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,

View File

@ -76,8 +76,8 @@ fun Application.configureSecurity(
}
authenticate(TOKEN_AUTH) {
get("/auth-check") {
val principal = call.principal<JWTPrincipal>()
val username = principal!!.payload.getClaim("uid")
val principal = call.principal<JWTPrincipal>() ?: throw IllegalStateException("no principal")
val username = principal.payload.getClaim("uid")
call.respondText("Hello $username")
}
}

View File

@ -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))
}
}

View File

@ -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<JWTPrincipal>() ?: throw RuntimeException("no principal")
val principal = call.principal<JWTPrincipal>() ?: throw IllegalStateException("no principal")
val userId = principal.payload.getClaim("uid").asLong()
val receive = call.receive<Post>()
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)

View File

@ -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 {

View File

@ -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 {

View File

@ -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

View File

@ -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)
}

View File

@ -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

View File

@ -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<UserResponse> {
TODO("Not yet implemented")
}
override suspend fun findById(id: Long): User =
userRepository.findById(id) ?: throw UserNotFoundException("$id was not found.")