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 java.time.Instant
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
interface IPostRepository {
|
||||
suspend fun generateId(): Long
|
||||
suspend fun save(post: Post): Post
|
||||
suspend fun findOneById(id: Long, userId: Long? = null): Post?
|
||||
suspend fun findByUrl(url: String): Post?
|
||||
suspend fun delete(id: Long)
|
||||
suspend fun findAll(since: Instant?, until: Instant?, minId: Long?, maxId: Long?, limit: Int?, userId: Long?): List<Post>
|
||||
suspend fun findByUserNameAndDomain(username: String,
|
||||
suspend fun findAll(
|
||||
since: Instant?,
|
||||
until: Instant?,
|
||||
minId: Long?,
|
||||
maxId: Long?,
|
||||
limit: Int?,
|
||||
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>
|
||||
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?
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,9 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) {
|
|||
get {
|
||||
val userParameter = (
|
||||
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) {
|
||||
return@get call.respond(userApiService.findById(userParameter.toLong()))
|
||||
|
@ -91,7 +93,9 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) {
|
|||
get {
|
||||
val userParameter = (
|
||||
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) {
|
||||
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"))
|
||||
|
||||
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 {
|
||||
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 getAll(since: Instant? = null,
|
||||
until: Instant? = null,
|
||||
minId: Long? = null,
|
||||
maxId: Long? = null,
|
||||
limit: Int? = null,
|
||||
userId: Long? = null): List<Post>
|
||||
|
||||
suspend fun getByUser(nameOrId: String,
|
||||
suspend fun getAll(
|
||||
since: Instant? = null,
|
||||
until: Instant? = null,
|
||||
minId: Long? = null,
|
||||
maxId: Long? = null,
|
||||
limit: Int? = null,
|
||||
userId: Long? = null): List<Post>
|
||||
userId: Long? = null
|
||||
): List<Post>
|
||||
|
||||
suspend fun getByUser(
|
||||
nameOrId: String,
|
||||
since: Instant? = null,
|
||||
until: Instant? = null,
|
||||
minId: Long? = null,
|
||||
maxId: Long? = null,
|
||||
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 org.koin.core.annotation.Single
|
||||
import java.time.Instant
|
||||
import dev.usbharu.hideout.domain.model.hideout.form.Post as FormPost
|
||||
|
||||
@Single
|
||||
class PostApiServiceImpl(private val postService: IPostService, private val postRepository: IPostRepository) : IPostApiService {
|
||||
override suspend fun createPost(postForm: dev.usbharu.hideout.domain.model.hideout.form.Post, userId: Long): Post {
|
||||
return postService.createLocal(PostCreateDto(
|
||||
class PostApiServiceImpl(
|
||||
private val postService: IPostService,
|
||||
private val postRepository: IPostRepository
|
||||
) : IPostApiService {
|
||||
override suspend fun createPost(postForm: FormPost, userId: Long): Post {
|
||||
return postService.createLocal(
|
||||
PostCreateDto(
|
||||
text = postForm.text,
|
||||
overview = postForm.overview,
|
||||
visibility = postForm.visibility,
|
||||
repostId = postForm.repostId,
|
||||
repolyId = postForm.replyId,
|
||||
userId = userId
|
||||
))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
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.")
|
||||
}
|
||||
|
||||
override suspend fun getAll(since: Instant?, until: Instant?, minId: Long?, maxId: Long?, limit: Int?, userId: Long?): List<Post> {
|
||||
return postRepository.findAll(since, until, minId, maxId, limit, userId)
|
||||
}
|
||||
override suspend fun getAll(
|
||||
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()
|
||||
return if (idOrNull == null) {
|
||||
val acct = AcctUtil.parse(nameOrId)
|
||||
postRepository.findByUserNameAndDomain(acct.username, acct.domain
|
||||
?: Config.configData.domain, since, until, minId, maxId, limit, userId)
|
||||
postRepository.findByUserNameAndDomain(
|
||||
acct.username,
|
||||
acct.domain
|
||||
?: Config.configData.domain,
|
||||
since,
|
||||
until,
|
||||
minId,
|
||||
maxId,
|
||||
limit,
|
||||
userId
|
||||
)
|
||||
} else {
|
||||
postRepository.findByUserId(idOrNull, since, until, minId, maxId, limit, userId)
|
||||
}
|
||||
|
|
|
@ -10,7 +10,11 @@ import org.koin.core.annotation.Single
|
|||
import java.time.Instant
|
||||
|
||||
@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 {
|
||||
val user = userRepository.findById(post.userId) ?: throw UserNotFoundException("${post.userId} was not found")
|
||||
val id = postRepository.generateId()
|
||||
|
@ -29,7 +33,5 @@ class PostServiceImpl(private val postRepository: IPostRepository, private val u
|
|||
return internalCreate(createPost)
|
||||
}
|
||||
|
||||
private suspend fun internalCreate(post: Post): Post {
|
||||
return postRepository.save(post)
|
||||
}
|
||||
private suspend fun internalCreate(post: Post): Post = postRepository.save(post)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue