From 34170d9b8013ce8cd45e7d8709327ad40acd368d Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 26 Jan 2024 12:09:29 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Statuses=20API=E3=81=AE=E3=83=AD?= =?UTF-8?q?=E3=82=B0=E3=82=A4=E3=83=B3=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC?= =?UTF-8?q?=E5=8F=96=E5=BE=97=E9=83=A8=E5=88=86=E3=82=92=E5=85=B1=E9=80=9A?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/status/MastodonStatusesApiContoller.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/status/MastodonStatusesApiContoller.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/status/MastodonStatusesApiContoller.kt index cc6443ce..5d1734cf 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/status/MastodonStatusesApiContoller.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/status/MastodonStatusesApiContoller.kt @@ -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 { - val jwt = SecurityContextHolder.getContext().authentication.principal as Jwt + val userid = loginUserContextHolder.getLoginUserId() + return ResponseEntity( statusesApiService.postStatus( devUsbharuHideoutDomainModelMastodonStatusesRequest, - jwt.getClaim("uid").toLong() + userid ), HttpStatus.OK ) @@ -27,14 +30,14 @@ class MastodonStatusesApiContoller(private val statusesApiService: StatusesApiSe override suspend fun apiV1StatusesIdEmojiReactionsEmojiDelete(id: String, emoji: String): ResponseEntity { val uid = - (SecurityContextHolder.getContext().authentication.principal as Jwt).getClaim("uid").toLong() + loginUserContextHolder.getLoginUserId() return ResponseEntity.ok(statusesApiService.removeEmojiReactions(id.toLong(), uid, emoji)) } override suspend fun apiV1StatusesIdEmojiReactionsEmojiPut(id: String, emoji: String): ResponseEntity { val uid = - (SecurityContextHolder.getContext().authentication.principal as Jwt).getClaim("uid").toLong() + loginUserContextHolder.getLoginUserId() return ResponseEntity.ok(statusesApiService.emojiReactions(id.toLong(), uid, emoji)) }