From 3cd3a5e933b39a457b79b44c0d2acbf9409e434b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amalie=20Mans=C3=A5ker?= Date: Fri, 21 Jul 2023 10:07:51 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Klarer=20=C3=A5=20registrere=20o?= =?UTF-8?q?g=20lagre=20ny=20feilmelding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fikser deserialisering av dato og post-error Co-authored-by: Sindre Kjelsrud --- .../main/kotlin/no/nav/helse/sprik/Application.kt | 3 +++ .../kotlin/no/nav/helse/sprik/modell/Feilmelding.kt | 2 -- .../kotlin/no/nav/helse/sprik/plugins/Routing.kt | 1 + frontend/src/pages/feil.tsx | 13 +++++++------ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/backend/src/main/kotlin/no/nav/helse/sprik/Application.kt b/backend/src/main/kotlin/no/nav/helse/sprik/Application.kt index 2ff3f15..d056654 100644 --- a/backend/src/main/kotlin/no/nav/helse/sprik/Application.kt +++ b/backend/src/main/kotlin/no/nav/helse/sprik/Application.kt @@ -2,6 +2,8 @@ package no.nav.helse.sprik import kotlinx.coroutines.runBlocking import no.nav.helse.sprik.db.Database +import org.jetbrains.exposed.sql.Database as ExposedDatabase + import no.nav.helse.sprik.plugins.* fun main() { @@ -14,6 +16,7 @@ fun main() { class Application(private val db: Database) { fun startBlocking() { runBlocking { + ExposedDatabase.connect(db.dataSource) configureRouting().start(wait = true) Runtime.getRuntime().addShutdownHook( Thread { diff --git a/backend/src/main/kotlin/no/nav/helse/sprik/modell/Feilmelding.kt b/backend/src/main/kotlin/no/nav/helse/sprik/modell/Feilmelding.kt index 496c9a8..4334ab2 100644 --- a/backend/src/main/kotlin/no/nav/helse/sprik/modell/Feilmelding.kt +++ b/backend/src/main/kotlin/no/nav/helse/sprik/modell/Feilmelding.kt @@ -16,8 +16,6 @@ import java.time.LocalDateTime class Feilmelding( val tittel: String, val beskrivelse: String, - - @Serializable(LocalDateTimeSerializer::class) val dato: LocalDateTime, //Krever en spesiallaget serialiserer i KotlinX //val tags: ArrayList = arrayListOf() //val bilde: String, diff --git a/backend/src/main/kotlin/no/nav/helse/sprik/plugins/Routing.kt b/backend/src/main/kotlin/no/nav/helse/sprik/plugins/Routing.kt index b94e557..b77e46b 100644 --- a/backend/src/main/kotlin/no/nav/helse/sprik/plugins/Routing.kt +++ b/backend/src/main/kotlin/no/nav/helse/sprik/plugins/Routing.kt @@ -53,6 +53,7 @@ fun configureRouting(): ApplicationEngine = embeddedServer(CIO, applicationEngin } post("/api/nyfeil") { val feilmelding = call.receive() + println(feilmelding.tittel) feilmeldingRepository.lagre(feilmelding) call.respond(status = HttpStatusCode.Created, message = "Feilmelding motatt og sendt til database") } diff --git a/frontend/src/pages/feil.tsx b/frontend/src/pages/feil.tsx index d8745b2..8e114ef 100644 --- a/frontend/src/pages/feil.tsx +++ b/frontend/src/pages/feil.tsx @@ -12,14 +12,15 @@ export default function Feil() { const [tittel, setTittel] = useState(""); const [beskrivelse, setBeskrivelse] = useState(""); + const url = "https://helse-sprik.intern.dev.nav.no" + //const url = "http://localhost:5174" + const handleSubmit = () => { - axios.post("https://helse-sprik.intern.dev.nav.no/nyfeil", + axios.post(url + "/api/nyfeil", { - "data": { - tittel: tittel, - beskrivelse: beskrivelse, - dato: new Date() - } + tittel: tittel, + beskrivelse: beskrivelse, + dato: new Date().toISOString().replace('Z', '') }, { headers: { 'Content-Type': 'application/json'