This commit is contained in:
usbharu 2024-06-07 18:24:25 +09:00
parent 8b3a6fc15a
commit 98a795c374
5 changed files with 49 additions and 17 deletions

View File

@ -19,9 +19,9 @@ package dev.usbharu.hideout.core.application.post
import dev.usbharu.hideout.core.domain.model.post.Visibility import dev.usbharu.hideout.core.domain.model.post.Visibility
data class RegisterLocalPost( data class RegisterLocalPost(
val actorId: Long, val userDetailId: Long,
val content: String, val content: String,
val overview: String, val overview: String?,
val visibility: Visibility, val visibility: Visibility,
val repostId: Long?, val repostId: Long?,
val replyId: Long?, val replyId: Long?,

View File

@ -25,6 +25,7 @@ import dev.usbharu.hideout.core.domain.model.media.MediaId
import dev.usbharu.hideout.core.domain.model.post.PostId import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.post.PostOverview import dev.usbharu.hideout.core.domain.model.post.PostOverview
import dev.usbharu.hideout.core.domain.model.post.PostRepository import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailRepository
import dev.usbharu.hideout.core.infrastructure.factory.PostFactoryImpl import dev.usbharu.hideout.core.infrastructure.factory.PostFactoryImpl
import org.slf4j.Logger import org.slf4j.Logger
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
@ -35,6 +36,7 @@ class RegisterLocalPostApplicationService(
private val postFactory: PostFactoryImpl, private val postFactory: PostFactoryImpl,
private val actorRepository: ActorRepository, private val actorRepository: ActorRepository,
private val postRepository: PostRepository, private val postRepository: PostRepository,
private val userDetailRepository: UserDetailRepository,
transaction: Transaction, transaction: Transaction,
) : AbstractApplicationService<RegisterLocalPost, Unit>(transaction, Companion.logger) { ) : AbstractApplicationService<RegisterLocalPost, Unit>(transaction, Companion.logger) {
@ -43,10 +45,12 @@ class RegisterLocalPostApplicationService(
} }
override suspend fun internalExecute(command: RegisterLocalPost, executor: CommandExecutor) { override suspend fun internalExecute(command: RegisterLocalPost, executor: CommandExecutor) {
val actorId = ActorId(command.actorId) val actorId = (userDetailRepository.findById(command.userDetailId)
?: throw IllegalStateException("actor not found")).actorId
val post = postFactory.createLocal(actorId, val post = postFactory.createLocal(actorId,
actorRepository.findById(actorId)!!.name, actorRepository.findById(actorId)!!.name,
PostOverview(command.overview), command.overview?.let { PostOverview(it) },
command.content, command.content,
command.visibility, command.visibility,
command.repostId?.let { PostId(it) }, command.repostId?.let { PostId(it) },

View File

@ -38,7 +38,7 @@ class PostFactoryImpl(
suspend fun createLocal( suspend fun createLocal(
actorId: ActorId, actorId: ActorId,
actorName: ActorName, actorName: ActorName,
overview: PostOverview, overview: PostOverview?,
content: String, content: String,
visibility: Visibility, visibility: Visibility,
repostId: PostId?, repostId: PostId?,

View File

@ -16,14 +16,22 @@
package dev.usbharu.hideout.mastodon.interfaces.api package dev.usbharu.hideout.mastodon.interfaces.api
import dev.usbharu.hideout.core.application.post.RegisterLocalPost
import dev.usbharu.hideout.core.application.post.RegisterLocalPostApplicationService
import dev.usbharu.hideout.core.domain.model.post.Visibility
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.Oauth2CommandExecutorFactory
import dev.usbharu.hideout.mastodon.interfaces.api.generated.StatusApi import dev.usbharu.hideout.mastodon.interfaces.api.generated.StatusApi
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.Status import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.Status
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.StatusesRequest import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.StatusesRequest
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.StatusesRequest.Visibility.*
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Controller import org.springframework.stereotype.Controller
@Controller @Controller
class SpringStatusApi : StatusApi { class SpringStatusApi(
private val oauth2CommandExecutorFactory: Oauth2CommandExecutorFactory,
private val registerLocalPostApplicationService: RegisterLocalPostApplicationService,
) : StatusApi {
override suspend fun apiV1StatusesIdEmojiReactionsEmojiDelete(id: String, emoji: String): ResponseEntity<Status> { override suspend fun apiV1StatusesIdEmojiReactionsEmojiDelete(id: String, emoji: String): ResponseEntity<Status> {
return super.apiV1StatusesIdEmojiReactionsEmojiDelete(id, emoji) return super.apiV1StatusesIdEmojiReactionsEmojiDelete(id, emoji)
} }
@ -37,6 +45,26 @@ class SpringStatusApi : StatusApi {
} }
override suspend fun apiV1StatusesPost(statusesRequest: StatusesRequest): ResponseEntity<Status> { override suspend fun apiV1StatusesPost(statusesRequest: StatusesRequest): ResponseEntity<Status> {
return super.apiV1StatusesPost(statusesRequest) val executor = oauth2CommandExecutorFactory.getCommandExecutor()
registerLocalPostApplicationService.execute(
RegisterLocalPost(
userDetailId = executor.userDetailId,
content = statusesRequest.status.orEmpty(),
overview = statusesRequest.spoilerText,
visibility = when (statusesRequest.visibility) {
public -> Visibility.PUBLIC
unlisted -> Visibility.UNLISTED
private -> Visibility.FOLLOWERS
direct -> Visibility.DIRECT
null -> Visibility.PUBLIC
},
repostId = null,
replyId = statusesRequest.inReplyToId?.toLong(),
sensitive = statusesRequest.sensitive == true,
mediaIds = statusesRequest.mediaIds.orEmpty().map { it.toLong() }
),
executor
)
return ResponseEntity.ok().build()
} }
} }