🐛 Klarer å registrere og lagre ny feilmelding

Fikser deserialisering av dato og post-error

Co-authored-by: Sindre Kjelsrud <sindre.kjelsrud@nav.no>
This commit is contained in:
Amalie Mansåker 2023-07-21 10:07:51 +02:00
parent baf3e3a867
commit 3cd3a5e933
4 changed files with 11 additions and 8 deletions

View file

@ -2,6 +2,8 @@ package no.nav.helse.sprik
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import no.nav.helse.sprik.db.Database import no.nav.helse.sprik.db.Database
import org.jetbrains.exposed.sql.Database as ExposedDatabase
import no.nav.helse.sprik.plugins.* import no.nav.helse.sprik.plugins.*
fun main() { fun main() {
@ -14,6 +16,7 @@ fun main() {
class Application(private val db: Database) { class Application(private val db: Database) {
fun startBlocking() { fun startBlocking() {
runBlocking { runBlocking {
ExposedDatabase.connect(db.dataSource)
configureRouting().start(wait = true) configureRouting().start(wait = true)
Runtime.getRuntime().addShutdownHook( Runtime.getRuntime().addShutdownHook(
Thread { Thread {

View file

@ -16,8 +16,6 @@ import java.time.LocalDateTime
class Feilmelding( class Feilmelding(
val tittel: String, val tittel: String,
val beskrivelse: String, val beskrivelse: String,
@Serializable(LocalDateTimeSerializer::class)
val dato: LocalDateTime, //Krever en spesiallaget serialiserer i KotlinX val dato: LocalDateTime, //Krever en spesiallaget serialiserer i KotlinX
//val tags: ArrayList<String> = arrayListOf<String>() //val tags: ArrayList<String> = arrayListOf<String>()
//val bilde: String, //val bilde: String,

View file

@ -53,6 +53,7 @@ fun configureRouting(): ApplicationEngine = embeddedServer(CIO, applicationEngin
} }
post("/api/nyfeil") { post("/api/nyfeil") {
val feilmelding = call.receive<Feilmelding>() val feilmelding = call.receive<Feilmelding>()
println(feilmelding.tittel)
feilmeldingRepository.lagre(feilmelding) feilmeldingRepository.lagre(feilmelding)
call.respond(status = HttpStatusCode.Created, message = "Feilmelding motatt og sendt til database") call.respond(status = HttpStatusCode.Created, message = "Feilmelding motatt og sendt til database")
} }

View file

@ -12,14 +12,15 @@ export default function Feil() {
const [tittel, setTittel] = useState(""); const [tittel, setTittel] = useState("");
const [beskrivelse, setBeskrivelse] = useState(""); const [beskrivelse, setBeskrivelse] = useState("");
const url = "https://helse-sprik.intern.dev.nav.no"
//const url = "http://localhost:5174"
const handleSubmit = () => { const handleSubmit = () => {
axios.post("https://helse-sprik.intern.dev.nav.no/nyfeil", axios.post(url + "/api/nyfeil",
{ {
"data": {
tittel: tittel, tittel: tittel,
beskrivelse: beskrivelse, beskrivelse: beskrivelse,
dato: new Date() dato: new Date().toISOString().replace('Z', '')
}
}, { }, {
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'