♻️ Sørger for at http-statuskodene matcher request

This commit is contained in:
Amalie Mansåker 2023-08-10 09:58:02 +02:00
parent 42065587c0
commit 8c7f1a7b47

View file

@ -51,13 +51,13 @@ fun configureRouting(): ApplicationEngine = embeddedServer(CIO, applicationEngin
} }
get("/api/hentallefeil"){ get("/api/hentallefeil"){
val testMelding = feilmeldingRepository.hentAlleFeilmeldinger() val testMelding = feilmeldingRepository.hentAlleFeilmeldinger()
call.respond(status = HttpStatusCode.Created, message = testMelding) call.respond(status = HttpStatusCode.OK, message = testMelding)
} }
get("/api/hentsok/{sokestreng}"){ get("/api/hentsok/{sokestreng}"){
val sokestreng = call.parameters["sokestreng"] val sokestreng = call.parameters["sokestreng"]
?: return@get call.respond(HttpStatusCode.BadRequest, "Sokestreng må være definert") ?: return@get call.respond(HttpStatusCode.BadRequest, "Sokestreng må være definert")
val sokeresultat = feilmeldingRepository.hentSokteFeilmeldinger(sokestreng) val sokeresultat = feilmeldingRepository.hentSokteFeilmeldinger(sokestreng)
call.respond(status = HttpStatusCode.Created, message = sokeresultat) call.respond(status = HttpStatusCode.OK, message = sokeresultat)
} }
post("/api/nyfeil") { post("/api/nyfeil") {
val feilmelding = call.receive<Feilmelding>() val feilmelding = call.receive<Feilmelding>()
@ -67,18 +67,18 @@ fun configureRouting(): ApplicationEngine = embeddedServer(CIO, applicationEngin
put("/api/oppdaterfeil") { put("/api/oppdaterfeil") {
val oppdatertFeilmelding = call.receive<Feilmelding>() val oppdatertFeilmelding = call.receive<Feilmelding>()
feilmeldingRepository.oppdaterFeilmelding(oppdatertFeilmelding) feilmeldingRepository.oppdaterFeilmelding(oppdatertFeilmelding)
call.respond(status = HttpStatusCode.Created, message = "Feilmelding oppdatert") call.respond(status = HttpStatusCode.OK, message = "Feilmelding oppdatert")
} }
put("/api/oppdaterkommentar") { put("/api/oppdaterkommentar") {
val innkommendeKommentar = call.receive<InnkommendeKommentar>() val innkommendeKommentar = call.receive<InnkommendeKommentar>()
feilmeldingRepository.oppdaterKommentar(innkommendeKommentar.id, innkommendeKommentar.kommentar) feilmeldingRepository.oppdaterKommentar(innkommendeKommentar.id, innkommendeKommentar.kommentar)
call.respond(status = HttpStatusCode.Created, message = "Feilmelding oppdatert") call.respond(status = HttpStatusCode.OK, message = "Feilmelding oppdatert")
} }
delete("api/slettfeilmelding/{id}") { delete("api/slettfeilmelding/{id}") {
val id = call.parameters["id"] val id = call.parameters["id"]
checkNotNull(id) {"Id kan ikke være null"} checkNotNull(id) {"Id kan ikke være null"}
feilmeldingRepository.slettFeilmelding(id.toInt()) feilmeldingRepository.slettFeilmelding(id.toInt())
call.respond(status = HttpStatusCode.Created, message = "Feilmelding slettet") call.respond(status = HttpStatusCode.OK, message = "Feilmelding slettet")
} }
} }
} }