feat: レスポンスのクラスを作成

This commit is contained in:
usbharu 2023-04-07 14:50:49 +09:00
parent 469b886caf
commit ab01b61f55
5 changed files with 18 additions and 5 deletions

View File

@ -0,0 +1,5 @@
package dev.usbharu.hideout.domain.model
import io.ktor.http.*
data class ActivityPubResponse(val httpStatusCode: HttpStatusCode, val message:String)

View File

@ -20,8 +20,12 @@ fun Routing.inbox(httpSignatureVerifyService: HttpSignatureVerifyService,activit
} }
val json = call.receiveText() val json = call.receiveText()
val activityTypes = activityPubService.parseActivity(json) val activityTypes = activityPubService.parseActivity(json)
activityPubService.processActivity(json,activityTypes) val response = activityPubService.processActivity(json, activityTypes)
call.respond(HttpStatusCode.NotImplemented) return@post if (response != null) {
call.respond(response.httpStatusCode, response.message)
}else {
call.respond(HttpStatusCode.InternalServerError)
}
} }
} }
route("/users/{name}/inbox"){ route("/users/{name}/inbox"){

View File

@ -1,9 +1,11 @@
package dev.usbharu.hideout.service.activitypub package dev.usbharu.hideout.service.activitypub
import dev.usbharu.hideout.domain.model.ActivityPubResponse
interface ActivityPubService { interface ActivityPubService {
fun parseActivity(json:String): ActivityType fun parseActivity(json:String): ActivityType
fun processActivity(json:String, type: ActivityType) fun processActivity(json:String, type: ActivityType):ActivityPubResponse?
} }
enum class ActivityType { enum class ActivityType {

View File

@ -2,6 +2,7 @@ package dev.usbharu.hideout.service.activitypub
import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.JsonNode
import dev.usbharu.hideout.config.Config import dev.usbharu.hideout.config.Config
import dev.usbharu.hideout.domain.model.ActivityPubResponse
import dev.usbharu.hideout.exception.JsonParseException import dev.usbharu.hideout.exception.JsonParseException
class ActivityPubServiceImpl : ActivityPubService { class ActivityPubServiceImpl : ActivityPubService {
@ -19,7 +20,7 @@ class ActivityPubServiceImpl : ActivityPubService {
return ActivityType.values().first { it.name.equals(type.asText(), true) } return ActivityType.values().first { it.name.equals(type.asText(), true) }
} }
override fun processActivity(json: String, type: ActivityType) { override fun processActivity(json: String, type: ActivityType): ActivityPubResponse? {
when (type) { when (type) {
ActivityType.Accept -> TODO() ActivityType.Accept -> TODO()
ActivityType.Add -> TODO() ActivityType.Add -> TODO()

View File

@ -1,5 +1,6 @@
package dev.usbharu.hideout.routing.activitypub package dev.usbharu.hideout.routing.activitypub
import dev.usbharu.hideout.domain.model.ActivityPubResponse
import dev.usbharu.hideout.plugins.configureRouting import dev.usbharu.hideout.plugins.configureRouting
import dev.usbharu.hideout.service.activitypub.ActivityPubService import dev.usbharu.hideout.service.activitypub.ActivityPubService
import dev.usbharu.hideout.service.activitypub.ActivityType import dev.usbharu.hideout.service.activitypub.ActivityType
@ -30,7 +31,7 @@ class UsersAPTest {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
override fun processActivity(json: String, type: ActivityType) { override fun processActivity(json: String, type: ActivityType): ActivityPubResponse? {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
}) })