mirror of https://github.com/usbharu/Hideout.git
style: スタイルを修正
This commit is contained in:
parent
1a63ae104c
commit
31e6b0f8d2
|
@ -3,22 +3,42 @@ package dev.usbharu.hideout.repository
|
||||||
import dev.usbharu.hideout.domain.model.hideout.entity.Post
|
import dev.usbharu.hideout.domain.model.hideout.entity.Post
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
|
@Suppress("LongParameterList")
|
||||||
interface IPostRepository {
|
interface IPostRepository {
|
||||||
suspend fun generateId(): Long
|
suspend fun generateId(): Long
|
||||||
suspend fun save(post: Post): Post
|
suspend fun save(post: Post): Post
|
||||||
suspend fun findOneById(id: Long, userId: Long? = null): Post?
|
suspend fun findOneById(id: Long, userId: Long? = null): Post?
|
||||||
suspend fun findByUrl(url: String): Post?
|
suspend fun findByUrl(url: String): Post?
|
||||||
suspend fun delete(id: Long)
|
suspend fun delete(id: Long)
|
||||||
suspend fun findAll(since: Instant?, until: Instant?, minId: Long?, maxId: Long?, limit: Int?, userId: Long?): List<Post>
|
suspend fun findAll(
|
||||||
suspend fun findByUserNameAndDomain(username: String,
|
since: Instant?,
|
||||||
s: String,
|
until: Instant?,
|
||||||
since: Instant?,
|
minId: Long?,
|
||||||
until: Instant?,
|
maxId: Long?,
|
||||||
minId: Long?,
|
limit: Int?,
|
||||||
maxId: Long?,
|
userId: Long?
|
||||||
limit: Int?,
|
): List<Post>
|
||||||
userId: Long?): List<Post>
|
|
||||||
|
suspend fun findByUserNameAndDomain(
|
||||||
|
username: String,
|
||||||
|
s: String,
|
||||||
|
since: Instant?,
|
||||||
|
until: Instant?,
|
||||||
|
minId: Long?,
|
||||||
|
maxId: Long?,
|
||||||
|
limit: Int?,
|
||||||
|
userId: Long?
|
||||||
|
): List<Post>
|
||||||
|
|
||||||
|
suspend fun findByUserId(
|
||||||
|
idOrNull: Long,
|
||||||
|
since: Instant?,
|
||||||
|
until: Instant?,
|
||||||
|
minId: Long?,
|
||||||
|
maxId: Long?,
|
||||||
|
limit: Int?,
|
||||||
|
userId: Long?
|
||||||
|
): List<Post>
|
||||||
|
|
||||||
suspend fun findByUserId(idOrNull: Long, since: Instant?, until: Instant?, minId: Long?, maxId: Long?, limit: Int?, userId: Long?): List<Post>
|
|
||||||
suspend fun findByApId(id: String): Post?
|
suspend fun findByApId(id: String): Post?
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ class PostRepositoryImpl(database: Database, private val idGenerateService: IdGe
|
||||||
|
|
||||||
@Suppress("InjectDispatcher")
|
@Suppress("InjectDispatcher")
|
||||||
suspend fun <T> query(block: suspend () -> T): T =
|
suspend fun <T> query(block: suspend () -> T): T =
|
||||||
newSuspendedTransaction(Dispatchers.IO) { block() }
|
newSuspendedTransaction(Dispatchers.IO) { block() }
|
||||||
|
|
||||||
override suspend fun save(post: Post): Post {
|
override suspend fun save(post: Post): Post {
|
||||||
return query {
|
return query {
|
||||||
|
@ -78,15 +78,39 @@ class PostRepositoryImpl(database: Database, private val idGenerateService: IdGe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findAll(since: Instant?, until: Instant?, minId: Long?, maxId: Long?, limit: Int?, userId: Long?): List<Post> {
|
override suspend fun findAll(
|
||||||
|
since: Instant?,
|
||||||
|
until: Instant?,
|
||||||
|
minId: Long?,
|
||||||
|
maxId: Long?,
|
||||||
|
limit: Int?,
|
||||||
|
userId: Long?
|
||||||
|
): List<Post> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByUserNameAndDomain(username: String, s: String, since: Instant?, until: Instant?, minId: Long?, maxId: Long?, limit: Int?, userId: Long?): List<Post> {
|
override suspend fun findByUserNameAndDomain(
|
||||||
|
username: String,
|
||||||
|
s: String,
|
||||||
|
since: Instant?,
|
||||||
|
until: Instant?,
|
||||||
|
minId: Long?,
|
||||||
|
maxId: Long?,
|
||||||
|
limit: Int?,
|
||||||
|
userId: Long?
|
||||||
|
): List<Post> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByUserId(idOrNull: Long, since: Instant?, until: Instant?, minId: Long?, maxId: Long?, limit: Int?, userId: Long?): List<Post> {
|
override suspend fun findByUserId(
|
||||||
|
idOrNull: Long,
|
||||||
|
since: Instant?,
|
||||||
|
until: Instant?,
|
||||||
|
minId: Long?,
|
||||||
|
maxId: Long?,
|
||||||
|
limit: Int?,
|
||||||
|
userId: Long?
|
||||||
|
): List<Post> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,9 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) {
|
||||||
get {
|
get {
|
||||||
val userParameter = (
|
val userParameter = (
|
||||||
call.parameters["name"]
|
call.parameters["name"]
|
||||||
?: throw ParameterNotExistException("Parameter(name='userName@domain') does not exist.")
|
?: throw ParameterNotExistException(
|
||||||
|
"Parameter(name='userName@domain') does not exist."
|
||||||
|
)
|
||||||
)
|
)
|
||||||
if (userParameter.toLongOrNull() != null) {
|
if (userParameter.toLongOrNull() != null) {
|
||||||
return@get call.respond(userApiService.findById(userParameter.toLong()))
|
return@get call.respond(userApiService.findById(userParameter.toLong()))
|
||||||
|
@ -91,7 +93,9 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) {
|
||||||
get {
|
get {
|
||||||
val userParameter = (
|
val userParameter = (
|
||||||
call.parameters["name"]
|
call.parameters["name"]
|
||||||
?: throw ParameterNotExistException("Parameter(name='userName@domain') does not exist.")
|
?: throw ParameterNotExistException(
|
||||||
|
"Parameter(name='userName@domain') does not exist."
|
||||||
|
)
|
||||||
)
|
)
|
||||||
if (userParameter.toLongOrNull() != null) {
|
if (userParameter.toLongOrNull() != null) {
|
||||||
return@get call.respond(userApiService.findFollowings(userParameter.toLong()))
|
return@get call.respond(userApiService.findFollowings(userParameter.toLong()))
|
||||||
|
|
|
@ -152,6 +152,6 @@ class ActivityPubNoteServiceImpl(
|
||||||
note(note, targetActor, note.id ?: throw IllegalArgumentException("note.id is null"))
|
note(note, targetActor, note.id ?: throw IllegalArgumentException("note.id is null"))
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val public: String = "https://www.w3.org/ns/activitystreams#Public"
|
const val public: String = "https://www.w3.org/ns/activitystreams#Public"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,18 +6,22 @@ import java.time.Instant
|
||||||
interface IPostApiService {
|
interface IPostApiService {
|
||||||
suspend fun createPost(postForm: dev.usbharu.hideout.domain.model.hideout.form.Post, userId: Long): Post
|
suspend fun createPost(postForm: dev.usbharu.hideout.domain.model.hideout.form.Post, userId: Long): Post
|
||||||
suspend fun getById(id: Long, userId: Long?): Post
|
suspend fun getById(id: Long, userId: Long?): Post
|
||||||
suspend fun getAll(since: Instant? = null,
|
suspend fun getAll(
|
||||||
until: Instant? = null,
|
since: Instant? = null,
|
||||||
minId: Long? = null,
|
until: Instant? = null,
|
||||||
maxId: Long? = null,
|
minId: Long? = null,
|
||||||
limit: Int? = null,
|
maxId: Long? = null,
|
||||||
userId: Long? = null): List<Post>
|
limit: Int? = null,
|
||||||
|
userId: Long? = null
|
||||||
|
): List<Post>
|
||||||
|
|
||||||
suspend fun getByUser(nameOrId: String,
|
suspend fun getByUser(
|
||||||
since: Instant? = null,
|
nameOrId: String,
|
||||||
until: Instant? = null,
|
since: Instant? = null,
|
||||||
minId: Long? = null,
|
until: Instant? = null,
|
||||||
maxId: Long? = null,
|
minId: Long? = null,
|
||||||
limit: Int? = null,
|
maxId: Long? = null,
|
||||||
userId: Long? = null): List<Post>
|
limit: Int? = null,
|
||||||
|
userId: Long? = null
|
||||||
|
): List<Post>
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,18 +9,24 @@ import dev.usbharu.hideout.service.post.IPostService
|
||||||
import dev.usbharu.hideout.util.AcctUtil
|
import dev.usbharu.hideout.util.AcctUtil
|
||||||
import org.koin.core.annotation.Single
|
import org.koin.core.annotation.Single
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
import dev.usbharu.hideout.domain.model.hideout.form.Post as FormPost
|
||||||
|
|
||||||
@Single
|
@Single
|
||||||
class PostApiServiceImpl(private val postService: IPostService, private val postRepository: IPostRepository) : IPostApiService {
|
class PostApiServiceImpl(
|
||||||
override suspend fun createPost(postForm: dev.usbharu.hideout.domain.model.hideout.form.Post, userId: Long): Post {
|
private val postService: IPostService,
|
||||||
return postService.createLocal(PostCreateDto(
|
private val postRepository: IPostRepository
|
||||||
text = postForm.text,
|
) : IPostApiService {
|
||||||
overview = postForm.overview,
|
override suspend fun createPost(postForm: FormPost, userId: Long): Post {
|
||||||
visibility = postForm.visibility,
|
return postService.createLocal(
|
||||||
repostId = postForm.repostId,
|
PostCreateDto(
|
||||||
repolyId = postForm.replyId,
|
text = postForm.text,
|
||||||
userId = userId
|
overview = postForm.overview,
|
||||||
))
|
visibility = postForm.visibility,
|
||||||
|
repostId = postForm.repostId,
|
||||||
|
repolyId = postForm.replyId,
|
||||||
|
userId = userId
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getById(id: Long, userId: Long?): Post {
|
override suspend fun getById(id: Long, userId: Long?): Post {
|
||||||
|
@ -28,16 +34,38 @@ class PostApiServiceImpl(private val postService: IPostService, private val post
|
||||||
?: throw PostNotFoundException("$id was not found or is not authorized.")
|
?: throw PostNotFoundException("$id was not found or is not authorized.")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getAll(since: Instant?, until: Instant?, minId: Long?, maxId: Long?, limit: Int?, userId: Long?): List<Post> {
|
override suspend fun getAll(
|
||||||
return postRepository.findAll(since, until, minId, maxId, limit, userId)
|
since: Instant?,
|
||||||
}
|
until: Instant?,
|
||||||
|
minId: Long?,
|
||||||
|
maxId: Long?,
|
||||||
|
limit: Int?,
|
||||||
|
userId: Long?
|
||||||
|
): List<Post> = postRepository.findAll(since, until, minId, maxId, limit, userId)
|
||||||
|
|
||||||
override suspend fun getByUser(nameOrId: String, since: Instant?, until: Instant?, minId: Long?, maxId: Long?, limit: Int?, userId: Long?): List<Post> {
|
override suspend fun getByUser(
|
||||||
|
nameOrId: String,
|
||||||
|
since: Instant?,
|
||||||
|
until: Instant?,
|
||||||
|
minId: Long?,
|
||||||
|
maxId: Long?,
|
||||||
|
limit: Int?,
|
||||||
|
userId: Long?
|
||||||
|
): List<Post> {
|
||||||
val idOrNull = nameOrId.toLongOrNull()
|
val idOrNull = nameOrId.toLongOrNull()
|
||||||
return if (idOrNull == null) {
|
return if (idOrNull == null) {
|
||||||
val acct = AcctUtil.parse(nameOrId)
|
val acct = AcctUtil.parse(nameOrId)
|
||||||
postRepository.findByUserNameAndDomain(acct.username, acct.domain
|
postRepository.findByUserNameAndDomain(
|
||||||
?: Config.configData.domain, since, until, minId, maxId, limit, userId)
|
acct.username,
|
||||||
|
acct.domain
|
||||||
|
?: Config.configData.domain,
|
||||||
|
since,
|
||||||
|
until,
|
||||||
|
minId,
|
||||||
|
maxId,
|
||||||
|
limit,
|
||||||
|
userId
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
postRepository.findByUserId(idOrNull, since, until, minId, maxId, limit, userId)
|
postRepository.findByUserId(idOrNull, since, until, minId, maxId, limit, userId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,11 @@ import org.koin.core.annotation.Single
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
@Single
|
@Single
|
||||||
class PostServiceImpl(private val postRepository: IPostRepository, private val userRepository: IUserRepository, private val activityPubNoteService: ActivityPubNoteService) : IPostService {
|
class PostServiceImpl(
|
||||||
|
private val postRepository: IPostRepository,
|
||||||
|
private val userRepository: IUserRepository,
|
||||||
|
private val activityPubNoteService: ActivityPubNoteService
|
||||||
|
) : IPostService {
|
||||||
override suspend fun createLocal(post: PostCreateDto): Post {
|
override suspend fun createLocal(post: PostCreateDto): Post {
|
||||||
val user = userRepository.findById(post.userId) ?: throw UserNotFoundException("${post.userId} was not found")
|
val user = userRepository.findById(post.userId) ?: throw UserNotFoundException("${post.userId} was not found")
|
||||||
val id = postRepository.generateId()
|
val id = postRepository.generateId()
|
||||||
|
@ -29,7 +33,5 @@ class PostServiceImpl(private val postRepository: IPostRepository, private val u
|
||||||
return internalCreate(createPost)
|
return internalCreate(createPost)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun internalCreate(post: Post): Post {
|
private suspend fun internalCreate(post: Post): Post = postRepository.save(post)
|
||||||
return postRepository.save(post)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue