Slett feilmeldinger (#34)

*  Backend støtter mulighet for å slette innmeldte feilmeldinger

*  Knapp i redigeringsverktøy for sletting av feil

* 🐛 Fikset routing bug, Delete was not allowed, og feil endepunkt i frontend

* ️ Refresher mainpage ved sletting av feil

---------

Co-authored-by: Amalie Mansåker <amalie.erdal.mansaker@nav.no>
Co-authored-by: Sindre Kjelsrud <sindre.kjelsrud@nav.no>
This commit is contained in:
Markus A. R. Johansen 2023-08-11 09:53:09 +02:00 committed by GitHub
parent df3ce139c2
commit 900422a4e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 1 deletions

View file

@ -71,4 +71,8 @@ class FeilmeldingRepository {
it[FeilmeldingTable.kommentar] = kommentar
}
}
fun slettFeilmelding(id: Int) = transaction {
FeilmeldingTable.deleteWhere { FeilmeldingTable.id eq id }
}
}

View file

@ -28,6 +28,7 @@ fun configureRouting(): ApplicationEngine = embeddedServer(CIO, applicationEngin
allowMethod(HttpMethod.Get)
allowMethod(HttpMethod.Post)
allowMethod(HttpMethod.Put)
allowMethod(HttpMethod.Delete)
allowNonSimpleContentTypes = true
}
install(ContentNegotiation) {
@ -73,6 +74,12 @@ fun configureRouting(): ApplicationEngine = embeddedServer(CIO, applicationEngin
feilmeldingRepository.oppdaterKommentar(innkommendeKommentar.id, innkommendeKommentar.kommentar)
call.respond(status = HttpStatusCode.Created, message = "Feilmelding oppdatert")
}
delete("api/slettfeilmelding/{id}") {
val id = call.parameters["id"]
checkNotNull(id) {"Id kan ikke være null"}
feilmeldingRepository.slettFeilmelding(id.toInt())
call.respond(status = HttpStatusCode.Created, message = "Feilmelding slettet")
}
}
}

View file

@ -188,4 +188,12 @@ class FeilmeldingTest {
val oppdatertKommentar = transaction { FeilmeldingTable.selectAll().single()[FeilmeldingTable.kommentar] }
assertEquals("Oppdatert kommentar", oppdatertKommentar)
}
@Test
fun `Feilmelding slettes basert på id`() {
feilmeldingRepository.lagre(feilmelding)
feilmeldingRepository.slettFeilmelding(getId())
val resultat = transaction { FeilmeldingTable.selectAll().map { it }.size }
assertEquals(0, resultat)
}
}