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

This commit is contained in:
usbharu 2024-01-26 12:09:40 +09:00
parent 34170d9b80
commit 54b89c290a
1 changed files with 7 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package dev.usbharu.hideout.mastodon.interfaces.api.timeline
import dev.usbharu.hideout.controller.mastodon.generated.TimelineApi
import dev.usbharu.hideout.core.infrastructure.springframework.security.LoginUserContextHolder
import dev.usbharu.hideout.domain.mastodon.model.generated.Status
import dev.usbharu.hideout.mastodon.service.timeline.TimelineApiService
import kotlinx.coroutines.flow.Flow
@ -8,21 +9,22 @@ import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.runBlocking
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 MastodonTimelineApiController(private val timelineApiService: TimelineApiService) : TimelineApi {
class MastodonTimelineApiController(
private val timelineApiService: TimelineApiService,
private val loginUserContextHolder: LoginUserContextHolder
) : TimelineApi {
override fun apiV1TimelinesHomeGet(
maxId: String?,
sinceId: String?,
minId: String?,
limit: Int?
): ResponseEntity<Flow<Status>> = runBlocking {
val jwt = SecurityContextHolder.getContext().authentication.principal as Jwt
val homeTimeline = timelineApiService.homeTimeline(
userId = jwt.getClaim<String>("uid").toLong(),
userId = loginUserContextHolder.getLoginUserId(),
maxId = maxId?.toLongOrNull(),
minId = minId?.toLongOrNull(),
sinceId = sinceId?.toLongOrNull(),