mirror of https://github.com/usbharu/Hideout.git
sql
This commit is contained in:
parent
8b3a6fc15a
commit
98a795c374
|
@ -19,9 +19,9 @@ package dev.usbharu.hideout.core.application.post
|
|||
import dev.usbharu.hideout.core.domain.model.post.Visibility
|
||||
|
||||
data class RegisterLocalPost(
|
||||
val actorId: Long,
|
||||
val userDetailId: Long,
|
||||
val content: String,
|
||||
val overview: String,
|
||||
val overview: String?,
|
||||
val visibility: Visibility,
|
||||
val repostId: Long?,
|
||||
val replyId: Long?,
|
||||
|
|
|
@ -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.PostOverview
|
||||
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 org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
@ -35,6 +36,7 @@ class RegisterLocalPostApplicationService(
|
|||
private val postFactory: PostFactoryImpl,
|
||||
private val actorRepository: ActorRepository,
|
||||
private val postRepository: PostRepository,
|
||||
private val userDetailRepository: UserDetailRepository,
|
||||
transaction: Transaction,
|
||||
) : AbstractApplicationService<RegisterLocalPost, Unit>(transaction, Companion.logger) {
|
||||
|
||||
|
@ -43,10 +45,12 @@ class RegisterLocalPostApplicationService(
|
|||
}
|
||||
|
||||
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,
|
||||
actorRepository.findById(actorId)!!.name,
|
||||
PostOverview(command.overview),
|
||||
command.overview?.let { PostOverview(it) },
|
||||
command.content,
|
||||
command.visibility,
|
||||
command.repostId?.let { PostId(it) },
|
||||
|
|
|
@ -38,7 +38,7 @@ class PostFactoryImpl(
|
|||
suspend fun createLocal(
|
||||
actorId: ActorId,
|
||||
actorName: ActorName,
|
||||
overview: PostOverview,
|
||||
overview: PostOverview?,
|
||||
content: String,
|
||||
visibility: Visibility,
|
||||
repostId: PostId?,
|
||||
|
|
|
@ -16,14 +16,22 @@
|
|||
|
||||
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.model.Status
|
||||
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.stereotype.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> {
|
||||
return super.apiV1StatusesIdEmojiReactionsEmojiDelete(id, emoji)
|
||||
}
|
||||
|
@ -37,6 +45,26 @@ class SpringStatusApi : StatusApi {
|
|||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue