feat: Spring MVCのControllerでActivityPubのエンドポイントを実装

This commit is contained in:
usbharu 2023-09-19 12:49:39 +09:00
parent 656e935ce2
commit afb606c9e2
6 changed files with 93 additions and 0 deletions

View File

@ -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<Unit> {
return ResponseEntity(HttpStatus.ACCEPTED)
}
}

View File

@ -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<Unit> {
val parseActivity = apService.parseActivity(string)
apService.processActivity(string, parseActivity)
return ResponseEntity(HttpStatus.ACCEPTED)
}
}

View File

@ -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<Unit> {
return ResponseEntity(HttpStatus.ACCEPTED)
}
}

View File

@ -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<Unit> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}
}

View File

@ -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<Person>
}

View File

@ -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<Person> {
val person = apUserService.getPersonByName(username)
return ResponseEntity(person, HttpStatus.OK)
}
}