mirror of https://github.com/usbharu/Hideout.git
Merge pull request #73 from usbharu/refactor-all
refactor: 不要なファイルを削除、インスペクションを解消
This commit is contained in:
commit
a7f5a33b9e
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
package dev.usbharu.hideout.domain.model.api.mastodon
|
||||
|
||||
data class StatusForPost(
|
||||
val status: String,
|
||||
val userId: Long
|
||||
)
|
|
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
)
|
|
@ -1,3 +0,0 @@
|
|||
package dev.usbharu.hideout.domain.model.hideout.form
|
||||
|
||||
data class Reaction(val reaction: String?)
|
|
@ -1,3 +0,0 @@
|
|||
package dev.usbharu.hideout.domain.model.hideout.form
|
||||
|
||||
data class RefreshToken(val refreshToken: String)
|
|
@ -1,3 +0,0 @@
|
|||
package dev.usbharu.hideout.domain.model.hideout.form
|
||||
|
||||
data class UserCreate(val username: String, val password: String)
|
|
@ -1,3 +0,0 @@
|
|||
package dev.usbharu.hideout.domain.model.hideout.form
|
||||
|
||||
data class UserLogin(val username: String, val password: String)
|
|
@ -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<ReceiveFollowJob, String> = string("actor")
|
||||
val follow: Prop<ReceiveFollowJob, String> = string("follow")
|
||||
val targetActor: Prop<ReceiveFollowJob, String> = string("targetActor")
|
||||
}
|
||||
|
||||
@Component
|
||||
object DeliverPostJob : HideoutJob("DeliverPostJob") {
|
||||
val post = string("post")
|
||||
val actor = string("actor")
|
||||
val inbox = string("inbox")
|
||||
val post: Prop<DeliverPostJob, String> = string("post")
|
||||
val actor: Prop<DeliverPostJob, String> = string("actor")
|
||||
val inbox: Prop<DeliverPostJob, String> = 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<DeliverReactionJob, String> = string("reaction")
|
||||
val postUrl: Prop<DeliverReactionJob, String> = string("postUrl")
|
||||
val actor: Prop<DeliverReactionJob, String> = string("actor")
|
||||
val inbox: Prop<DeliverReactionJob, String> = string("inbox")
|
||||
val id: Prop<DeliverReactionJob, String> = 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<DeliverRemoveReactionJob, String> = string("id")
|
||||
val inbox: Prop<DeliverRemoveReactionJob, String> = string("inbox")
|
||||
val actor: Prop<DeliverRemoveReactionJob, String> = string("actor")
|
||||
val like: Prop<DeliverRemoveReactionJob, String> = string("like")
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
@file:Suppress("ClassName")
|
||||
|
||||
package dev.usbharu.hideout.domain.model.wellknown
|
||||
|
||||
@Suppress("ClassNaming")
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,10 @@ class HttpSignaturePluginConfig {
|
|||
lateinit var keyMap: KeyMap
|
||||
}
|
||||
|
||||
val httpSignaturePlugin = createClientPlugin("HttpSign", ::HttpSignaturePluginConfig) {
|
||||
val httpSignaturePlugin: ClientPlugin<HttpSignaturePluginConfig> = 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<String> =
|
||||
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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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<PostResponse>
|
||||
|
||||
suspend fun findByUserId(
|
||||
userId: Long,
|
||||
since: Long? = null,
|
||||
until: Long? = null,
|
||||
minId: Long? = null,
|
||||
maxId: Long? = null,
|
||||
limit: Int? = null,
|
||||
userId2: Long? = null
|
||||
): List<PostResponse>
|
||||
|
||||
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<PostResponse>
|
||||
}
|
|
@ -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<PostResponse> {
|
||||
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<PostResponse> {
|
||||
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<PostResponse> {
|
||||
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()) }
|
||||
}
|
||||
}
|
|
@ -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<Reaction> {
|
||||
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<ReactionResponse> {
|
||||
return Reactions
|
||||
.leftJoin(Users, onColumn = { Reactions.userId }, otherColumn = { id })
|
||||
.select { Reactions.postId.eq(postId) }
|
||||
.groupBy { _: ResultRow -> ReactionResponse("❤", true, "", emptyList()) }
|
||||
.map { entry: Map.Entry<ReactionResponse, List<ResultRow>> ->
|
||||
entry.key.copy(accounts = entry.value.map { Account(it[Users.screenName], "", it[Users.url]) })
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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> = long("id")
|
||||
val version: Column<String> = varchar("version", 1000)
|
||||
val kid: Column<String> = varchar("kid", 1000)
|
||||
val jwtPrivateKey: Column<String> = varchar("jwt_private_key", 100000)
|
||||
val jwtPublicKey: Column<String> = varchar("jwt_public_key", 100000)
|
||||
override val primaryKey: PrimaryKey = PrimaryKey(id)
|
||||
}
|
||||
|
|
|
@ -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> = long("id")
|
||||
val userId: Column<Long> = long("userId").references(Users.id)
|
||||
val overview: Column<String?> = varchar("overview", 100).nullable()
|
||||
val text: Column<String> = varchar("text", 3000)
|
||||
val createdAt: Column<Long> = long("createdAt")
|
||||
val visibility: Column<Int> = integer("visibility").default(0)
|
||||
val url: Column<String> = varchar("url", 500)
|
||||
val repostId: Column<Long?> = long("repostId").references(id).nullable()
|
||||
val replyId: Column<Long?> = long("replyId").references(id).nullable()
|
||||
val sensitive: Column<Boolean> = bool("sensitive").default(false)
|
||||
val apId: Column<String> = varchar("ap_id", 100).uniqueIndex()
|
||||
override val primaryKey: PrimaryKey = PrimaryKey(id)
|
||||
}
|
||||
|
||||
|
|
|
@ -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> = long("emoji_id")
|
||||
val postId: Column<Long> = long("post_id").references(Posts.id)
|
||||
val userId: Column<Long> = long("user_id").references(Users.id)
|
||||
|
||||
init {
|
||||
uniqueIndex(emojiId, postId, userId)
|
||||
|
|
|
@ -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<String> = varchar("id", 100)
|
||||
val clientId: Column<String> = varchar("client_id", 100)
|
||||
val clientIdIssuedAt: Column<Instant> = timestamp("client_id_issued_at").defaultExpression(CurrentTimestamp())
|
||||
val clientSecret: Column<String?> = varchar("client_secret", 200).nullable().default(null)
|
||||
val clientSecretExpiresAt: Column<Instant?> = timestamp("client_secret_expires_at").nullable().default(null)
|
||||
val clientName: Column<String> = varchar("client_name", 200)
|
||||
val clientAuthenticationMethods: Column<String> = varchar("client_authentication_methods", 1000)
|
||||
val authorizationGrantTypes: Column<String> = varchar("authorization_grant_types", 1000)
|
||||
val redirectUris: Column<String?> = varchar("redirect_uris", 1000).nullable().default(null)
|
||||
val postLogoutRedirectUris: Column<String?> = varchar("post_logout_redirect_uris", 1000).nullable().default(null)
|
||||
val scopes: Column<String> = varchar("scopes", 1000)
|
||||
val clientSettings: Column<String> = varchar("client_settings", 2000)
|
||||
val tokenSettings: Column<String> = varchar("token_settings", 2000)
|
||||
|
||||
override val primaryKey = PrimaryKey(id)
|
||||
override val primaryKey: PrimaryKey = PrimaryKey(id)
|
||||
}
|
||||
|
|
|
@ -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> = long("id")
|
||||
val name: Column<String> = varchar("name", length = Config.configData.characterLimit.account.id)
|
||||
val domain: Column<String> = varchar("domain", length = Config.configData.characterLimit.general.domain)
|
||||
val screenName: Column<String> = varchar("screen_name", length = Config.configData.characterLimit.account.name)
|
||||
val description: Column<String> = varchar(
|
||||
"description",
|
||||
length = Config.configData.characterLimit.account.description
|
||||
)
|
||||
val password: Column<String?> = varchar("password", length = 255).nullable()
|
||||
val inbox: Column<String> = varchar("inbox", length = Config.configData.characterLimit.general.url).uniqueIndex()
|
||||
val outbox: Column<String> = varchar("outbox", length = Config.configData.characterLimit.general.url).uniqueIndex()
|
||||
val url: Column<String> = varchar("url", length = Config.configData.characterLimit.general.url).uniqueIndex()
|
||||
val publicKey: Column<String> = varchar("public_key", length = Config.configData.characterLimit.general.publicKey)
|
||||
val privateKey: Column<String?> = varchar(
|
||||
"private_key",
|
||||
length = Config.configData.characterLimit.general.privateKey
|
||||
).nullable()
|
||||
val createdAt: Column<Long> = 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> = long("user_id").references(Users.id).index()
|
||||
val followerId: Column<Long> = 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> = long("user_id").references(Users.id)
|
||||
val followerId: Column<Long> = long("follower_id").references(Users.id)
|
||||
|
||||
init {
|
||||
uniqueIndex(userId, followerId)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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<ReceiveFollowJob>)
|
||||
when {
|
||||
hideoutJob is ReceiveFollowJob -> {
|
||||
when (hideoutJob) {
|
||||
is ReceiveFollowJob -> {
|
||||
apReceiveFollowService.receiveFollowJob(
|
||||
job.props as JobProps<ReceiveFollowJob>
|
||||
)
|
||||
}
|
||||
|
||||
hideoutJob is DeliverPostJob -> apNoteService.createNoteJob(job.props as JobProps<DeliverPostJob>)
|
||||
hideoutJob is DeliverReactionJob -> apReactionService.reactionJob(job.props as JobProps<DeliverReactionJob>)
|
||||
hideoutJob is DeliverRemoveReactionJob -> apReactionService.removeReactionJob(
|
||||
is DeliverPostJob -> apNoteService.createNoteJob(job.props as JobProps<DeliverPostJob>)
|
||||
is DeliverReactionJob -> apReactionService.reactionJob(job.props as JobProps<DeliverReactionJob>)
|
||||
is DeliverRemoveReactionJob -> apReactionService.removeReactionJob(
|
||||
job.props as JobProps<DeliverRemoveReactionJob>
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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<PostResponse>
|
||||
|
||||
suspend fun getByUser(
|
||||
nameOrId: String,
|
||||
since: Instant? = null,
|
||||
until: Instant? = null,
|
||||
minId: Long? = null,
|
||||
maxId: Long? = null,
|
||||
limit: Int? = null,
|
||||
userId: Long? = null
|
||||
): List<PostResponse>
|
||||
|
||||
suspend fun getReactionByPostId(postId: Long, userId: Long? = null): List<ReactionResponse>
|
||||
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<PostResponse> = 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<PostResponse> {
|
||||
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<ReactionResponse> =
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<UserResponse>
|
||||
|
||||
suspend fun findById(id: Long): UserResponse
|
||||
|
||||
suspend fun findByIds(ids: List<Long>): List<UserResponse>
|
||||
|
||||
suspend fun findByAcct(acct: Acct): UserResponse
|
||||
|
||||
suspend fun findFollowers(userId: Long): List<UserResponse>
|
||||
|
||||
suspend fun findFollowings(userId: Long): List<UserResponse>
|
||||
|
||||
suspend fun findFollowersByAcct(acct: Acct): List<UserResponse>
|
||||
|
||||
suspend fun findFollowingsByAcct(acct: Acct): List<UserResponse>
|
||||
|
||||
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<UserResponse> = 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<Long>): List<UserResponse> {
|
||||
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<UserResponse> = transaction.transaction {
|
||||
followerQueryService.findFollowersById(userId).map { UserResponse.from(it) }
|
||||
}
|
||||
|
||||
override suspend fun findFollowings(userId: Long): List<UserResponse> = transaction.transaction {
|
||||
followerQueryService.findFollowingById(userId).map { UserResponse.from(it) }
|
||||
}
|
||||
|
||||
override suspend fun findFollowersByAcct(acct: Acct): List<UserResponse> = transaction.transaction {
|
||||
followerQueryService.findFollowersByNameAndDomain(acct.username, acct.domain ?: applicationConfig.url.host)
|
||||
.map { UserResponse.from(it) }
|
||||
}
|
||||
|
||||
override suspend fun findFollowingsByAcct(acct: Acct): List<UserResponse> = 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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,8 +60,6 @@ class TimelineApiServiceImpl(
|
|||
): List<Status> = transaction.transaction {
|
||||
generateTimelineService.getTimeline(
|
||||
forUserId = userId,
|
||||
localOnly = false,
|
||||
mediaOnly = false,
|
||||
maxId = maxId,
|
||||
minId = minId,
|
||||
sinceId = sinceId,
|
||||
|
|
|
@ -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<String> = varchar("registered_client_id", 100)
|
||||
val principalName: Column<String> = varchar("principal_name", 200)
|
||||
val authorities: Column<String> = varchar("authorities", 1000)
|
||||
override val primaryKey: PrimaryKey = PrimaryKey(registeredClientId, principalName)
|
||||
}
|
||||
|
|
|
@ -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<String> = varchar("id", 255)
|
||||
val registeredClientId: Column<String> = varchar("registered_client_id", 255)
|
||||
val principalName: Column<String> = varchar("principal_name", 255)
|
||||
val authorizationGrantType: Column<String> = varchar("authorization_grant_type", 255)
|
||||
val authorizedScopes: Column<String?> = varchar("authorized_scopes", 1000).nullable().default(null)
|
||||
val attributes: Column<String?> = varchar("attributes", 4000).nullable().default(null)
|
||||
val state: Column<String?> = varchar("state", 500).nullable().default(null)
|
||||
val authorizationCodeValue: Column<String?> = varchar("authorization_code_value", 4000).nullable().default(null)
|
||||
val authorizationCodeIssuedAt: Column<Instant?> = timestamp("authorization_code_issued_at").nullable().default(null)
|
||||
val authorizationCodeExpiresAt: Column<Instant?> = timestamp("authorization_code_expires_at").nullable().default(
|
||||
null
|
||||
)
|
||||
val authorizationCodeMetadata: Column<String?> = varchar("authorization_code_metadata", 2000).nullable().default(
|
||||
null
|
||||
)
|
||||
val accessTokenValue: Column<String?> = varchar("access_token_value", 4000).nullable().default(null)
|
||||
val accessTokenIssuedAt: Column<Instant?> = timestamp("access_token_issued_at").nullable().default(null)
|
||||
val accessTokenExpiresAt: Column<Instant?> = timestamp("access_token_expires_at").nullable().default(null)
|
||||
val accessTokenMetadata: Column<String?> = varchar("access_token_metadata", 2000).nullable().default(null)
|
||||
val accessTokenType: Column<String?> = varchar("access_token_type", 255).nullable().default(null)
|
||||
val accessTokenScopes: Column<String?> = varchar("access_token_scopes", 1000).nullable().default(null)
|
||||
val refreshTokenValue: Column<String?> = varchar("refresh_token_value", 4000).nullable().default(null)
|
||||
val refreshTokenIssuedAt: Column<Instant?> = timestamp("refresh_token_issued_at").nullable().default(null)
|
||||
val refreshTokenExpiresAt: Column<Instant?> = timestamp("refresh_token_expires_at").nullable().default(null)
|
||||
val refreshTokenMetadata: Column<String?> = varchar("refresh_token_metadata", 2000).nullable().default(null)
|
||||
val oidcIdTokenValue: Column<String?> = varchar("oidc_id_token_value", 4000).nullable().default(null)
|
||||
val oidcIdTokenIssuedAt: Column<Instant?> = timestamp("oidc_id_token_issued_at").nullable().default(null)
|
||||
val oidcIdTokenExpiresAt: Column<Instant?> = timestamp("oidc_id_token_expires_at").nullable().default(null)
|
||||
val oidcIdTokenMetadata: Column<String?> = varchar("oidc_id_token_metadata", 2000).nullable().default(null)
|
||||
val oidcIdTokenClaims: Column<String?> = varchar("oidc_id_token_claims", 2000).nullable().default(null)
|
||||
val userCodeValue: Column<String?> = varchar("user_code_value", 4000).nullable().default(null)
|
||||
val userCodeIssuedAt: Column<Instant?> = timestamp("user_code_issued_at").nullable().default(null)
|
||||
val userCodeExpiresAt: Column<Instant?> = timestamp("user_code_expires_at").nullable().default(null)
|
||||
val userCodeMetadata: Column<String?> = varchar("user_code_metadata", 2000).nullable().default(null)
|
||||
val deviceCodeValue: Column<String?> = varchar("device_code_value", 4000).nullable().default(null)
|
||||
val deviceCodeIssuedAt: Column<Instant?> = timestamp("device_code_issued_at").nullable().default(null)
|
||||
val deviceCodeExpiresAt: Column<Instant?> = timestamp("device_code_expires_at").nullable().default(null)
|
||||
val deviceCodeMetadata: Column<String?> = varchar("device_code_metadata", 2000).nullable().default(null)
|
||||
|
||||
override val primaryKey = PrimaryKey(id)
|
||||
override val primaryKey: PrimaryKey = PrimaryKey(id)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class ExposedKJob(config: Configuration) : BaseKJob<ExposedKJob.Configuration>(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<ExposedKJob.Configuration>(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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue