From f3285c30de6e505d34c9c4aeee7cc17a30db5555 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 5 Oct 2023 13:04:30 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=B8=8D=E8=A6=81=E3=81=AA?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E5=89=8A=E9=99=A4?= =?UTF-8?q?=E3=80=81=E3=82=A4=E3=83=B3=E3=82=B9=E3=83=9A=E3=82=AF=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=82=92=E8=A7=A3=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/usbharu/hideout/JobQueueRunner.kt | 5 +- .../model/api/mastodon/StatusForPost.kt | 6 - .../domain/model/hideout/dto/PostResponse.kt | 31 ----- .../domain/model/hideout/dto/UserResponse.kt | 27 ---- .../hideout/domain/model/hideout/form/Post.kt | 11 -- .../domain/model/hideout/form/Reaction.kt | 3 - .../domain/model/hideout/form/RefreshToken.kt | 3 - .../domain/model/hideout/form/UserCreate.kt | 3 - .../domain/model/hideout/form/UserLogin.kt | 3 - .../hideout/domain/model/job/HideoutJob.kt | 31 +++-- .../domain/model/wellknown/Nodeinfo2_0.kt | 2 + .../FailedToGetResourcesException.kt | 7 + .../exception/HttpSignatureVerifyException.kt | 7 + .../exception/IllegalParameterException.kt | 7 + .../exception/InvalidRefreshTokenException.kt | 7 + .../InvalidUsernameOrPasswordException.kt | 7 + .../hideout/exception/JsonParseException.kt | 7 + .../hideout/exception/NotInitException.kt | 7 + .../exception/ParameterNotExistException.kt | 7 + .../exception/PostNotFoundException.kt | 7 + .../exception/UserNotFoundException.kt | 7 + .../UsernameAlreadyExistException.kt | 7 + .../ap/IllegalActivityPubObjectException.kt | 7 + .../usbharu/hideout/plugins/ActivityPub.kt | 9 +- .../hideout/query/FollowerQueryServiceImpl.kt | 4 +- .../hideout/query/PostResponseQueryService.kt | 39 ------ .../query/PostResponseQueryServiceImpl.kt | 70 ---------- .../hideout/query/ReactionQueryServiceImpl.kt | 61 --------- .../query/mastodon/StatusQueryServiceImpl.kt | 15 +- .../hideout/repository/MetaRepositoryImpl.kt | 15 +- .../hideout/repository/PostRepositoryImpl.kt | 22 +-- .../repository/ReactionRepositoryImpl.kt | 6 +- .../RegisteredClientRepositoryImpl.kt | 37 ++--- .../hideout/repository/UserRepositoryImpl.kt | 38 +++--- .../hideout/service/ap/APAcceptService.kt | 1 - .../hideout/service/ap/APCreateService.kt | 1 - .../hideout/service/ap/APLikeService.kt | 5 +- .../hideout/service/ap/APNoteService.kt | 7 +- .../hideout/service/ap/APReactionService.kt | 1 - .../hideout/service/ap/APSendFollowService.kt | 1 - .../usbharu/hideout/service/ap/APService.kt | 13 +- .../hideout/service/ap/APUndoService.kt | 1 - .../hideout/service/ap/APUserService.kt | 1 - .../hideout/service/api/PostApiService.kt | 129 ------------------ .../hideout/service/api/UserApiService.kt | 116 ---------------- .../api/mastodon/StatusesApiService.kt | 13 +- .../api/mastodon/TimelineApiService.kt | 2 - ...xposedOAuth2AuthorizationConsentService.kt | 10 +- .../auth/ExposedOAuth2AuthorizationService.kt | 77 ++++++----- .../hideout/service/core/MetaServiceImpl.kt | 2 +- .../hideout/service/post/PostServiceImpl.kt | 4 +- .../service/user/UserAuthServiceImpl.kt | 4 +- .../dev/usbharu/kjob/exposed/ExposedKJob.kt | 8 +- 53 files changed, 242 insertions(+), 679 deletions(-) delete mode 100644 src/main/kotlin/dev/usbharu/hideout/domain/model/api/mastodon/StatusForPost.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/PostResponse.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/UserResponse.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/Post.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/Reaction.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/RefreshToken.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/UserCreate.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/UserLogin.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryService.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryServiceImpl.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/query/ReactionQueryServiceImpl.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/service/api/PostApiService.kt delete mode 100644 src/main/kotlin/dev/usbharu/hideout/service/api/UserApiService.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/JobQueueRunner.kt b/src/main/kotlin/dev/usbharu/hideout/JobQueueRunner.kt index d1c1b03f..0f3a3829 100644 --- a/src/main/kotlin/dev/usbharu/hideout/JobQueueRunner.kt +++ b/src/main/kotlin/dev/usbharu/hideout/JobQueueRunner.kt @@ -4,6 +4,7 @@ import dev.usbharu.hideout.domain.model.job.HideoutJob import dev.usbharu.hideout.service.ap.APService import dev.usbharu.hideout.service.job.JobQueueParentService import dev.usbharu.hideout.service.job.JobQueueWorkerService +import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.boot.ApplicationArguments import org.springframework.boot.ApplicationRunner @@ -18,7 +19,7 @@ class JobQueueRunner(private val jobQueueParentService: JobQueueParentService, p } companion object { - val LOGGER = LoggerFactory.getLogger(JobQueueRunner::class.java) + val LOGGER: Logger = LoggerFactory.getLogger(JobQueueRunner::class.java) } } @@ -46,6 +47,6 @@ class JobQueueWorkerRunner( } companion object { - val LOGGER = LoggerFactory.getLogger(JobQueueWorkerRunner::class.java) + val LOGGER: Logger = LoggerFactory.getLogger(JobQueueWorkerRunner::class.java) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/api/mastodon/StatusForPost.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/api/mastodon/StatusForPost.kt deleted file mode 100644 index bc1f7dfc..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/api/mastodon/StatusForPost.kt +++ /dev/null @@ -1,6 +0,0 @@ -package dev.usbharu.hideout.domain.model.api.mastodon - -data class StatusForPost( - val status: String, - val userId: Long -) diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/PostResponse.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/PostResponse.kt deleted file mode 100644 index 8aee3f68..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/PostResponse.kt +++ /dev/null @@ -1,31 +0,0 @@ -package dev.usbharu.hideout.domain.model.hideout.dto - -import dev.usbharu.hideout.domain.model.hideout.entity.Post -import dev.usbharu.hideout.domain.model.hideout.entity.User -import dev.usbharu.hideout.domain.model.hideout.entity.Visibility - -data class PostResponse( - val id: String, - val user: UserResponse, - val overview: String? = null, - val text: String? = null, - val createdAt: Long, - val visibility: Visibility, - val url: String, - val sensitive: Boolean = false, -) { - companion object { - fun from(post: Post, user: User): PostResponse { - return PostResponse( - id = post.id.toString(), - user = UserResponse.from(user), - overview = post.overview, - text = post.text, - createdAt = post.createdAt, - visibility = post.visibility, - url = post.url, - sensitive = post.sensitive - ) - } - } -} 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 deleted file mode 100644 index 6213a7e4..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/UserResponse.kt +++ /dev/null @@ -1,27 +0,0 @@ -package dev.usbharu.hideout.domain.model.hideout.dto - -import dev.usbharu.hideout.domain.model.hideout.entity.User - -data class UserResponse( - val id: String, - val name: String, - val domain: String, - val screenName: String, - val description: String = "", - val url: String, - val createdAt: Long -) { - companion object { - fun from(user: User): UserResponse { - return UserResponse( - id = user.id.toString(), - 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/domain/model/hideout/form/Post.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/Post.kt deleted file mode 100644 index bc768d32..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/Post.kt +++ /dev/null @@ -1,11 +0,0 @@ -package dev.usbharu.hideout.domain.model.hideout.form - -import dev.usbharu.hideout.domain.model.hideout.entity.Visibility - -data class Post( - val text: String, - val overview: String? = null, - val visibility: Visibility = Visibility.PUBLIC, - val repostId: Long? = null, - val replyId: Long? = null -) diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/Reaction.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/Reaction.kt deleted file mode 100644 index c006d581..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/Reaction.kt +++ /dev/null @@ -1,3 +0,0 @@ -package dev.usbharu.hideout.domain.model.hideout.form - -data class Reaction(val reaction: String?) diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/RefreshToken.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/RefreshToken.kt deleted file mode 100644 index 5d7898a1..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/RefreshToken.kt +++ /dev/null @@ -1,3 +0,0 @@ -package dev.usbharu.hideout.domain.model.hideout.form - -data class RefreshToken(val refreshToken: String) diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/UserCreate.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/UserCreate.kt deleted file mode 100644 index 40d96a92..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/UserCreate.kt +++ /dev/null @@ -1,3 +0,0 @@ -package dev.usbharu.hideout.domain.model.hideout.form - -data class UserCreate(val username: String, val password: String) diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/UserLogin.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/UserLogin.kt deleted file mode 100644 index d9d5fc4d..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/form/UserLogin.kt +++ /dev/null @@ -1,3 +0,0 @@ -package dev.usbharu.hideout.domain.model.hideout.form - -data class UserLogin(val username: String, val password: String) diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/job/HideoutJob.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/job/HideoutJob.kt index efc9e844..252dcb17 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/job/HideoutJob.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/job/HideoutJob.kt @@ -1,37 +1,38 @@ package dev.usbharu.hideout.domain.model.job import kjob.core.Job +import kjob.core.Prop import org.springframework.stereotype.Component sealed class HideoutJob(name: String = "") : Job(name) @Component object ReceiveFollowJob : HideoutJob("ReceiveFollowJob") { - val actor = string("actor") - val follow = string("follow") - val targetActor = string("targetActor") + val actor: Prop = string("actor") + val follow: Prop = string("follow") + val targetActor: Prop = string("targetActor") } @Component object DeliverPostJob : HideoutJob("DeliverPostJob") { - val post = string("post") - val actor = string("actor") - val inbox = string("inbox") + val post: Prop = string("post") + val actor: Prop = string("actor") + val inbox: Prop = string("inbox") } @Component object DeliverReactionJob : HideoutJob("DeliverReactionJob") { - val reaction = string("reaction") - val postUrl = string("postUrl") - val actor = string("actor") - val inbox = string("inbox") - val id = string("id") + val reaction: Prop = string("reaction") + val postUrl: Prop = string("postUrl") + val actor: Prop = string("actor") + val inbox: Prop = string("inbox") + val id: Prop = string("id") } @Component object DeliverRemoveReactionJob : HideoutJob("DeliverRemoveReactionJob") { - val id = string("id") - val inbox = string("inbox") - val actor = string("actor") - val like = string("like") + val id: Prop = string("id") + val inbox: Prop = string("inbox") + val actor: Prop = string("actor") + val like: Prop = string("like") } diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/wellknown/Nodeinfo2_0.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/wellknown/Nodeinfo2_0.kt index 99548641..b4faa8a4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/wellknown/Nodeinfo2_0.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/wellknown/Nodeinfo2_0.kt @@ -1,3 +1,5 @@ +@file:Suppress("ClassName") + package dev.usbharu.hideout.domain.model.wellknown @Suppress("ClassNaming") diff --git a/src/main/kotlin/dev/usbharu/hideout/exception/FailedToGetResourcesException.kt b/src/main/kotlin/dev/usbharu/hideout/exception/FailedToGetResourcesException.kt index 95cd08a9..d13b5f72 100644 --- a/src/main/kotlin/dev/usbharu/hideout/exception/FailedToGetResourcesException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/exception/FailedToGetResourcesException.kt @@ -1,8 +1,15 @@ package dev.usbharu.hideout.exception +import java.io.Serial + open class FailedToGetResourcesException : IllegalArgumentException { constructor() : super() constructor(s: String?) : super(s) constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) + + companion object { + @Serial + private const val serialVersionUID: Long = -3117221954866309059L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/exception/HttpSignatureVerifyException.kt b/src/main/kotlin/dev/usbharu/hideout/exception/HttpSignatureVerifyException.kt index d123025f..504ce898 100644 --- a/src/main/kotlin/dev/usbharu/hideout/exception/HttpSignatureVerifyException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/exception/HttpSignatureVerifyException.kt @@ -1,8 +1,15 @@ package dev.usbharu.hideout.exception +import java.io.Serial + class HttpSignatureVerifyException : IllegalArgumentException { constructor() : super() constructor(s: String?) : super(s) constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) + + companion object { + @Serial + private const val serialVersionUID: Long = 1484943321770741944L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/exception/IllegalParameterException.kt b/src/main/kotlin/dev/usbharu/hideout/exception/IllegalParameterException.kt index dd94d127..fca3b79a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/exception/IllegalParameterException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/exception/IllegalParameterException.kt @@ -1,8 +1,15 @@ package dev.usbharu.hideout.exception +import java.io.Serial + class IllegalParameterException : IllegalArgumentException { constructor() : super() constructor(s: String?) : super(s) constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) + + companion object { + @Serial + private const val serialVersionUID: Long = -4641102874061252642L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/exception/InvalidRefreshTokenException.kt b/src/main/kotlin/dev/usbharu/hideout/exception/InvalidRefreshTokenException.kt index 08c8ab7d..c43b3a50 100644 --- a/src/main/kotlin/dev/usbharu/hideout/exception/InvalidRefreshTokenException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/exception/InvalidRefreshTokenException.kt @@ -1,8 +1,15 @@ package dev.usbharu.hideout.exception +import java.io.Serial + class InvalidRefreshTokenException : IllegalArgumentException { constructor() : super() constructor(s: String?) : super(s) constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) + + companion object { + @Serial + private const val serialVersionUID: Long = -3779633753651907145L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/exception/InvalidUsernameOrPasswordException.kt b/src/main/kotlin/dev/usbharu/hideout/exception/InvalidUsernameOrPasswordException.kt index b9036aad..8dc0b4de 100644 --- a/src/main/kotlin/dev/usbharu/hideout/exception/InvalidUsernameOrPasswordException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/exception/InvalidUsernameOrPasswordException.kt @@ -1,8 +1,15 @@ package dev.usbharu.hideout.exception +import java.io.Serial + class InvalidUsernameOrPasswordException : IllegalArgumentException { constructor() : super() constructor(s: String?) : super(s) constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) + + companion object { + @Serial + private const val serialVersionUID: Long = -3638699928983322003L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/exception/JsonParseException.kt b/src/main/kotlin/dev/usbharu/hideout/exception/JsonParseException.kt index d5749f75..e822367d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/exception/JsonParseException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/exception/JsonParseException.kt @@ -1,8 +1,15 @@ package dev.usbharu.hideout.exception +import java.io.Serial + class JsonParseException : IllegalArgumentException { constructor() : super() constructor(s: String?) : super(s) constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) + + companion object { + @Serial + private const val serialVersionUID: Long = 7975567796830950692L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/exception/NotInitException.kt b/src/main/kotlin/dev/usbharu/hideout/exception/NotInitException.kt index 29b22484..6155a46f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/exception/NotInitException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/exception/NotInitException.kt @@ -1,8 +1,15 @@ package dev.usbharu.hideout.exception +import java.io.Serial + class NotInitException : IllegalStateException { constructor() : super() constructor(s: String?) : super(s) constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) + + companion object { + @Serial + private const val serialVersionUID: Long = -5859046179473905716L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/exception/ParameterNotExistException.kt b/src/main/kotlin/dev/usbharu/hideout/exception/ParameterNotExistException.kt index d3ca6693..22649c7d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/exception/ParameterNotExistException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/exception/ParameterNotExistException.kt @@ -1,8 +1,15 @@ package dev.usbharu.hideout.exception +import java.io.Serial + class ParameterNotExistException : IllegalArgumentException { constructor() : super() constructor(s: String?) : super(s) constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) + + companion object { + @Serial + private const val serialVersionUID: Long = -8845602757225726432L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/exception/PostNotFoundException.kt b/src/main/kotlin/dev/usbharu/hideout/exception/PostNotFoundException.kt index 9fe3cf78..26104de6 100644 --- a/src/main/kotlin/dev/usbharu/hideout/exception/PostNotFoundException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/exception/PostNotFoundException.kt @@ -1,8 +1,15 @@ package dev.usbharu.hideout.exception +import java.io.Serial + class PostNotFoundException : IllegalArgumentException { constructor() : super() constructor(s: String?) : super(s) constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) + + companion object { + @Serial + private const val serialVersionUID: Long = 7133035286017262876L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/exception/UserNotFoundException.kt b/src/main/kotlin/dev/usbharu/hideout/exception/UserNotFoundException.kt index 0c8ca15e..39b5d675 100644 --- a/src/main/kotlin/dev/usbharu/hideout/exception/UserNotFoundException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/exception/UserNotFoundException.kt @@ -1,8 +1,15 @@ package dev.usbharu.hideout.exception +import java.io.Serial + class UserNotFoundException : IllegalArgumentException { constructor() : super() constructor(s: String?) : super(s) constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) + + companion object { + @Serial + private const val serialVersionUID: Long = 6343548635914580823L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/exception/UsernameAlreadyExistException.kt b/src/main/kotlin/dev/usbharu/hideout/exception/UsernameAlreadyExistException.kt index bbd25d93..d9661bd4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/exception/UsernameAlreadyExistException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/exception/UsernameAlreadyExistException.kt @@ -1,8 +1,15 @@ package dev.usbharu.hideout.exception +import java.io.Serial + class UsernameAlreadyExistException : IllegalArgumentException { constructor() : super() constructor(s: String?) : super(s) constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) + + companion object { + @Serial + private const val serialVersionUID: Long = -4635016576575533883L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/exception/ap/IllegalActivityPubObjectException.kt b/src/main/kotlin/dev/usbharu/hideout/exception/ap/IllegalActivityPubObjectException.kt index 12965d62..7e63dbc4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/exception/ap/IllegalActivityPubObjectException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/exception/ap/IllegalActivityPubObjectException.kt @@ -1,8 +1,15 @@ package dev.usbharu.hideout.exception.ap +import java.io.Serial + class IllegalActivityPubObjectException : IllegalArgumentException { constructor() : super() constructor(s: String?) : super(s) constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) + + companion object { + @Serial + private const val serialVersionUID: Long = 7216998115771415263L + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/plugins/ActivityPub.kt b/src/main/kotlin/dev/usbharu/hideout/plugins/ActivityPub.kt index dcdea469..bed7c761 100644 --- a/src/main/kotlin/dev/usbharu/hideout/plugins/ActivityPub.kt +++ b/src/main/kotlin/dev/usbharu/hideout/plugins/ActivityPub.kt @@ -56,7 +56,10 @@ class HttpSignaturePluginConfig { lateinit var keyMap: KeyMap } -val httpSignaturePlugin = createClientPlugin("HttpSign", ::HttpSignaturePluginConfig) { +val httpSignaturePlugin: ClientPlugin = createClientPlugin( + "HttpSign", + ::HttpSignaturePluginConfig +) { val keyMap = pluginConfig.keyMap val format = SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US) format.timeZone = TimeZone.getTimeZone("GMT") @@ -141,13 +144,13 @@ val httpSignaturePlugin = createClientPlugin("HttpSign", ::HttpSignaturePluginCo request.headers.remove("Signature") - signer!!.sign(object : HttpMessage, HttpRequest { + (signer ?: return@onRequest).sign(object : HttpMessage, HttpRequest { override fun headerValues(name: String?): MutableList = name?.let { request.headers.getAll(it) }?.toMutableList() ?: mutableListOf() override fun addHeader(name: String?, value: String?) { val split = value?.split("=").orEmpty() - name?.let { request.header(it, split.get(0) + "=\"" + split.get(1).trim('"') + "\"") } + name?.let { request.header(it, split[0] + "=\"" + split[1].trim('"') + "\"") } } override fun method(): String = request.method.value diff --git a/src/main/kotlin/dev/usbharu/hideout/query/FollowerQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/query/FollowerQueryServiceImpl.kt index 218d793c..bb4f56fc 100644 --- a/src/main/kotlin/dev/usbharu/hideout/query/FollowerQueryServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/query/FollowerQueryServiceImpl.kt @@ -59,7 +59,7 @@ class FollowerQueryServiceImpl : FollowerQueryService { val followers = Users.alias("FOLLOWERS") return Users.innerJoin( otherTable = UsersFollowers, - onColumn = { Users.id }, + onColumn = { id }, otherColumn = { userId } ) .innerJoin( @@ -149,7 +149,7 @@ class FollowerQueryServiceImpl : FollowerQueryService { val followers = Users.alias("FOLLOWERS") return Users.innerJoin( otherTable = UsersFollowers, - onColumn = { Users.id }, + onColumn = { id }, otherColumn = { userId } ) .innerJoin( diff --git a/src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryService.kt b/src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryService.kt deleted file mode 100644 index 9c5263b8..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryService.kt +++ /dev/null @@ -1,39 +0,0 @@ -package dev.usbharu.hideout.query - -import dev.usbharu.hideout.domain.model.hideout.dto.PostResponse -import org.springframework.stereotype.Repository - -@Suppress("LongParameterList") -@Repository -interface PostResponseQueryService { - suspend fun findById(id: Long, userId: Long?): PostResponse - suspend fun findAll( - since: Long? = null, - until: Long? = null, - minId: Long? = null, - maxId: Long? = null, - limit: Int? = null, - userId: Long? = null - ): List - - suspend fun findByUserId( - userId: Long, - since: Long? = null, - until: Long? = null, - minId: Long? = null, - maxId: Long? = null, - limit: Int? = null, - userId2: Long? = null - ): List - - suspend fun findByUserNameAndUserDomain( - name: String, - domain: String, - since: Long? = null, - until: Long? = null, - minId: Long? = null, - maxId: Long? = null, - limit: Int? = null, - userId: Long? = null - ): List -} diff --git a/src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryServiceImpl.kt deleted file mode 100644 index b359707d..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/query/PostResponseQueryServiceImpl.kt +++ /dev/null @@ -1,70 +0,0 @@ -package dev.usbharu.hideout.query - -import dev.usbharu.hideout.domain.model.hideout.dto.PostResponse -import dev.usbharu.hideout.exception.FailedToGetResourcesException -import dev.usbharu.hideout.repository.Posts -import dev.usbharu.hideout.repository.Users -import dev.usbharu.hideout.repository.toPost -import dev.usbharu.hideout.repository.toUser -import dev.usbharu.hideout.util.singleOr -import org.jetbrains.exposed.sql.and -import org.jetbrains.exposed.sql.innerJoin -import org.jetbrains.exposed.sql.select -import org.jetbrains.exposed.sql.selectAll -import org.springframework.stereotype.Repository - -@Repository -class PostResponseQueryServiceImpl : PostResponseQueryService { - override suspend fun findById(id: Long, userId: Long?): PostResponse { - return Posts - .innerJoin(Users, onColumn = { Posts.userId }, otherColumn = { Users.id }) - .select { Posts.id eq id } - .singleOr { FailedToGetResourcesException("id: $id,userId: $userId is a duplicate or does not exist.", it) } - .let { PostResponse.from(it.toPost(), it.toUser()) } - } - - override suspend fun findAll( - since: Long?, - until: Long?, - minId: Long?, - maxId: Long?, - limit: Int?, - userId: Long? - ): List { - return Posts - .innerJoin(Users, onColumn = { Posts.userId }, otherColumn = { id }) - .selectAll() - .map { PostResponse.from(it.toPost(), it.toUser()) } - } - - override suspend fun findByUserId( - userId: Long, - since: Long?, - until: Long?, - minId: Long?, - maxId: Long?, - limit: Int?, - userId2: Long? - ): List { - return Posts - .innerJoin(Users, onColumn = { Posts.userId }, otherColumn = { id }) - .select { Posts.userId eq userId } - .map { PostResponse.from(it.toPost(), it.toUser()) } - } - - override suspend fun findByUserNameAndUserDomain( - name: String, - domain: String, - since: Long?, - until: Long?, - minId: Long?, - maxId: Long?, - limit: Int?, - userId: Long? - ): List { - return Posts - .innerJoin(Users, onColumn = { Posts.userId }, otherColumn = { id }) - .select { Users.name eq name and (Users.domain eq domain) } - .map { PostResponse.from(it.toPost(), it.toUser()) } - } -} diff --git a/src/main/kotlin/dev/usbharu/hideout/query/ReactionQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/query/ReactionQueryServiceImpl.kt deleted file mode 100644 index 4d9897d9..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/query/ReactionQueryServiceImpl.kt +++ /dev/null @@ -1,61 +0,0 @@ -package dev.usbharu.hideout.query - -import dev.usbharu.hideout.domain.model.hideout.dto.Account -import dev.usbharu.hideout.domain.model.hideout.dto.ReactionResponse -import dev.usbharu.hideout.domain.model.hideout.entity.Reaction -import dev.usbharu.hideout.exception.FailedToGetResourcesException -import dev.usbharu.hideout.repository.Reactions -import dev.usbharu.hideout.repository.Users -import dev.usbharu.hideout.repository.toReaction -import dev.usbharu.hideout.util.singleOr -import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq -import org.springframework.stereotype.Repository - -@Repository -class ReactionQueryServiceImpl : ReactionQueryService { - override suspend fun findByPostId(postId: Long, userId: Long?): List { - return Reactions.select { - Reactions.postId.eq(postId) - }.map { it.toReaction() } - } - - @Suppress("FunctionMaxLength") - override suspend fun findByPostIdAndUserIdAndEmojiId(postId: Long, userId: Long, emojiId: Long): Reaction { - return Reactions - .select { - Reactions.postId.eq(postId).and(Reactions.userId.eq(userId)).and( - Reactions.emojiId.eq(emojiId) - ) - } - .singleOr { - FailedToGetResourcesException( - "postId: $postId,userId: $userId,emojiId: $emojiId is duplicate or does not exist.", - it - ) - } - .toReaction() - } - - override suspend fun reactionAlreadyExist(postId: Long, userId: Long, emojiId: Long): Boolean { - return Reactions.select { - Reactions.postId.eq(postId).and(Reactions.userId.eq(userId)).and( - Reactions.emojiId.eq(emojiId) - ) - }.empty().not() - } - - override suspend fun deleteByPostIdAndUserId(postId: Long, userId: Long) { - Reactions.deleteWhere { Reactions.postId.eq(postId).and(Reactions.userId.eq(userId)) } - } - - override suspend fun findByPostIdWithUsers(postId: Long, userId: Long?): List { - return Reactions - .leftJoin(Users, onColumn = { Reactions.userId }, otherColumn = { id }) - .select { Reactions.postId.eq(postId) } - .groupBy { _: ResultRow -> ReactionResponse("❤", true, "", emptyList()) } - .map { entry: Map.Entry> -> - entry.key.copy(accounts = entry.value.map { Account(it[Users.screenName], "", it[Users.url]) }) - } - } -} diff --git a/src/main/kotlin/dev/usbharu/hideout/query/mastodon/StatusQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/query/mastodon/StatusQueryServiceImpl.kt index 71d3e0e1..ae9056f7 100644 --- a/src/main/kotlin/dev/usbharu/hideout/query/mastodon/StatusQueryServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/query/mastodon/StatusQueryServiceImpl.kt @@ -69,16 +69,7 @@ class StatusQueryServiceImpl : StatusQueryService { inReplyToAccountId = null, language = null, text = it[Posts.text], - editedAt = null, - application = null, - poll = null, - card = null, - favourited = null, - reblogged = null, - muted = null, - bookmarked = null, - pinned = null, - filtered = null + editedAt = null ) to it[Posts.repostId] } @@ -86,14 +77,14 @@ class StatusQueryServiceImpl : StatusQueryService { return pairs .map { if (it.second != null) { - it.first.copy(reblog = statuses.find { status -> status.id == it.second.toString() }) + it.first.copy(reblog = statuses.find { (id) -> id == it.second.toString() }) } else { it.first } } .map { if (it.inReplyToId != null) { - it.copy(inReplyToAccountId = statuses.find { status -> status.id == it.inReplyToId }?.id) + it.copy(inReplyToAccountId = statuses.find { (id) -> id == it.inReplyToId }?.id) } else { it } diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/MetaRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/MetaRepositoryImpl.kt index 03864cfb..132d8428 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/MetaRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/MetaRepositoryImpl.kt @@ -1,10 +1,7 @@ package dev.usbharu.hideout.repository import dev.usbharu.hideout.domain.model.hideout.entity.Jwt -import org.jetbrains.exposed.sql.Table -import org.jetbrains.exposed.sql.insert -import org.jetbrains.exposed.sql.select -import org.jetbrains.exposed.sql.update +import org.jetbrains.exposed.sql.* import org.springframework.stereotype.Repository import java.util.* @@ -41,10 +38,10 @@ class MetaRepositoryImpl : MetaRepository { } object Meta : Table("meta_info") { - val id = long("id") - val version = varchar("version", 1000) - val kid = varchar("kid", 1000) - val jwtPrivateKey = varchar("jwt_private_key", 100000) - val jwtPublicKey = varchar("jwt_public_key", 100000) + val id: Column = long("id") + val version: Column = varchar("version", 1000) + val kid: Column = varchar("kid", 1000) + val jwtPrivateKey: Column = varchar("jwt_private_key", 100000) + val jwtPublicKey: Column = varchar("jwt_public_key", 100000) override val primaryKey: PrimaryKey = PrimaryKey(id) } diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/PostRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/PostRepositoryImpl.kt index e4aad089..3bafd654 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/PostRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/PostRepositoryImpl.kt @@ -55,17 +55,17 @@ class PostRepositoryImpl(private val idGenerateService: IdGenerateService) : Pos } object Posts : Table() { - val id = long("id") - val userId = long("userId").references(Users.id) - val overview = varchar("overview", 100).nullable() - val text = varchar("text", 3000) - val createdAt = long("createdAt") - val visibility = integer("visibility").default(0) - val url = varchar("url", 500) - val repostId = long("repostId").references(id).nullable() - val replyId = long("replyId").references(id).nullable() - val sensitive = bool("sensitive").default(false) - val apId = varchar("ap_id", 100).uniqueIndex() + val id: Column = long("id") + val userId: Column = long("userId").references(Users.id) + val overview: Column = varchar("overview", 100).nullable() + val text: Column = varchar("text", 3000) + val createdAt: Column = long("createdAt") + val visibility: Column = integer("visibility").default(0) + val url: Column = varchar("url", 500) + val repostId: Column = long("repostId").references(id).nullable() + val replyId: Column = long("replyId").references(id).nullable() + val sensitive: Column = bool("sensitive").default(false) + val apId: Column = varchar("ap_id", 100).uniqueIndex() override val primaryKey: PrimaryKey = PrimaryKey(id) } diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt index 34789884..806e7841 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt @@ -53,9 +53,9 @@ fun ResultRow.toReaction(): Reaction { } object Reactions : LongIdTable("reactions") { - val emojiId = long("emoji_id") - val postId = long("post_id").references(Posts.id) - val userId = long("user_id").references(Users.id) + val emojiId: Column = long("emoji_id") + val postId: Column = long("post_id").references(Posts.id) + val userId: Column = long("user_id").references(Users.id) init { uniqueIndex(emojiId, postId, userId) diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt index 81632609..7c72725f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/RegisteredClientRepositoryImpl.kt @@ -10,6 +10,7 @@ import dev.usbharu.hideout.service.auth.ExposedOAuth2AuthorizationService import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.javatime.CurrentTimestamp import org.jetbrains.exposed.sql.javatime.timestamp +import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.security.jackson2.SecurityJackson2Modules import org.springframework.security.oauth2.core.AuthorizationGrantType @@ -40,9 +41,9 @@ class RegisteredClientRepositoryImpl : RegisteredClientRepository { it[clientSecretExpiresAt] = registeredClient.clientSecretExpiresAt it[clientName] = registeredClient.clientName it[clientAuthenticationMethods] = - registeredClient.clientAuthenticationMethods.map { method -> method.value }.joinToString(",") + registeredClient.clientAuthenticationMethods.joinToString(",") { method -> method.value } it[authorizationGrantTypes] = - registeredClient.authorizationGrantTypes.map { type -> type.value }.joinToString(",") + registeredClient.authorizationGrantTypes.joinToString(",") { type -> type.value } it[redirectUris] = registeredClient.redirectUris.joinToString(",") it[postLogoutRedirectUris] = registeredClient.postLogoutRedirectUris.joinToString(",") it[scopes] = registeredClient.scopes.joinToString(",") @@ -84,7 +85,7 @@ class RegisteredClientRepositoryImpl : RegisteredClientRepository { val toRegisteredClient = RegisteredClient.select { RegisteredClient.clientId eq clientId }.singleOrNull()?.toRegisteredClient() - LOGGER.trace("findByClientId: $toRegisteredClient") + LOGGER.trace("findByClientId: {}", toRegisteredClient) return toRegisteredClient } @@ -157,7 +158,7 @@ class RegisteredClientRepositoryImpl : RegisteredClientRepository { companion object { val objectMapper: ObjectMapper = ObjectMapper() - val LOGGER = LoggerFactory.getLogger(RegisteredClientRepositoryImpl::class.java) + val LOGGER: Logger = LoggerFactory.getLogger(RegisteredClientRepositoryImpl::class.java) init { @@ -172,19 +173,19 @@ class RegisteredClientRepositoryImpl : RegisteredClientRepository { // org/springframework/security/oauth2/server/authorization/client/oauth2-registered-client-schema.sql object RegisteredClient : Table("registered_client") { - val id = varchar("id", 100) - val clientId = varchar("client_id", 100) - val clientIdIssuedAt = timestamp("client_id_issued_at").defaultExpression(CurrentTimestamp()) - val clientSecret = varchar("client_secret", 200).nullable().default(null) - val clientSecretExpiresAt = timestamp("client_secret_expires_at").nullable().default(null) - val clientName = varchar("client_name", 200) - val clientAuthenticationMethods = varchar("client_authentication_methods", 1000) - val authorizationGrantTypes = varchar("authorization_grant_types", 1000) - val redirectUris = varchar("redirect_uris", 1000).nullable().default(null) - val postLogoutRedirectUris = varchar("post_logout_redirect_uris", 1000).nullable().default(null) - val scopes = varchar("scopes", 1000) - val clientSettings = varchar("client_settings", 2000) - val tokenSettings = varchar("token_settings", 2000) + val id: Column = varchar("id", 100) + val clientId: Column = varchar("client_id", 100) + val clientIdIssuedAt: Column = timestamp("client_id_issued_at").defaultExpression(CurrentTimestamp()) + val clientSecret: Column = varchar("client_secret", 200).nullable().default(null) + val clientSecretExpiresAt: Column = timestamp("client_secret_expires_at").nullable().default(null) + val clientName: Column = varchar("client_name", 200) + val clientAuthenticationMethods: Column = varchar("client_authentication_methods", 1000) + val authorizationGrantTypes: Column = varchar("authorization_grant_types", 1000) + val redirectUris: Column = varchar("redirect_uris", 1000).nullable().default(null) + val postLogoutRedirectUris: Column = varchar("post_logout_redirect_uris", 1000).nullable().default(null) + val scopes: Column = varchar("scopes", 1000) + val clientSettings: Column = varchar("client_settings", 2000) + val tokenSettings: Column = varchar("token_settings", 2000) - override val primaryKey = PrimaryKey(id) + override val primaryKey: PrimaryKey = PrimaryKey(id) } diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/UserRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/UserRepositoryImpl.kt index a5cbb82c..5bfa479f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/UserRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/UserRepositoryImpl.kt @@ -71,18 +71,24 @@ class UserRepositoryImpl(private val idGenerateService: IdGenerateService) : } object Users : Table("users") { - val id = long("id") - val name = varchar("name", length = Config.configData.characterLimit.account.id) - val domain = varchar("domain", length = Config.configData.characterLimit.general.domain) - val screenName = varchar("screen_name", length = Config.configData.characterLimit.account.name) - val description = varchar("description", length = Config.configData.characterLimit.account.description) - val password = varchar("password", length = 255).nullable() - val inbox = varchar("inbox", length = Config.configData.characterLimit.general.url).uniqueIndex() - val outbox = varchar("outbox", length = Config.configData.characterLimit.general.url).uniqueIndex() - val url = varchar("url", length = Config.configData.characterLimit.general.url).uniqueIndex() - val publicKey = varchar("public_key", length = Config.configData.characterLimit.general.publicKey) - val privateKey = varchar("private_key", length = Config.configData.characterLimit.general.privateKey).nullable() - val createdAt = long("created_at") + val id: Column = long("id") + val name: Column = varchar("name", length = Config.configData.characterLimit.account.id) + val domain: Column = varchar("domain", length = Config.configData.characterLimit.general.domain) + val screenName: Column = varchar("screen_name", length = Config.configData.characterLimit.account.name) + val description: Column = varchar( + "description", + length = Config.configData.characterLimit.account.description + ) + val password: Column = varchar("password", length = 255).nullable() + val inbox: Column = varchar("inbox", length = Config.configData.characterLimit.general.url).uniqueIndex() + val outbox: Column = varchar("outbox", length = Config.configData.characterLimit.general.url).uniqueIndex() + val url: Column = varchar("url", length = Config.configData.characterLimit.general.url).uniqueIndex() + val publicKey: Column = varchar("public_key", length = Config.configData.characterLimit.general.publicKey) + val privateKey: Column = varchar( + "private_key", + length = Config.configData.characterLimit.general.privateKey + ).nullable() + val createdAt: Column = long("created_at") override val primaryKey: PrimaryKey = PrimaryKey(id) @@ -109,8 +115,8 @@ fun ResultRow.toUser(): User { } object UsersFollowers : LongIdTable("users_followers") { - val userId = long("user_id").references(Users.id).index() - val followerId = long("follower_id").references(Users.id) + val userId: Column = long("user_id").references(Users.id).index() + val followerId: Column = long("follower_id").references(Users.id) init { uniqueIndex(userId, followerId) @@ -118,8 +124,8 @@ object UsersFollowers : LongIdTable("users_followers") { } object FollowRequests : LongIdTable("follow_requests") { - val userId = long("user_id").references(Users.id) - val followerId = long("follower_id").references(Users.id) + val userId: Column = long("user_id").references(Users.id) + val followerId: Column = long("follower_id").references(Users.id) init { uniqueIndex(userId, followerId) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APAcceptService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APAcceptService.kt index 3cf16f03..00b6777c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APAcceptService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APAcceptService.kt @@ -12,7 +12,6 @@ import dev.usbharu.hideout.service.user.UserService import io.ktor.http.* import org.springframework.stereotype.Service -@Service interface APAcceptService { suspend fun receiveAccept(accept: Accept): ActivityPubResponse } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APCreateService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APCreateService.kt index 91aecea4..82d6013a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APCreateService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APCreateService.kt @@ -9,7 +9,6 @@ import dev.usbharu.hideout.service.core.Transaction import io.ktor.http.* import org.springframework.stereotype.Service -@Service interface APCreateService { suspend fun receiveCreate(create: Create): ActivityPubResponse } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APLikeService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APLikeService.kt index 62a8e39e..089f8b50 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APLikeService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APLikeService.kt @@ -10,7 +10,6 @@ import dev.usbharu.hideout.service.reaction.ReactionService import io.ktor.http.* import org.springframework.stereotype.Service -@Service interface APLikeService { suspend fun receiveLike(like: Like): ActivityPubResponse } @@ -29,9 +28,9 @@ class APLikeServiceImpl( like.`object` ?: throw IllegalActivityPubObjectException("object is null") transaction.transaction(java.sql.Connection.TRANSACTION_SERIALIZABLE) { val person = apUserService.fetchPersonWithEntity(actor) - apNoteService.fetchNote(like.`object`!!) + apNoteService.fetchNote(like.`object` ?: return@transaction) - val post = postQueryService.findByUrl(like.`object`!!) + val post = postQueryService.findByUrl(like.`object` ?: return@transaction) reactionService.receiveReaction( content, diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt index 2b6ce229..bc1958ea 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt @@ -27,7 +27,6 @@ import org.springframework.beans.factory.annotation.Qualifier import org.springframework.stereotype.Service import java.time.Instant -@Service interface APNoteService { suspend fun createNote(post: Post) @@ -57,7 +56,7 @@ class APNoteServiceImpl( postService.addInterceptor(this) } - private val logger = LoggerFactory.getLogger(this::class.java) + private val logger = LoggerFactory.getLogger(APNoteServiceImpl::class.java) override suspend fun createNote(post: Post) { val followers = followerQueryService.findFollowersById(post.userId) @@ -81,7 +80,7 @@ class APNoteServiceImpl( attributedTo = actor, content = postEntity.text, published = Instant.ofEpochMilli(postEntity.createdAt).toString(), - to = listOf(public, actor + "/follower") + to = listOf(public, "$actor/follower") ) val inbox = props[DeliverPostJob.inbox] logger.debug("createNoteJob: actor={}, note={}, inbox={}", actor, postEntity, inbox) @@ -173,12 +172,10 @@ class APNoteServiceImpl( Post.of( id = postRepository.generateId(), userId = person.second.id, - overview = null, text = note.content.orEmpty(), createdAt = Instant.parse(note.published).toEpochMilli(), visibility = visibility, url = note.id ?: url, - repostId = null, replyId = reply?.id, sensitive = note.sensitive, apId = note.id ?: url, diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APReactionService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APReactionService.kt index eacef3cc..d4c1dfd1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APReactionService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APReactionService.kt @@ -19,7 +19,6 @@ import org.springframework.beans.factory.annotation.Qualifier import org.springframework.stereotype.Service import java.time.Instant -@Service interface APReactionService { suspend fun reaction(like: Reaction) suspend fun removeReaction(like: Reaction) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APSendFollowService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APSendFollowService.kt index b2069234..97d50c5d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APSendFollowService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APSendFollowService.kt @@ -8,7 +8,6 @@ import io.ktor.client.* import org.springframework.beans.factory.annotation.Qualifier import org.springframework.stereotype.Service -@Service interface APSendFollowService { suspend fun sendFollow(sendFollowDto: SendFollowDto) } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APService.kt index aa2d9781..146a70de 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APService.kt @@ -14,7 +14,6 @@ import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Qualifier import org.springframework.stereotype.Service -@Service interface APService { fun parseActivity(json: String): ActivityType @@ -186,7 +185,7 @@ class APServiceImpl( @Qualifier("activitypub") private val objectMapper: ObjectMapper ) : APService { - val logger: Logger = LoggerFactory.getLogger(this::class.java) + val logger: Logger = LoggerFactory.getLogger(APServiceImpl::class.java) override fun parseActivity(json: String): ActivityType { val readTree = objectMapper.readTree(json) logger.trace("readTree: {}", readTree) @@ -229,16 +228,16 @@ class APServiceImpl( // println(apReceiveFollowService::class.java) // apReceiveFollowService.receiveFollowJob(job.props as JobProps) - when { - hideoutJob is ReceiveFollowJob -> { + when (hideoutJob) { + is ReceiveFollowJob -> { apReceiveFollowService.receiveFollowJob( job.props as JobProps ) } - hideoutJob is DeliverPostJob -> apNoteService.createNoteJob(job.props as JobProps) - hideoutJob is DeliverReactionJob -> apReactionService.reactionJob(job.props as JobProps) - hideoutJob is DeliverRemoveReactionJob -> apReactionService.removeReactionJob( + is DeliverPostJob -> apNoteService.createNoteJob(job.props as JobProps) + is DeliverReactionJob -> apReactionService.reactionJob(job.props as JobProps) + is DeliverRemoveReactionJob -> apReactionService.removeReactionJob( job.props as JobProps ) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APUndoService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APUndoService.kt index 39c23be2..db4fe99c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APUndoService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APUndoService.kt @@ -10,7 +10,6 @@ import dev.usbharu.hideout.service.user.UserService import io.ktor.http.* import org.springframework.stereotype.Service -@Service interface APUndoService { suspend fun receiveUndo(undo: Undo): ActivityPubResponse } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APUserService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APUserService.kt index abb7423f..49056e21 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APUserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APUserService.kt @@ -22,7 +22,6 @@ import io.ktor.http.* import org.springframework.beans.factory.annotation.Qualifier import org.springframework.stereotype.Service -@Service interface APUserService { suspend fun getPersonByName(name: String): Person diff --git a/src/main/kotlin/dev/usbharu/hideout/service/api/PostApiService.kt b/src/main/kotlin/dev/usbharu/hideout/service/api/PostApiService.kt deleted file mode 100644 index 0c4240e8..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/service/api/PostApiService.kt +++ /dev/null @@ -1,129 +0,0 @@ -package dev.usbharu.hideout.service.api - -import dev.usbharu.hideout.config.ApplicationConfig -import dev.usbharu.hideout.domain.model.hideout.dto.PostCreateDto -import dev.usbharu.hideout.domain.model.hideout.dto.PostResponse -import dev.usbharu.hideout.domain.model.hideout.dto.ReactionResponse -import dev.usbharu.hideout.domain.model.hideout.form.Post -import dev.usbharu.hideout.query.PostResponseQueryService -import dev.usbharu.hideout.query.ReactionQueryService -import dev.usbharu.hideout.repository.UserRepository -import dev.usbharu.hideout.service.core.Transaction -import dev.usbharu.hideout.service.post.PostService -import dev.usbharu.hideout.service.reaction.ReactionService -import dev.usbharu.hideout.util.AcctUtil -import org.springframework.stereotype.Service -import java.time.Instant - -@Suppress("LongParameterList") -@Service -interface PostApiService { - suspend fun createPost(postForm: dev.usbharu.hideout.domain.model.hideout.form.Post, userId: Long): PostResponse - suspend fun getById(id: Long, userId: Long?): PostResponse - suspend fun getAll( - since: Instant? = null, - until: Instant? = null, - minId: Long? = null, - maxId: Long? = null, - limit: Int? = null, - userId: Long? = null - ): List - - suspend fun getByUser( - nameOrId: String, - since: Instant? = null, - until: Instant? = null, - minId: Long? = null, - maxId: Long? = null, - limit: Int? = null, - userId: Long? = null - ): List - - suspend fun getReactionByPostId(postId: Long, userId: Long? = null): List - suspend fun appendReaction(reaction: String, userId: Long, postId: Long) - suspend fun removeReaction(userId: Long, postId: Long) -} - -@Service -class PostApiServiceImpl( - private val postService: PostService, - private val userRepository: UserRepository, - private val postResponseQueryService: PostResponseQueryService, - private val reactionQueryService: ReactionQueryService, - private val reactionService: ReactionService, - private val transaction: Transaction, - private val applicationConfig: ApplicationConfig -) : PostApiService { - override suspend fun createPost(postForm: Post, userId: Long): PostResponse { - return transaction.transaction { - val createdPost = postService.createLocal( - PostCreateDto( - text = postForm.text, - overview = postForm.overview, - visibility = postForm.visibility, - repostId = postForm.repostId, - repolyId = postForm.replyId, - userId = userId - ) - ) - val creator = userRepository.findById(userId) - PostResponse.from(createdPost, creator!!) - } - } - - override suspend fun getById(id: Long, userId: Long?): PostResponse = postResponseQueryService.findById(id, userId) - - override suspend fun getAll( - since: Instant?, - until: Instant?, - minId: Long?, - maxId: Long?, - limit: Int?, - userId: Long? - ): List = transaction.transaction { - postResponseQueryService.findAll( - since = since?.toEpochMilli(), - until = until?.toEpochMilli(), - minId = minId, - maxId = maxId, - limit = limit, - userId = userId - ) - } - - override suspend fun getByUser( - nameOrId: String, - since: Instant?, - until: Instant?, - minId: Long?, - maxId: Long?, - limit: Int?, - userId: Long? - ): List { - val idOrNull = nameOrId.toLongOrNull() - return if (idOrNull == null) { - val acct = AcctUtil.parse(nameOrId) - postResponseQueryService.findByUserNameAndUserDomain( - acct.username, - acct.domain ?: applicationConfig.url.host - ) - } else { - postResponseQueryService.findByUserId(idOrNull) - } - } - - override suspend fun getReactionByPostId(postId: Long, userId: Long?): List = - transaction.transaction { reactionQueryService.findByPostIdWithUsers(postId, userId) } - - override suspend fun appendReaction(reaction: String, userId: Long, postId: Long) { - transaction.transaction { - reactionService.sendReaction(reaction, userId, postId) - } - } - - override suspend fun removeReaction(userId: Long, postId: Long) { - transaction.transaction { - reactionService.removeReaction(userId, postId) - } - } -} diff --git a/src/main/kotlin/dev/usbharu/hideout/service/api/UserApiService.kt b/src/main/kotlin/dev/usbharu/hideout/service/api/UserApiService.kt deleted file mode 100644 index 9bc4e38e..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/service/api/UserApiService.kt +++ /dev/null @@ -1,116 +0,0 @@ -package dev.usbharu.hideout.service.api - -import dev.usbharu.hideout.config.ApplicationConfig -import dev.usbharu.hideout.domain.model.Acct -import dev.usbharu.hideout.domain.model.hideout.dto.UserCreateDto -import dev.usbharu.hideout.domain.model.hideout.dto.UserResponse -import dev.usbharu.hideout.exception.UsernameAlreadyExistException -import dev.usbharu.hideout.query.FollowerQueryService -import dev.usbharu.hideout.query.UserQueryService -import dev.usbharu.hideout.service.core.Transaction -import dev.usbharu.hideout.service.user.UserService -import org.springframework.stereotype.Service -import kotlin.math.min - -@Suppress("TooManyFunctions") -@Service -interface UserApiService { - suspend fun findAll(limit: Int? = 100, offset: Long = 0): List - - suspend fun findById(id: Long): UserResponse - - suspend fun findByIds(ids: List): List - - suspend fun findByAcct(acct: Acct): UserResponse - - suspend fun findFollowers(userId: Long): List - - suspend fun findFollowings(userId: Long): List - - suspend fun findFollowersByAcct(acct: Acct): List - - suspend fun findFollowingsByAcct(acct: Acct): List - - suspend fun createUser(username: String, password: String): UserResponse - - suspend fun follow(targetId: Long, sourceId: Long): Boolean - suspend fun follow(targetAcct: Acct, sourceId: Long): Boolean -} - -@Service -class UserApiServiceImpl( - private val userQueryService: UserQueryService, - private val followerQueryService: FollowerQueryService, - private val userService: UserService, - private val transaction: Transaction, - private val applicationConfig: ApplicationConfig -) : UserApiService { - override suspend fun findAll(limit: Int?, offset: Long): List = transaction.transaction { - userQueryService.findAll(min(limit ?: 100, 100), offset).map { UserResponse.from(it) } - } - - override suspend fun findById(id: Long): UserResponse = - transaction.transaction { UserResponse.from(userQueryService.findById(id)) } - - override suspend fun findByIds(ids: List): List { - return transaction.transaction { - userQueryService.findByIds(ids).map { UserResponse.from(it) } - } - } - - override suspend fun findByAcct(acct: Acct): UserResponse { - return transaction.transaction { - UserResponse.from( - userQueryService.findByNameAndDomain( - acct.username, - acct.domain ?: applicationConfig.url.host - ) - ) - } - } - - override suspend fun findFollowers(userId: Long): List = transaction.transaction { - followerQueryService.findFollowersById(userId).map { UserResponse.from(it) } - } - - override suspend fun findFollowings(userId: Long): List = transaction.transaction { - followerQueryService.findFollowingById(userId).map { UserResponse.from(it) } - } - - override suspend fun findFollowersByAcct(acct: Acct): List = transaction.transaction { - followerQueryService.findFollowersByNameAndDomain(acct.username, acct.domain ?: applicationConfig.url.host) - .map { UserResponse.from(it) } - } - - override suspend fun findFollowingsByAcct(acct: Acct): List = transaction.transaction { - followerQueryService.findFollowingByNameAndDomain(acct.username, acct.domain ?: applicationConfig.url.host) - .map { UserResponse.from(it) } - } - - override suspend fun createUser(username: String, password: String): UserResponse { - return transaction.transaction { - if (userQueryService.existByNameAndDomain(username, applicationConfig.url.host)) { - throw UsernameAlreadyExistException() - } - UserResponse.from(userService.createLocalUser(UserCreateDto(username, username, "", password))) - } - } - - override suspend fun follow(targetId: Long, sourceId: Long): Boolean { - return transaction.transaction { - userService.followRequest(targetId, sourceId) - } - } - - override suspend fun follow(targetAcct: Acct, sourceId: Long): Boolean { - return transaction.transaction { - userService.followRequest( - userQueryService.findByNameAndDomain( - targetAcct.username, - targetAcct.domain ?: applicationConfig.url.host - ).id, - sourceId - ) - } - } -} diff --git a/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/StatusesApiService.kt b/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/StatusesApiService.kt index 4fd1e4fa..bebaa59a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/StatusesApiService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/StatusesApiService.kt @@ -42,7 +42,6 @@ class StatsesApiServiceImpl( text = statusesRequest.status.orEmpty(), overview = statusesRequest.spoilerText, visibility = visibility, - repostId = null, repolyId = statusesRequest.inReplyToId?.toLongOrNull(), userId = userId ) @@ -86,19 +85,9 @@ class StatsesApiServiceImpl( url = post.url, inReplyToId = post.replyId?.toString(), inReplyToAccountId = replyUser?.toString(), - reblog = null, language = null, text = post.text, - editedAt = null, - application = null, - poll = null, - card = null, - favourited = null, - reblogged = null, - muted = null, - bookmarked = null, - pinned = null, - filtered = null + editedAt = null ) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/TimelineApiService.kt b/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/TimelineApiService.kt index 2dfc1f24..7f2a39e4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/TimelineApiService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/TimelineApiService.kt @@ -60,8 +60,6 @@ class TimelineApiServiceImpl( ): List = transaction.transaction { generateTimelineService.getTimeline( forUserId = userId, - localOnly = false, - mediaOnly = false, maxId = maxId, minId = minId, sinceId = sinceId, diff --git a/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationConsentService.kt b/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationConsentService.kt index 469de633..d03ffde4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationConsentService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationConsentService.kt @@ -17,7 +17,7 @@ class ExposedOAuth2AuthorizationConsentService( ) : OAuth2AuthorizationConsentService { - override fun save(authorizationConsent: AuthorizationConsent?) = runBlocking { + override fun save(authorizationConsent: AuthorizationConsent?): Unit = runBlocking { requireNotNull(authorizationConsent) transaction.transaction { val singleOrNull = @@ -74,8 +74,8 @@ class ExposedOAuth2AuthorizationConsentService( } object OAuth2AuthorizationConsent : Table("oauth2_authorization_consent") { - val registeredClientId = varchar("registered_client_id", 100) - val principalName = varchar("principal_name", 200) - val authorities = varchar("authorities", 1000) - override val primaryKey = PrimaryKey(registeredClientId, principalName) + val registeredClientId: Column = varchar("registered_client_id", 100) + val principalName: Column = varchar("principal_name", 200) + val authorities: Column = varchar("authorities", 1000) + override val primaryKey: PrimaryKey = PrimaryKey(registeredClientId, principalName) } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt b/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt index b3c3a2a2..1d93e49b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/auth/ExposedOAuth2AuthorizationService.kt @@ -23,6 +23,7 @@ import org.springframework.security.oauth2.server.authorization.OAuth2TokenType import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository import org.springframework.security.oauth2.server.authorization.jackson2.OAuth2AuthorizationServerJackson2Module import org.springframework.stereotype.Service +import java.time.Instant @Service class ExposedOAuth2AuthorizationService( @@ -133,7 +134,7 @@ class ExposedOAuth2AuthorizationService( if (authorization == null) { return } - Authorization.deleteWhere { Authorization.id eq authorization.id } + Authorization.deleteWhere { id eq authorization.id } } override fun findById(id: String?): OAuth2Authorization? { @@ -336,40 +337,44 @@ class ExposedOAuth2AuthorizationService( } object Authorization : Table("application_authorization") { - val id = varchar("id", 255) - val registeredClientId = varchar("registered_client_id", 255) - val principalName = varchar("principal_name", 255) - val authorizationGrantType = varchar("authorization_grant_type", 255) - val authorizedScopes = varchar("authorized_scopes", 1000).nullable().default(null) - val attributes = varchar("attributes", 4000).nullable().default(null) - val state = varchar("state", 500).nullable().default(null) - val authorizationCodeValue = varchar("authorization_code_value", 4000).nullable().default(null) - val authorizationCodeIssuedAt = timestamp("authorization_code_issued_at").nullable().default(null) - val authorizationCodeExpiresAt = timestamp("authorization_code_expires_at").nullable().default(null) - val authorizationCodeMetadata = varchar("authorization_code_metadata", 2000).nullable().default(null) - val accessTokenValue = varchar("access_token_value", 4000).nullable().default(null) - val accessTokenIssuedAt = timestamp("access_token_issued_at").nullable().default(null) - val accessTokenExpiresAt = timestamp("access_token_expires_at").nullable().default(null) - val accessTokenMetadata = varchar("access_token_metadata", 2000).nullable().default(null) - val accessTokenType = varchar("access_token_type", 255).nullable().default(null) - val accessTokenScopes = varchar("access_token_scopes", 1000).nullable().default(null) - val refreshTokenValue = varchar("refresh_token_value", 4000).nullable().default(null) - val refreshTokenIssuedAt = timestamp("refresh_token_issued_at").nullable().default(null) - val refreshTokenExpiresAt = timestamp("refresh_token_expires_at").nullable().default(null) - val refreshTokenMetadata = varchar("refresh_token_metadata", 2000).nullable().default(null) - val oidcIdTokenValue = varchar("oidc_id_token_value", 4000).nullable().default(null) - val oidcIdTokenIssuedAt = timestamp("oidc_id_token_issued_at").nullable().default(null) - val oidcIdTokenExpiresAt = timestamp("oidc_id_token_expires_at").nullable().default(null) - val oidcIdTokenMetadata = varchar("oidc_id_token_metadata", 2000).nullable().default(null) - val oidcIdTokenClaims = varchar("oidc_id_token_claims", 2000).nullable().default(null) - val userCodeValue = varchar("user_code_value", 4000).nullable().default(null) - val userCodeIssuedAt = timestamp("user_code_issued_at").nullable().default(null) - val userCodeExpiresAt = timestamp("user_code_expires_at").nullable().default(null) - val userCodeMetadata = varchar("user_code_metadata", 2000).nullable().default(null) - val deviceCodeValue = varchar("device_code_value", 4000).nullable().default(null) - val deviceCodeIssuedAt = timestamp("device_code_issued_at").nullable().default(null) - val deviceCodeExpiresAt = timestamp("device_code_expires_at").nullable().default(null) - val deviceCodeMetadata = varchar("device_code_metadata", 2000).nullable().default(null) + val id: Column = varchar("id", 255) + val registeredClientId: Column = varchar("registered_client_id", 255) + val principalName: Column = varchar("principal_name", 255) + val authorizationGrantType: Column = varchar("authorization_grant_type", 255) + val authorizedScopes: Column = varchar("authorized_scopes", 1000).nullable().default(null) + val attributes: Column = varchar("attributes", 4000).nullable().default(null) + val state: Column = varchar("state", 500).nullable().default(null) + val authorizationCodeValue: Column = varchar("authorization_code_value", 4000).nullable().default(null) + val authorizationCodeIssuedAt: Column = timestamp("authorization_code_issued_at").nullable().default(null) + val authorizationCodeExpiresAt: Column = timestamp("authorization_code_expires_at").nullable().default( + null + ) + val authorizationCodeMetadata: Column = varchar("authorization_code_metadata", 2000).nullable().default( + null + ) + val accessTokenValue: Column = varchar("access_token_value", 4000).nullable().default(null) + val accessTokenIssuedAt: Column = timestamp("access_token_issued_at").nullable().default(null) + val accessTokenExpiresAt: Column = timestamp("access_token_expires_at").nullable().default(null) + val accessTokenMetadata: Column = varchar("access_token_metadata", 2000).nullable().default(null) + val accessTokenType: Column = varchar("access_token_type", 255).nullable().default(null) + val accessTokenScopes: Column = varchar("access_token_scopes", 1000).nullable().default(null) + val refreshTokenValue: Column = varchar("refresh_token_value", 4000).nullable().default(null) + val refreshTokenIssuedAt: Column = timestamp("refresh_token_issued_at").nullable().default(null) + val refreshTokenExpiresAt: Column = timestamp("refresh_token_expires_at").nullable().default(null) + val refreshTokenMetadata: Column = varchar("refresh_token_metadata", 2000).nullable().default(null) + val oidcIdTokenValue: Column = varchar("oidc_id_token_value", 4000).nullable().default(null) + val oidcIdTokenIssuedAt: Column = timestamp("oidc_id_token_issued_at").nullable().default(null) + val oidcIdTokenExpiresAt: Column = timestamp("oidc_id_token_expires_at").nullable().default(null) + val oidcIdTokenMetadata: Column = varchar("oidc_id_token_metadata", 2000).nullable().default(null) + val oidcIdTokenClaims: Column = varchar("oidc_id_token_claims", 2000).nullable().default(null) + val userCodeValue: Column = varchar("user_code_value", 4000).nullable().default(null) + val userCodeIssuedAt: Column = timestamp("user_code_issued_at").nullable().default(null) + val userCodeExpiresAt: Column = timestamp("user_code_expires_at").nullable().default(null) + val userCodeMetadata: Column = varchar("user_code_metadata", 2000).nullable().default(null) + val deviceCodeValue: Column = varchar("device_code_value", 4000).nullable().default(null) + val deviceCodeIssuedAt: Column = timestamp("device_code_issued_at").nullable().default(null) + val deviceCodeExpiresAt: Column = timestamp("device_code_expires_at").nullable().default(null) + val deviceCodeMetadata: Column = varchar("device_code_metadata", 2000).nullable().default(null) - override val primaryKey = PrimaryKey(id) + override val primaryKey: PrimaryKey = PrimaryKey(id) } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/core/MetaServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/core/MetaServiceImpl.kt index cab68f79..7dac4813 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/core/MetaServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/core/MetaServiceImpl.kt @@ -12,7 +12,7 @@ class MetaServiceImpl(private val metaRepository: MetaRepository, private val tr override suspend fun getMeta(): Meta = transaction.transaction { metaRepository.get() ?: throw NotInitException("Meta is null") } - override suspend fun updateMeta(meta: Meta) = transaction.transaction { + override suspend fun updateMeta(meta: Meta): Unit = transaction.transaction { metaRepository.save(meta) } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt index a86c2227..755e5bb7 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt @@ -44,9 +44,7 @@ class PostServiceImpl( text = post.text, createdAt = Instant.now().toEpochMilli(), visibility = post.visibility, - url = "${user.url}/posts/$id", - repostId = null, - replyId = null + url = "${user.url}/posts/$id" ) return internalCreate(createPost, isLocal) } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthServiceImpl.kt index f059db4a..f6ca9424 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/user/UserAuthServiceImpl.kt @@ -26,8 +26,8 @@ class UserAuthServiceImpl( companion object { val sha256: MessageDigest = MessageDigest.getInstance("SHA-256") - const val keySize = 2048 - const val pemSize = 64 + const val keySize: Int = 2048 + const val pemSize: Int = 64 } } diff --git a/src/main/kotlin/dev/usbharu/kjob/exposed/ExposedKJob.kt b/src/main/kotlin/dev/usbharu/kjob/exposed/ExposedKJob.kt index 7d1f59ac..1a688f28 100644 --- a/src/main/kotlin/dev/usbharu/kjob/exposed/ExposedKJob.kt +++ b/src/main/kotlin/dev/usbharu/kjob/exposed/ExposedKJob.kt @@ -26,7 +26,7 @@ class ExposedKJob(config: Configuration) : BaseKJob(c return super.start() } - override fun shutdown() = runBlocking { + override fun shutdown(): Unit = runBlocking { super.shutdown() lockRepository.clearExpired() } @@ -40,10 +40,10 @@ class ExposedKJob(config: Configuration) : BaseKJob(c var driverClassName: String? = null var connectionDatabase: Database? = null - var jobTableName = "kjobJobs" + var jobTableName: String = "kjobJobs" - var lockTableName = "kjobLocks" + var lockTableName: String = "kjobLocks" - var expireLockInMinutes = 5L + var expireLockInMinutes: Long = 5L } }