diff --git a/filbackend/src/main/kotlin/Filbackend.kt b/filbackend/src/main/kotlin/Filbackend.kt index fdc17e2..8a20b9f 100644 --- a/filbackend/src/main/kotlin/Filbackend.kt +++ b/filbackend/src/main/kotlin/Filbackend.kt @@ -3,18 +3,22 @@ import Filsluse.finnPerson import io.ktor.http.* import io.ktor.http.ContentType.Application.Json import io.ktor.http.HttpStatusCode.Companion.BadRequest +import io.ktor.http.HttpStatusCode.Companion.Created import io.ktor.http.HttpStatusCode.Companion.NotFound import io.ktor.http.HttpStatusCode.Companion.OK import io.ktor.server.application.* import io.ktor.server.cio.* import io.ktor.server.engine.* import io.ktor.server.http.content.* +import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* import java.util.UUID fun main() { embeddedServer(CIO, environment = applicationEngineEnvironment { + val personer = mutableMapOf() + val hendelser = mutableMapOf() module { routing { @@ -26,21 +30,30 @@ fun main() { get("/api/person/") { val maskertId = call.request.headers["maskertId"]?.let { UUID.fromString(it) } ?: return@get call.respond(BadRequest) - val person = maskertId.finnPerson() ?: return@get call.respond(NotFound) + val person = personer[maskertId] ?: maskertId.finnPerson() ?: return@get call.respond(NotFound) call.respondText(person, Json, OK) } post("/api/uuid/") { val maskertId = call.request.headers["maskertId"]?.let { UUID.fromString(it) } ?: return@post call.respond(BadRequest) - val person = maskertId.finnPerson() ?: return@post call.respond(NotFound) + val person = personer[maskertId] ?: maskertId.finnPerson() ?: return@post call.respond(NotFound) call.respondText(person, Json, OK) } get("/api/hendelse/{meldingsreferanse}") { val meldingsreferanse = call.parameters["meldingsreferanse"]?.let { UUID.fromString(it) } ?: return@get call.respond(BadRequest) - val hendelse = meldingsreferanse.finnHendelse() ?: return@get call.respond(NotFound) + val hendelse = hendelser[meldingsreferanse] ?: meldingsreferanse.finnHendelse() ?: return@get call.respond(NotFound) call.respondText(hendelse, Json, OK) } + + post("/api/{type}/{uuid}") { + val type = call.parameters["type"]?.takeIf { it in setOf("person", "hendelse") } ?: return@post call.respond(BadRequest) + val uuid = call.parameters["uuid"]?.let { UUID.fromString(it) } ?: return@post call.respond(BadRequest) + val json = call.receiveText() + if (type == "hendelse") hendelser[uuid] = json + else personer[uuid] = json + call.respond(Created) + } } }