feat: Statuses APIのログインユーザー取得部分を共通化

This commit is contained in:
usbharu 2024-01-26 12:09:29 +09:00
parent 91622bb33f
commit 34170d9b80
1 changed files with 10 additions and 7 deletions

View File

@ -1,25 +1,28 @@
package dev.usbharu.hideout.mastodon.interfaces.api.status
import dev.usbharu.hideout.controller.mastodon.generated.StatusApi
import dev.usbharu.hideout.core.infrastructure.springframework.security.LoginUserContextHolder
import dev.usbharu.hideout.domain.mastodon.model.generated.Status
import dev.usbharu.hideout.mastodon.service.status.StatusesApiService
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.security.oauth2.jwt.Jwt
import org.springframework.stereotype.Controller
@Controller
class MastodonStatusesApiContoller(private val statusesApiService: StatusesApiService) : StatusApi {
class MastodonStatusesApiContoller(
private val statusesApiService: StatusesApiService,
private val loginUserContextHolder: LoginUserContextHolder
) : StatusApi {
override suspend fun apiV1StatusesPost(
devUsbharuHideoutDomainModelMastodonStatusesRequest: StatusesRequest
): ResponseEntity<Status> {
val jwt = SecurityContextHolder.getContext().authentication.principal as Jwt
val userid = loginUserContextHolder.getLoginUserId()
return ResponseEntity(
statusesApiService.postStatus(
devUsbharuHideoutDomainModelMastodonStatusesRequest,
jwt.getClaim<String>("uid").toLong()
userid
),
HttpStatus.OK
)
@ -27,14 +30,14 @@ class MastodonStatusesApiContoller(private val statusesApiService: StatusesApiSe
override suspend fun apiV1StatusesIdEmojiReactionsEmojiDelete(id: String, emoji: String): ResponseEntity<Status> {
val uid =
(SecurityContextHolder.getContext().authentication.principal as Jwt).getClaim<String>("uid").toLong()
loginUserContextHolder.getLoginUserId()
return ResponseEntity.ok(statusesApiService.removeEmojiReactions(id.toLong(), uid, emoji))
}
override suspend fun apiV1StatusesIdEmojiReactionsEmojiPut(id: String, emoji: String): ResponseEntity<Status> {
val uid =
(SecurityContextHolder.getContext().authentication.principal as Jwt).getClaim<String>("uid").toLong()
loginUserContextHolder.getLoginUserId()
return ResponseEntity.ok(statusesApiService.emojiReactions(id.toLong(), uid, emoji))
}