From fc6be8f02c368bb2c91b0bf6c3125ab7c7902760 Mon Sep 17 00:00:00 2001 From: "Markus A. R. Johansen" <90006516+J0hans1@users.noreply.github.com> Date: Thu, 20 Jul 2023 16:01:36 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20bygger=20basen=20for=20API=20for=20?= =?UTF-8?q?henting=20av=20alle=20feilmeldinger=20fra=20database=20til=20fr?= =?UTF-8?q?ontend=20(#13)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../no/nav/helse/sprik/plugins/Routing.kt | 3 ++ frontend/src/components/CardsContainer.tsx | 44 ++++++++++++++----- frontend/src/index.tsx | 4 +- frontend/src/interface.ts | 1 + frontend/src/pages/feil.tsx | 3 -- 5 files changed, 39 insertions(+), 16 deletions(-) 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 3f258fe..b94e557 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 @@ -56,6 +56,9 @@ fun configureRouting(): ApplicationEngine = embeddedServer(CIO, applicationEngin feilmeldingRepository.lagre(feilmelding) call.respond(status = HttpStatusCode.Created, message = "Feilmelding motatt og sendt til database") } + get("/api/hentfeil"){ + call.respond(status = HttpStatusCode.Created, message = "Prøver å hente feil fra DB") + } } } connector { diff --git a/frontend/src/components/CardsContainer.tsx b/frontend/src/components/CardsContainer.tsx index cacf5bd..392c106 100644 --- a/frontend/src/components/CardsContainer.tsx +++ b/frontend/src/components/CardsContainer.tsx @@ -1,35 +1,52 @@ +import axios from "axios" import FeilCard from "./FeilCard" +import useSWR from "swr" /** * * @returns Komponent for returnering av konteiner med alle feilinnmeldingene. */ +const fetcher = (url: RequestInfo | URL) => fetch(url).then(r => r.json()) + + +const fetchFeil = () => { + const {data, error, isLoading } = useSWR("/api/hentFeil", fetcher) + if (error) return
Forsøker å loade feil objekter her:
+ {fetchFeil()} +