From 2f4cf69334e376490620acfd1f7f906c38aacb1c Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sun, 24 Sep 2023 10:40:22 +0900 Subject: [PATCH] feat: remove Spring WebFlux --- build.gradle.kts | 6 ------ .../controller/mastodon/MastodonAccountApiController.kt | 5 +++-- .../controller/mastodon/MastodonAppsApiController.kt | 9 +++++---- .../controller/mastodon/MastodonInstanceApiController.kt | 5 +++-- .../controller/mastodon/MastodonStatusesApiContoller.kt | 5 +++-- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index fa1458da..bf3eafb9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -55,11 +55,7 @@ tasks.create("openApiGenerateMastodonCompatibleApi", GenerateTask: modelPackage.set("dev.usbharu.hideout.domain.mastodon.model.generated") configOptions.put("interfaceOnly", "true") configOptions.put("useSpringBoot3", "true") - configOptions.put("reactive", "true") additionalProperties.put("useTags", "true") - -// importMappings.putAll(mapOf("ReactionResponse" to "ReactionResponse")) -// typeMappings.putAll(mapOf("ReactionResponse" to "ReactionResponse")) } repositories { @@ -108,8 +104,6 @@ dependencies { implementation("org.springframework.data:spring-data-commons") implementation("org.springframework.boot:spring-boot-starter-jdbc") implementation("org.springframework.boot:spring-boot-starter-data-jdbc") - implementation("org.springframework.boot:spring-boot-starter-webflux") - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor") testImplementation("org.springframework.boot:spring-boot-test-autoconfigure") testImplementation("org.springframework.boot:spring-boot-starter-test") implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") diff --git a/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonAccountApiController.kt b/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonAccountApiController.kt index c9285d01..d6754a3d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonAccountApiController.kt +++ b/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonAccountApiController.kt @@ -3,6 +3,7 @@ package dev.usbharu.hideout.controller.mastodon import dev.usbharu.hideout.controller.mastodon.generated.AccountApi import dev.usbharu.hideout.domain.mastodon.model.generated.CredentialAccount import dev.usbharu.hideout.service.api.mastodon.AccountApiService +import kotlinx.coroutines.runBlocking import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.security.core.context.SecurityContextHolder @@ -11,10 +12,10 @@ import org.springframework.stereotype.Controller @Controller class MastodonAccountApiController(private val accountApiService: AccountApiService) : AccountApi { - override suspend fun apiV1AccountsVerifyCredentialsGet(): ResponseEntity { + override fun apiV1AccountsVerifyCredentialsGet(): ResponseEntity = runBlocking { val principal = SecurityContextHolder.getContext().getAuthentication().principal as Jwt - return ResponseEntity( + ResponseEntity( accountApiService.verifyCredentials(principal.getClaim("uid").toLong()), HttpStatus.OK ) diff --git a/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonAppsApiController.kt b/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonAppsApiController.kt index 934b7d79..44d9582a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonAppsApiController.kt +++ b/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonAppsApiController.kt @@ -4,6 +4,7 @@ import dev.usbharu.hideout.controller.mastodon.generated.AppApi import dev.usbharu.hideout.domain.mastodon.model.generated.Application import dev.usbharu.hideout.domain.mastodon.model.generated.AppsRequest import dev.usbharu.hideout.service.api.mastodon.AppApiService +import kotlinx.coroutines.runBlocking import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.stereotype.Controller @@ -13,9 +14,9 @@ import org.springframework.web.bind.annotation.RequestParam @Controller class MastodonAppsApiController(private val appApiService: AppApiService) : AppApi { - override suspend fun apiV1AppsPost(appsRequest: AppsRequest): ResponseEntity { + override fun apiV1AppsPost(appsRequest: AppsRequest): ResponseEntity = runBlocking { println(appsRequest) - return ResponseEntity( + ResponseEntity( appApiService.createApp(appsRequest), HttpStatus.OK ) @@ -27,10 +28,10 @@ class MastodonAppsApiController(private val appApiService: AppApiService) : AppA produces = ["application/json"], consumes = ["application/x-www-form-urlencoded"] ) - suspend fun apiV1AppsPost(@RequestParam map: Map): ResponseEntity { + fun apiV1AppsPost(@RequestParam map: Map): ResponseEntity = runBlocking { val appsRequest = AppsRequest(map.getValue("client_name"), map.getValue("redirect_uris"), map["scopes"], map["website"]) - return ResponseEntity( + ResponseEntity( appApiService.createApp(appsRequest), HttpStatus.OK ) diff --git a/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonInstanceApiController.kt b/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonInstanceApiController.kt index 207d809c..5741fd2e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonInstanceApiController.kt +++ b/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonInstanceApiController.kt @@ -3,13 +3,14 @@ package dev.usbharu.hideout.controller.mastodon import dev.usbharu.hideout.controller.mastodon.generated.InstanceApi import dev.usbharu.hideout.domain.mastodon.model.generated.V1Instance import dev.usbharu.hideout.service.api.mastodon.InstanceApiService +import kotlinx.coroutines.runBlocking import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.stereotype.Controller @Controller class MastodonInstanceApiController(private val instanceApiService: InstanceApiService) : InstanceApi { - override suspend fun apiV1InstanceGet(): ResponseEntity { - return ResponseEntity(instanceApiService.v1Instance(), HttpStatus.OK) + override fun apiV1InstanceGet(): ResponseEntity = runBlocking { + ResponseEntity(instanceApiService.v1Instance(), HttpStatus.OK) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonStatusesApiContoller.kt b/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonStatusesApiContoller.kt index 0e81d218..b75a7da0 100644 --- a/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonStatusesApiContoller.kt +++ b/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonStatusesApiContoller.kt @@ -5,6 +5,7 @@ import dev.usbharu.hideout.domain.mastodon.model.generated.Status import dev.usbharu.hideout.domain.mastodon.model.generated.StatusesRequest import dev.usbharu.hideout.domain.model.UserDetailsImpl import dev.usbharu.hideout.service.api.mastodon.StatusesApiService +import kotlinx.coroutines.runBlocking import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.security.core.context.SecurityContextHolder @@ -12,9 +13,9 @@ import org.springframework.stereotype.Controller @Controller class MastodonStatusesApiContoller(private val statusesApiService: StatusesApiService) : StatusApi { - override suspend fun apiV1StatusesPost(statusesRequest: StatusesRequest): ResponseEntity { + override fun apiV1StatusesPost(statusesRequest: StatusesRequest): ResponseEntity = runBlocking { val principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal() require(principal is UserDetailsImpl) - return ResponseEntity(statusesApiService.postStatus(statusesRequest, principal), HttpStatus.OK) + ResponseEntity(statusesApiService.postStatus(statusesRequest, principal), HttpStatus.OK) } }