diff --git a/backend/src/main/kotlin/no/nav/helse/sprik/db/FeilmeldingRepository.kt b/backend/src/main/kotlin/no/nav/helse/sprik/db/FeilmeldingRepository.kt index 64a264c..ad368ac 100644 --- a/backend/src/main/kotlin/no/nav/helse/sprik/db/FeilmeldingRepository.kt +++ b/backend/src/main/kotlin/no/nav/helse/sprik/db/FeilmeldingRepository.kt @@ -2,14 +2,16 @@ package no.nav.helse.sprik.db import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.transactions.transaction +import java.time.LocalDateTime class FeilmeldingRepository { - fun lagre(tittel: String, beskrivelse: String){ + fun lagre(tittel: String, beskrivelse: String, dato: LocalDateTime){ transaction { FeilmeldingTable.run { insert { it[FeilmeldingTable.tittel] = tittel it[FeilmeldingTable.beskrivelse] = beskrivelse + it[FeilmeldingTable.dato] = dato } } } diff --git a/backend/src/main/kotlin/no/nav/helse/sprik/db/FeilmeldingTable.kt b/backend/src/main/kotlin/no/nav/helse/sprik/db/FeilmeldingTable.kt index ab85da7..8a15d01 100644 --- a/backend/src/main/kotlin/no/nav/helse/sprik/db/FeilmeldingTable.kt +++ b/backend/src/main/kotlin/no/nav/helse/sprik/db/FeilmeldingTable.kt @@ -1,8 +1,10 @@ package no.nav.helse.sprik.db import org.jetbrains.exposed.sql.Table +import org.jetbrains.exposed.sql.javatime.datetime object FeilmeldingTable : Table("feilmelding") { val tittel = text("tittel") val beskrivelse = text("beskrivelse") + val dato = datetime("dato") } \ No newline at end of file diff --git a/backend/src/main/resources/db/migration/V3__leggerTilDatoIFeilmelding.sql b/backend/src/main/resources/db/migration/V3__leggerTilDatoIFeilmelding.sql new file mode 100644 index 0000000..a853492 --- /dev/null +++ b/backend/src/main/resources/db/migration/V3__leggerTilDatoIFeilmelding.sql @@ -0,0 +1 @@ +ALTER TABLE feilmelding ADD dato TIMESTAMP \ No newline at end of file diff --git a/backend/src/test/kotlin/no/nav/helse/sprik/FeilmeldingTest.kt b/backend/src/test/kotlin/no/nav/helse/sprik/FeilmeldingTest.kt index d69bc52..30259f2 100644 --- a/backend/src/test/kotlin/no/nav/helse/sprik/FeilmeldingTest.kt +++ b/backend/src/test/kotlin/no/nav/helse/sprik/FeilmeldingTest.kt @@ -12,6 +12,7 @@ import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance +import java.time.LocalDateTime import kotlin.test.assertEquals import org.jetbrains.exposed.sql.Database as ExposedDatabase @@ -31,24 +32,25 @@ class FeilmeldingTest { FeilmeldingTable.deleteAll() } } - - @Test - fun `Lagrer feilmelding i databasen`() { - feilmeldingRepository.lagre("test", "testesen") - transaction { - val actual = FeilmeldingTable.selectAll().single() - assertEquals("test", actual[FeilmeldingTable.tittel]) - assertEquals("testesen", actual[FeilmeldingTable.beskrivelse]) - } - } - @Test fun `Sett opp testdatabasen riktig`(){ - feilmeldingRepository.lagre("Hællæ", "skjera bagera") + feilmeldingRepository.lagre("Hællæ", "skjera bagera", LocalDateTime.of(2000,1,1,8,0)) transaction { assertEquals(1, FeilmeldingTable.selectAll().map { it }.size) } } + + @Test + fun `Lagrer feilmelding i databasen`() { + feilmeldingRepository.lagre("test", "testesen", LocalDateTime.of(2000,1,1,8,0)) + transaction { + val actual = FeilmeldingTable.selectAll().single() + assertEquals("test", actual[FeilmeldingTable.tittel]) + assertEquals("testesen", actual[FeilmeldingTable.beskrivelse]) + assertEquals(LocalDateTime.of(2023, 1, 1, 8, 0), actual[FeilmeldingTable.dato]) + } + } + } \ No newline at end of file