style: スタイルを修正

This commit is contained in:
usbharu 2023-06-04 00:59:47 +09:00
parent 1a63ae104c
commit 31e6b0f8d2
7 changed files with 132 additions and 50 deletions

View File

@ -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?,
until: Instant?,
minId: Long?,
maxId: Long?,
limit: Int?,
userId: Long?
): List<Post>
suspend fun findByUserNameAndDomain(
username: String,
s: String, s: String,
since: Instant?, since: Instant?,
until: Instant?, until: Instant?,
minId: Long?, minId: Long?,
maxId: Long?, maxId: Long?,
limit: Int?, 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? suspend fun findByApId(id: String): Post?
} }

View File

@ -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")
} }

View File

@ -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()))

View File

@ -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"
} }
} }

View File

@ -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,
minId: Long? = null,
maxId: Long? = null,
limit: Int? = null,
userId: Long? = null): List<Post>
suspend fun getByUser(nameOrId: String,
since: Instant? = null, since: Instant? = null,
until: Instant? = null, until: Instant? = null,
minId: Long? = null, minId: Long? = null,
maxId: Long? = null, maxId: Long? = null,
limit: Int? = 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>
} }

View File

@ -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
) : IPostApiService {
override suspend fun createPost(postForm: FormPost, userId: Long): Post {
return postService.createLocal(
PostCreateDto(
text = postForm.text, text = postForm.text,
overview = postForm.overview, overview = postForm.overview,
visibility = postForm.visibility, visibility = postForm.visibility,
repostId = postForm.repostId, repostId = postForm.repostId,
repolyId = postForm.replyId, repolyId = postForm.replyId,
userId = userId 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)
} }

View File

@ -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)
}
} }