mirror of https://github.com/usbharu/Hideout.git
feat: Postのドメイン知識を追加
This commit is contained in:
parent
dff3397bab
commit
b07a0ffabb
|
@ -1,6 +1,8 @@
|
|||
package dev.usbharu.hideout.domain.model.hideout.entity
|
||||
|
||||
data class Post(
|
||||
import dev.usbharu.hideout.config.Config
|
||||
|
||||
data class Post private constructor(
|
||||
val id: Long,
|
||||
val userId: Long,
|
||||
val overview: String? = null,
|
||||
|
@ -12,4 +14,60 @@ data class Post(
|
|||
val replyId: Long? = null,
|
||||
val sensitive: Boolean = false,
|
||||
val apId: String = url
|
||||
)
|
||||
) {
|
||||
companion object {
|
||||
fun of(
|
||||
id: Long,
|
||||
userId: Long,
|
||||
overview: String? = null,
|
||||
text: String,
|
||||
createdAt: Long,
|
||||
visibility: Visibility,
|
||||
url: String,
|
||||
repostId: Long? = null,
|
||||
replyId: Long? = null,
|
||||
sensitive: Boolean = false,
|
||||
apId: String = url
|
||||
): Post {
|
||||
val characterLimit = Config.configData.characterLimit
|
||||
|
||||
require(id >= 0) { "id must be greater than or equal to 0." }
|
||||
|
||||
require(userId >= 0) { "userId must be greater than or equal to 0." }
|
||||
|
||||
val limitedOverview = if ((overview?.length ?: 0) >= characterLimit.post.overview) {
|
||||
overview?.substring(0, characterLimit.post.overview)
|
||||
} else {
|
||||
overview
|
||||
}
|
||||
|
||||
val limitedText = if (text.length >= characterLimit.post.text) {
|
||||
text.substring(0, characterLimit.post.text)
|
||||
} else {
|
||||
text
|
||||
}
|
||||
|
||||
require(url.isNotBlank()) { "url must contain non-blank characters" }
|
||||
require(url.length <= characterLimit.general.url) {
|
||||
"url must not exceed ${characterLimit.general.url} characters."
|
||||
}
|
||||
|
||||
require((repostId ?: 0) >= 0) { "repostId must be greater then or equal to 0." }
|
||||
require((replyId ?: 0) >= 0) { "replyId must be greater then or equal to 0." }
|
||||
|
||||
return Post(
|
||||
id = id,
|
||||
userId = userId,
|
||||
overview = limitedOverview,
|
||||
text = limitedText,
|
||||
createdAt = createdAt,
|
||||
visibility = visibility,
|
||||
url = url,
|
||||
repostId = repostId,
|
||||
replyId = replyId,
|
||||
sensitive = sensitive,
|
||||
apId = apId
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ object Posts : Table() {
|
|||
}
|
||||
|
||||
fun ResultRow.toPost(): Post {
|
||||
return Post(
|
||||
return Post.of(
|
||||
id = this[Posts.id],
|
||||
userId = this[Posts.userId],
|
||||
overview = this[Posts.overview],
|
||||
|
|
|
@ -5,7 +5,6 @@ import dev.usbharu.hideout.domain.model.ActivityPubStringResponse
|
|||
import dev.usbharu.hideout.domain.model.ap.Like
|
||||
import dev.usbharu.hideout.exception.ap.IllegalActivityPubObjectException
|
||||
import dev.usbharu.hideout.query.PostQueryService
|
||||
import dev.usbharu.hideout.query.UserQueryService
|
||||
import dev.usbharu.hideout.service.core.Transaction
|
||||
import dev.usbharu.hideout.service.reaction.ReactionService
|
||||
import io.ktor.http.*
|
||||
|
@ -20,7 +19,6 @@ class APLikeServiceImpl(
|
|||
private val reactionService: ReactionService,
|
||||
private val apUserService: APUserService,
|
||||
private val apNoteService: APNoteService,
|
||||
private val userQueryService: UserQueryService,
|
||||
private val postQueryService: PostQueryService,
|
||||
private val transaction: Transaction
|
||||
) : APLikeService {
|
||||
|
@ -32,7 +30,6 @@ class APLikeServiceImpl(
|
|||
val person = apUserService.fetchPersonWithEntity(actor)
|
||||
apNoteService.fetchNote(like.`object`!!)
|
||||
|
||||
|
||||
val post = postQueryService.findByUrl(like.`object`!!)
|
||||
|
||||
reactionService.receiveReaction(
|
||||
|
|
|
@ -155,7 +155,7 @@ class APNoteServiceImpl(
|
|||
}
|
||||
|
||||
postRepository.save(
|
||||
Post(
|
||||
Post.of(
|
||||
id = postRepository.generateId(),
|
||||
userId = person.second.id,
|
||||
overview = null,
|
||||
|
|
|
@ -11,7 +11,6 @@ import dev.usbharu.hideout.plugins.postAp
|
|||
import dev.usbharu.hideout.query.FollowerQueryService
|
||||
import dev.usbharu.hideout.query.PostQueryService
|
||||
import dev.usbharu.hideout.query.UserQueryService
|
||||
import dev.usbharu.hideout.repository.PostRepository
|
||||
import dev.usbharu.hideout.service.job.JobQueueParentService
|
||||
import io.ktor.client.*
|
||||
import kjob.core.job.JobProps
|
||||
|
@ -28,7 +27,6 @@ interface APReactionService {
|
|||
@Single
|
||||
class APReactionServiceImpl(
|
||||
private val jobQueueParentService: JobQueueParentService,
|
||||
private val postRepository: PostRepository,
|
||||
private val httpClient: HttpClient,
|
||||
private val userQueryService: UserQueryService,
|
||||
private val followerQueryService: FollowerQueryService,
|
||||
|
|
|
@ -18,7 +18,7 @@ class PostServiceImpl(
|
|||
override suspend fun createLocal(post: PostCreateDto): Post {
|
||||
val user = userRepository.findById(post.userId) ?: throw UserNotFoundException("${post.userId} was not found")
|
||||
val id = postRepository.generateId()
|
||||
val createPost = Post(
|
||||
val createPost = Post.of(
|
||||
id = id,
|
||||
userId = post.userId,
|
||||
overview = post.overview,
|
||||
|
|
|
@ -86,7 +86,7 @@ class APNoteServiceImplTest {
|
|||
followerQueryService,
|
||||
mock()
|
||||
)
|
||||
val postEntity = Post(
|
||||
val postEntity = Post.of(
|
||||
1L,
|
||||
1L,
|
||||
null,
|
||||
|
|
Loading…
Reference in New Issue