From afb606c9e26e536499396c0d49e5e84d73f1a640 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:49:39 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Spring=20MVC=E3=81=AEController?= =?UTF-8?q?=E3=81=A7ActivityPub=E3=81=AE=E3=82=A8=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=83=9D=E3=82=A4=E3=83=B3=E3=83=88=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/controller/InboxController.kt | 21 +++++++++++++++++++ .../hideout/controller/InboxControllerImpl.kt | 15 +++++++++++++ .../hideout/controller/OutboxController.kt | 16 ++++++++++++++ .../controller/OutboxControllerImpl.kt | 13 ++++++++++++ .../hideout/controller/UserAPController.kt | 13 ++++++++++++ .../controller/UserAPControllerImpl.kt | 15 +++++++++++++ 6 files changed, 93 insertions(+) create mode 100644 src/main/kotlin/dev/usbharu/hideout/controller/InboxController.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/controller/InboxControllerImpl.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/controller/OutboxController.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/controller/OutboxControllerImpl.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/controller/UserAPController.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/controller/UserAPControllerImpl.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/controller/InboxController.kt b/src/main/kotlin/dev/usbharu/hideout/controller/InboxController.kt new file mode 100644 index 00000000..0cba64e3 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/controller/InboxController.kt @@ -0,0 +1,21 @@ +package dev.usbharu.hideout.controller + +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.RestController + +@RestController +interface InboxController { + @RequestMapping( + "/inbox", + "/users/{username}/inbox", + produces = ["application/activity+json", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""], + method = [RequestMethod.GET, RequestMethod.POST] + ) + suspend fun inbox(@RequestBody string: String): ResponseEntity { + return ResponseEntity(HttpStatus.ACCEPTED) + } +} diff --git a/src/main/kotlin/dev/usbharu/hideout/controller/InboxControllerImpl.kt b/src/main/kotlin/dev/usbharu/hideout/controller/InboxControllerImpl.kt new file mode 100644 index 00000000..002dee31 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/controller/InboxControllerImpl.kt @@ -0,0 +1,15 @@ +package dev.usbharu.hideout.controller + +import dev.usbharu.hideout.service.ap.APService +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.RestController + +@RestController +class InboxControllerImpl(private val apService: APService) : InboxController { + override suspend fun inbox(string: String): ResponseEntity { + val parseActivity = apService.parseActivity(string) + apService.processActivity(string, parseActivity) + return ResponseEntity(HttpStatus.ACCEPTED) + } +} diff --git a/src/main/kotlin/dev/usbharu/hideout/controller/OutboxController.kt b/src/main/kotlin/dev/usbharu/hideout/controller/OutboxController.kt new file mode 100644 index 00000000..ee003682 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/controller/OutboxController.kt @@ -0,0 +1,16 @@ +package dev.usbharu.hideout.controller + +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.RestController + +@RestController +interface OutboxController { + @RequestMapping("/outbox", "/users/{username}/outbox", method = [RequestMethod.POST, RequestMethod.GET]) + fun outbox(@RequestBody string: String): ResponseEntity { + return ResponseEntity(HttpStatus.ACCEPTED) + } +} diff --git a/src/main/kotlin/dev/usbharu/hideout/controller/OutboxControllerImpl.kt b/src/main/kotlin/dev/usbharu/hideout/controller/OutboxControllerImpl.kt new file mode 100644 index 00000000..04dc227f --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/controller/OutboxControllerImpl.kt @@ -0,0 +1,13 @@ +package dev.usbharu.hideout.controller + +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RestController + +@RestController +class OutboxControllerImpl : OutboxController { + override fun outbox(@RequestBody string: String): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } +} diff --git a/src/main/kotlin/dev/usbharu/hideout/controller/UserAPController.kt b/src/main/kotlin/dev/usbharu/hideout/controller/UserAPController.kt new file mode 100644 index 00000000..5390fff2 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/controller/UserAPController.kt @@ -0,0 +1,13 @@ +package dev.usbharu.hideout.controller + +import dev.usbharu.hideout.domain.model.ap.Person +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RestController + +@RestController +interface UserAPController { + @GetMapping("/users/{username}") + suspend fun userAp(@PathVariable("username") username: String): ResponseEntity +} diff --git a/src/main/kotlin/dev/usbharu/hideout/controller/UserAPControllerImpl.kt b/src/main/kotlin/dev/usbharu/hideout/controller/UserAPControllerImpl.kt new file mode 100644 index 00000000..90fb6155 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/controller/UserAPControllerImpl.kt @@ -0,0 +1,15 @@ +package dev.usbharu.hideout.controller + +import dev.usbharu.hideout.domain.model.ap.Person +import dev.usbharu.hideout.service.ap.APUserService +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.RestController + +@RestController +class UserAPControllerImpl(private val apUserService: APUserService) : UserAPController { + override suspend fun userAp(username: String): ResponseEntity { + val person = apUserService.getPersonByName(username) + return ResponseEntity(person, HttpStatus.OK) + } +}