mirror of https://github.com/usbharu/Hideout.git
feat: メディア付き投稿が可能に
This commit is contained in:
parent
426105f6a5
commit
db517cf288
|
@ -60,9 +60,17 @@ tasks.create<GenerateTask>("openApiGenerateMastodonCompatibleApi", GenerateTask:
|
|||
configOptions.put("interfaceOnly", "true")
|
||||
configOptions.put("useSpringBoot3", "true")
|
||||
additionalProperties.put("useTags", "true")
|
||||
|
||||
importMappings.put("org.springframework.core.io.Resource", "org.springframework.web.multipart.MultipartFile")
|
||||
typeMappings.put("org.springframework.core.io.Resource", "org.springframework.web.multipart.MultipartFile")
|
||||
schemaMappings.put(
|
||||
"StatusesRequest",
|
||||
"dev.usbharu.hideout.domain.model.mastodon.StatusesRequest"
|
||||
)
|
||||
templateDir.set("$rootDir/templates")
|
||||
globalProperties.put("debugModels", "true")
|
||||
globalProperties.put("debugOpenAPI", "true")
|
||||
globalProperties.put("debugOperations", "true")
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
|
|
@ -2,7 +2,6 @@ package dev.usbharu.hideout.controller.mastodon
|
|||
|
||||
import dev.usbharu.hideout.controller.mastodon.generated.StatusApi
|
||||
import dev.usbharu.hideout.domain.mastodon.model.generated.Status
|
||||
import dev.usbharu.hideout.domain.mastodon.model.generated.StatusesRequest
|
||||
import dev.usbharu.hideout.service.api.mastodon.StatusesApiService
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.springframework.http.HttpStatus
|
||||
|
@ -13,7 +12,7 @@ import org.springframework.stereotype.Controller
|
|||
|
||||
@Controller
|
||||
class MastodonStatusesApiContoller(private val statusesApiService: StatusesApiService) : StatusApi {
|
||||
override fun apiV1StatusesPost(statusesRequest: StatusesRequest): ResponseEntity<Status> =
|
||||
override fun apiV1StatusesPost(statusesRequest: dev.usbharu.hideout.domain.model.mastodon.StatusesRequest): ResponseEntity<Status> =
|
||||
runBlocking {
|
||||
val jwt = SecurityContextHolder.getContext().authentication.principal as Jwt
|
||||
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package dev.usbharu.hideout.domain.model.mastodon
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import dev.usbharu.hideout.domain.mastodon.model.generated.StatusesRequest
|
||||
import dev.usbharu.hideout.domain.mastodon.model.generated.StatusesRequestPoll
|
||||
|
||||
class StatusesRequest {
|
||||
@JsonProperty("status")
|
||||
var status: String? = null
|
||||
@JsonProperty("media_ids")
|
||||
var media_ids: List<String> = emptyList()
|
||||
@JsonProperty("poll")
|
||||
var poll: StatusesRequestPoll? = null
|
||||
@JsonProperty("in_reply_to_id")
|
||||
var in_reply_to_id: String? = null
|
||||
@JsonProperty("sensitive")
|
||||
var sensitive: Boolean? = null
|
||||
@JsonProperty("spoiler_text")
|
||||
var spoiler_text: String? = null
|
||||
@JsonProperty("visibility")
|
||||
var visibility: StatusesRequest.Visibility? = null
|
||||
@JsonProperty("language")
|
||||
var language: String? = null
|
||||
@JsonProperty("scheduled_at")
|
||||
var scheduled_at: String? = null
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other !is dev.usbharu.hideout.domain.model.mastodon.StatusesRequest) return false
|
||||
|
||||
if (status != other.status) return false
|
||||
if (media_ids != other.media_ids) return false
|
||||
if (poll != other.poll) return false
|
||||
if (in_reply_to_id != other.in_reply_to_id) return false
|
||||
if (sensitive != other.sensitive) return false
|
||||
if (spoiler_text != other.spoiler_text) return false
|
||||
if (visibility != other.visibility) return false
|
||||
if (language != other.language) return false
|
||||
if (scheduled_at != other.scheduled_at) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = status?.hashCode() ?: 0
|
||||
result = 31 * result + media_ids.hashCode()
|
||||
result = 31 * result + (poll?.hashCode() ?: 0)
|
||||
result = 31 * result + (in_reply_to_id?.hashCode() ?: 0)
|
||||
result = 31 * result + (sensitive?.hashCode() ?: 0)
|
||||
result = 31 * result + (spoiler_text?.hashCode() ?: 0)
|
||||
result = 31 * result + (visibility?.hashCode() ?: 0)
|
||||
result = 31 * result + (language?.hashCode() ?: 0)
|
||||
result = 31 * result + (scheduled_at?.hashCode() ?: 0)
|
||||
return result
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "StatusesRequest(status=$status, mediaIds=$media_ids, poll=$poll, inReplyToId=$in_reply_to_id, sensitive=$sensitive, spoilerText=$spoiler_text, visibility=$visibility, language=$language, scheduledAt=$scheduled_at)"
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -18,7 +18,10 @@ import java.time.Instant
|
|||
|
||||
@Service
|
||||
interface StatusesApiService {
|
||||
suspend fun postStatus(statusesRequest: StatusesRequest, userId: Long): Status
|
||||
suspend fun postStatus(
|
||||
statusesRequest: dev.usbharu.hideout.domain.model.mastodon.StatusesRequest,
|
||||
userId: Long
|
||||
): Status
|
||||
}
|
||||
|
||||
@Service
|
||||
|
@ -32,8 +35,11 @@ class StatsesApiServiceImpl(
|
|||
) :
|
||||
StatusesApiService {
|
||||
@Suppress("LongMethod")
|
||||
override suspend fun postStatus(statusesRequest: StatusesRequest, userId: Long): Status = transaction.transaction {
|
||||
println("Post status media ids " + statusesRequest.mediaIds)
|
||||
override suspend fun postStatus(
|
||||
statusesRequest: dev.usbharu.hideout.domain.model.mastodon.StatusesRequest,
|
||||
userId: Long
|
||||
): Status = transaction.transaction {
|
||||
println("Post status media ids " + statusesRequest.media_ids)
|
||||
val visibility = when (statusesRequest.visibility) {
|
||||
StatusesRequest.Visibility.public -> Visibility.PUBLIC
|
||||
StatusesRequest.Visibility.unlisted -> Visibility.UNLISTED
|
||||
|
@ -45,11 +51,11 @@ class StatsesApiServiceImpl(
|
|||
val post = postService.createLocal(
|
||||
PostCreateDto(
|
||||
text = statusesRequest.status.orEmpty(),
|
||||
overview = statusesRequest.spoilerText,
|
||||
overview = statusesRequest.spoiler_text,
|
||||
visibility = visibility,
|
||||
repolyId = statusesRequest.inReplyToId?.toLongOrNull(),
|
||||
repolyId = statusesRequest.in_reply_to_id?.toLongOrNull(),
|
||||
userId = userId,
|
||||
mediaIds = statusesRequest.mediaIds.orEmpty().map { it.toLong() }
|
||||
mediaIds = statusesRequest.media_ids.orEmpty().map { it.toLong() }
|
||||
)
|
||||
)
|
||||
val account = accountService.findById(userId)
|
||||
|
|
Loading…
Reference in New Issue