mirror of https://github.com/usbharu/Hideout.git
style: スタイルを修正
This commit is contained in:
parent
27b561976a
commit
67610f2c02
|
@ -32,6 +32,15 @@ style:
|
||||||
ForbiddenComment:
|
ForbiddenComment:
|
||||||
active: false
|
active: false
|
||||||
|
|
||||||
|
ThrowsCount:
|
||||||
|
active: false
|
||||||
|
|
||||||
|
UseCheckOrError:
|
||||||
|
active: false
|
||||||
|
|
||||||
|
UseRequire:
|
||||||
|
active: false
|
||||||
|
|
||||||
complexity:
|
complexity:
|
||||||
CognitiveComplexMethod:
|
CognitiveComplexMethod:
|
||||||
active: true
|
active: true
|
||||||
|
|
|
@ -100,12 +100,12 @@ fun Application.parent() {
|
||||||
inject<JwkProvider>().value,
|
inject<JwkProvider>().value,
|
||||||
)
|
)
|
||||||
configureRouting(
|
configureRouting(
|
||||||
inject<HttpSignatureVerifyService>().value,
|
httpSignatureVerifyService = inject<HttpSignatureVerifyService>().value,
|
||||||
inject<ActivityPubService>().value,
|
activityPubService = inject<ActivityPubService>().value,
|
||||||
inject<IUserService>().value,
|
userService = inject<IUserService>().value,
|
||||||
inject<ActivityPubUserService>().value,
|
activityPubUserService = inject<ActivityPubUserService>().value,
|
||||||
inject<IPostService>().value,
|
postService = inject<IPostService>().value,
|
||||||
inject<IUserApiService>().value,
|
userApiService = inject<IUserApiService>().value,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,5 @@ open class Key : Object {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String = "Key(owner=$owner, publicKeyPem=$publicKeyPem) ${super.toString()}"
|
||||||
return "Key(owner=$owner, publicKeyPem=$publicKeyPem) ${super.toString()}"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,7 @@ open class Object : JsonLd {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String = "Object(type=$type, name=$name, actor=$actor, id=$id) ${super.toString()}"
|
||||||
return "Object(type=$type, name=$name, actor=$actor, id=$id) ${super.toString()}"
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
|
|
@ -14,13 +14,13 @@ data class UserResponse(
|
||||||
companion object {
|
companion object {
|
||||||
fun from(user: User): UserResponse {
|
fun from(user: User): UserResponse {
|
||||||
return UserResponse(
|
return UserResponse(
|
||||||
user.id,
|
id = user.id,
|
||||||
user.name,
|
name = user.name,
|
||||||
user.domain,
|
domain = user.domain,
|
||||||
user.screenName,
|
screenName = user.screenName,
|
||||||
user.description,
|
description = user.description,
|
||||||
user.url,
|
url = user.url,
|
||||||
user.createdAt.toEpochMilli()
|
createdAt = user.createdAt.toEpochMilli()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import io.ktor.server.application.*
|
||||||
import io.ktor.server.plugins.autohead.*
|
import io.ktor.server.plugins.autohead.*
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
|
|
||||||
|
@Suppress("LongParameterList")
|
||||||
fun Application.configureRouting(
|
fun Application.configureRouting(
|
||||||
httpSignatureVerifyService: HttpSignatureVerifyService,
|
httpSignatureVerifyService: HttpSignatureVerifyService,
|
||||||
activityPubService: ActivityPubService,
|
activityPubService: ActivityPubService,
|
||||||
|
|
|
@ -76,8 +76,8 @@ fun Application.configureSecurity(
|
||||||
}
|
}
|
||||||
authenticate(TOKEN_AUTH) {
|
authenticate(TOKEN_AUTH) {
|
||||||
get("/auth-check") {
|
get("/auth-check") {
|
||||||
val principal = call.principal<JWTPrincipal>()
|
val principal = call.principal<JWTPrincipal>() ?: throw IllegalStateException("no principal")
|
||||||
val username = principal!!.payload.getClaim("uid")
|
val username = principal.payload.getClaim("uid")
|
||||||
call.respondText("Hello $username")
|
call.respondText("Hello $username")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,9 @@ fun Routing.usersAP(activityPubUserService: ActivityPubUserService, userService:
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
get {
|
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))
|
call.respondText(userEntity.toString() + "\n" + userService.findFollowersById(userEntity.id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,21 +17,22 @@ import io.ktor.server.request.*
|
||||||
import io.ktor.server.response.*
|
import io.ktor.server.response.*
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
|
|
||||||
|
@Suppress("LongMethod")
|
||||||
fun Route.posts(postService: IPostService) {
|
fun Route.posts(postService: IPostService) {
|
||||||
route("/posts") {
|
route("/posts") {
|
||||||
authenticate(TOKEN_AUTH) {
|
authenticate(TOKEN_AUTH) {
|
||||||
post {
|
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 userId = principal.payload.getClaim("uid").asLong()
|
||||||
|
|
||||||
val receive = call.receive<Post>()
|
val receive = call.receive<Post>()
|
||||||
val postCreateDto = PostCreateDto(
|
val postCreateDto = PostCreateDto(
|
||||||
receive.text,
|
text = receive.text,
|
||||||
receive.overview,
|
overview = receive.overview,
|
||||||
receive.visibility,
|
visibility = receive.visibility,
|
||||||
receive.repostId,
|
repostId = receive.repostId,
|
||||||
receive.replyId,
|
repolyId = receive.replyId,
|
||||||
userId
|
userId = userId
|
||||||
)
|
)
|
||||||
val create = postService.create(postCreateDto)
|
val create = postService.create(postCreateDto)
|
||||||
call.response.header("Location", create.url)
|
call.response.header("Location", create.url)
|
||||||
|
|
|
@ -16,6 +16,7 @@ import io.ktor.server.request.*
|
||||||
import io.ktor.server.response.*
|
import io.ktor.server.response.*
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
|
|
||||||
|
@Suppress("LongMethod")
|
||||||
fun Route.users(userService: IUserService, userApiService: IUserApiService) {
|
fun Route.users(userService: IUserService, userApiService: IUserApiService) {
|
||||||
route("/users") {
|
route("/users") {
|
||||||
get {
|
get {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package dev.usbharu.hideout.routing.api.mastodon.v1
|
||||||
import dev.usbharu.hideout.service.IPostService
|
import dev.usbharu.hideout.service.IPostService
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
|
|
||||||
|
@Suppress("UnusedPrivateMember")
|
||||||
fun Route.statuses(postService: IPostService) {
|
fun Route.statuses(postService: IPostService) {
|
||||||
// route("/statuses") {
|
// route("/statuses") {
|
||||||
// post {
|
// post {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import dev.usbharu.hideout.domain.model.hideout.dto.PostCreateDto
|
||||||
import dev.usbharu.hideout.domain.model.hideout.entity.Post
|
import dev.usbharu.hideout.domain.model.hideout.entity.Post
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
|
@Suppress("LongParameterList")
|
||||||
interface IPostService {
|
interface IPostService {
|
||||||
suspend fun create(post: Post): Post
|
suspend fun create(post: Post): Post
|
||||||
suspend fun create(post: PostCreateDto): Post
|
suspend fun create(post: PostCreateDto): Post
|
||||||
|
|
|
@ -25,7 +25,7 @@ class ServerInitialiseServiceImpl(private val metaRepository: IMetaRepository) :
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isVersionChanged(savedMeta!!)) {
|
if (isVersionChanged(requireNotNull(savedMeta))) {
|
||||||
logger.info("Version changed!! (${savedMeta.version} -> $implementationVersion)")
|
logger.info("Version changed!! (${savedMeta.version} -> $implementationVersion)")
|
||||||
updateVersion(savedMeta, implementationVersion)
|
updateVersion(savedMeta, implementationVersion)
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,15 @@ class PostService(
|
||||||
val user = userService.findById(post.userId)
|
val user = userService.findById(post.userId)
|
||||||
val id = postRepository.generateId()
|
val id = postRepository.generateId()
|
||||||
val postEntity = Post(
|
val postEntity = Post(
|
||||||
id, user.id, null, post.text,
|
id = id,
|
||||||
Instant.now().toEpochMilli(), Visibility.PUBLIC, "${user.url}/posts/$id", null, null
|
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)
|
postRepository.save(postEntity)
|
||||||
return postEntity
|
return postEntity
|
||||||
|
|
|
@ -3,7 +3,6 @@ package dev.usbharu.hideout.service.impl
|
||||||
import dev.usbharu.hideout.config.Config
|
import dev.usbharu.hideout.config.Config
|
||||||
import dev.usbharu.hideout.domain.model.hideout.dto.RemoteUserCreateDto
|
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.UserCreateDto
|
||||||
import dev.usbharu.hideout.domain.model.hideout.dto.UserResponse
|
|
||||||
import dev.usbharu.hideout.domain.model.hideout.entity.User
|
import dev.usbharu.hideout.domain.model.hideout.entity.User
|
||||||
import dev.usbharu.hideout.exception.UserNotFoundException
|
import dev.usbharu.hideout.exception.UserNotFoundException
|
||||||
import dev.usbharu.hideout.repository.IUserRepository
|
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 =
|
override suspend fun findById(id: Long): User =
|
||||||
userRepository.findById(id) ?: throw UserNotFoundException("$id was not found.")
|
userRepository.findById(id) ?: throw UserNotFoundException("$id was not found.")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue