feat: mastodon 互換APIを追加

This commit is contained in:
usbharu 2024-09-08 23:32:01 +09:00
parent 7665286270
commit 021f6b0d45
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
2 changed files with 63 additions and 1 deletions

View File

@ -18,6 +18,10 @@ 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.application.reaction.CreateReaction
import dev.usbharu.hideout.core.application.reaction.RemoveReaction
import dev.usbharu.hideout.core.application.reaction.UserCreateReactionApplicationService
import dev.usbharu.hideout.core.application.reaction.UserRemoveReactionApplicationService
import dev.usbharu.hideout.core.domain.model.post.Visibility
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.SpringSecurityOauth2PrincipalContextHolder
import dev.usbharu.hideout.mastodon.application.status.GetStatus
@ -32,7 +36,9 @@ import org.springframework.stereotype.Controller
class SpringStatusApi(
private val registerLocalPostApplicationService: RegisterLocalPostApplicationService,
private val getStatusApplicationService: GetStatusApplicationService,
private val principalContextHolder: SpringSecurityOauth2PrincipalContextHolder
private val principalContextHolder: SpringSecurityOauth2PrincipalContextHolder,
private val userCreateReactionApplicationService: UserCreateReactionApplicationService,
private val userRemoveReactionApplicationService: UserRemoveReactionApplicationService
) : StatusApi {
override suspend fun apiV1StatusesIdEmojiReactionsEmojiDelete(id: String, emoji: String): ResponseEntity<Status> =
super.apiV1StatusesIdEmojiReactionsEmojiDelete(id, emoji)
@ -49,6 +55,20 @@ class SpringStatusApi(
)
}
override suspend fun apiV1StatusesIdFavouritePost(id: String): ResponseEntity<Status> {
val principal = principalContextHolder.getPrincipal()
userCreateReactionApplicationService.execute(CreateReaction(postId = id.toLong(), null, ""), principal)
return ResponseEntity.ok(getStatusApplicationService.execute(GetStatus(id), principal))
}
override suspend fun apiV1StatusesIdUnfavouritePost(id: String): ResponseEntity<Status> {
val principal = principalContextHolder.getPrincipal()
userRemoveReactionApplicationService.execute(RemoveReaction(postId = id.toLong(), null, ""), principal)
return ResponseEntity.ok(getStatusApplicationService.execute(GetStatus(id), principal))
}
override suspend fun apiV1StatusesPost(statusesRequest: StatusesRequest): ResponseEntity<Status> {
val principal = principalContextHolder.getPrincipal()
val execute = registerLocalPostApplicationService.execute(

View File

@ -177,6 +177,48 @@ paths:
schema:
$ref: "#/components/schemas/Status"
/api/v1/statuses/{id}/favourite:
post:
tags:
- status
security:
- OAuth2:
- "write:favourites"
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
200:
description: 成功
content:
application/json:
schema:
$ref: "#/components/schemas/Status"
/api/v1/statuses/{id}/unfavourite:
post:
tags:
- status
security:
- OAuth2:
- "write:favourites"
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
200:
description: 成功
content:
application/json:
schema:
$ref: "#/components/schemas/Status"
/api/v1/statuses/{id}/emoji_reactions/{emoji}:
put:
tags: