Skip to content

Commit

Permalink
Legger til et endpunkt man kan laste opp hendelser & personer
Browse files Browse the repository at this point in the history
Co-authored-by: David Steinsland <david@davidsteinsland.net>
Co-authored-by: Simen Ullern <simen.ullern@nav.no>
Co-authored-by: Hege Haavaldsen <hege.haavaldsen@nav.no>
  • Loading branch information
4 people committed Aug 26, 2024
1 parent e72a3d5 commit e3895e9
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions filbackend/src/main/kotlin/Filbackend.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<UUID, String>()
val hendelser = mutableMapOf<UUID, String>()

module {
routing {
Expand All @@ -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)
}
}
}

Expand Down

0 comments on commit e3895e9

Please sign in to comment.