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
|
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?,
|
||||||
|
|
|
@ -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) },
|
||||||
|
|
|
@ -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?,
|
||||||
|
|
|
@ -41,21 +41,21 @@ create table if not exists actors
|
||||||
url varchar(1000) not null unique,
|
url varchar(1000) not null unique,
|
||||||
public_key varchar(10000) not null,
|
public_key varchar(10000) not null,
|
||||||
private_key varchar(10000) null,
|
private_key varchar(10000) null,
|
||||||
created_at timestamp not null,
|
created_at timestamp not null,
|
||||||
key_id varchar(1000) not null,
|
key_id varchar(1000) not null,
|
||||||
"following" varchar(1000) null,
|
"following" varchar(1000) null,
|
||||||
followers varchar(1000) null,
|
followers varchar(1000) null,
|
||||||
"instance" bigint not null,
|
"instance" bigint not null,
|
||||||
locked boolean not null,
|
locked boolean not null,
|
||||||
following_count int null,
|
following_count int null,
|
||||||
followers_count int null,
|
followers_count int null,
|
||||||
posts_count int not null,
|
posts_count int not null,
|
||||||
last_post_at timestamp null default null,
|
last_post_at timestamp null default null,
|
||||||
last_update_at timestamp not null,
|
last_update_at timestamp not null,
|
||||||
suspend boolean not null,
|
suspend boolean not null,
|
||||||
move_to bigint null default null,
|
move_to bigint null default null,
|
||||||
emojis varchar(3000) not null default '',
|
emojis varchar(3000) not null default '',
|
||||||
deleted boolean not null default false,
|
deleted boolean not null default false,
|
||||||
unique ("name", "domain"),
|
unique ("name", "domain"),
|
||||||
constraint fk_actors_instance__id foreign key ("instance") references instance (id) on delete restrict on update restrict,
|
constraint fk_actors_instance__id foreign key ("instance") references instance (id) on delete restrict on update restrict,
|
||||||
constraint fk_actors_actors__move_to foreign key ("move_to") references actors (id) on delete restrict on update restrict
|
constraint fk_actors_actors__move_to foreign key ("move_to") references actors (id) on delete restrict on update restrict
|
||||||
|
@ -75,7 +75,7 @@ create table if not exists user_details
|
||||||
actor_id bigint not null unique,
|
actor_id bigint not null unique,
|
||||||
password varchar(255) not null,
|
password varchar(255) not null,
|
||||||
auto_accept_followee_follow_request boolean not null,
|
auto_accept_followee_follow_request boolean not null,
|
||||||
last_migration timestamp null default null,
|
last_migration timestamp null default null,
|
||||||
constraint fk_user_details_actor_id__id foreign key (actor_id) references actors (id) on delete restrict on update restrict
|
constraint fk_user_details_actor_id__id foreign key (actor_id) references actors (id) on delete restrict on update restrict
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue