🚧 Søkefelt henter array med feilmeldinger fra backend
WIP: arrayet er tomt fordi søk ikke fungerer Co-authored-by: Sindre Kjelsrud <sindre.kjelsrud@nav.no>
This commit is contained in:
parent
76c34abd2b
commit
8134cfc239
4 changed files with 37 additions and 5 deletions
|
@ -8,12 +8,18 @@ class Sokemotor {
|
|||
private val feilmeldingRepository = FeilmeldingRepository()
|
||||
|
||||
fun sok(s: String): List<Feilmelding> {
|
||||
|
||||
val feilmeldinger = feilmeldingRepository.hentAlleFeilmeldinger()
|
||||
val resultat = ArrayList<Feilmelding>()
|
||||
|
||||
val processed = s.lowercase()
|
||||
|
||||
for (i in feilmeldinger) {
|
||||
if (i.tittel.equals(s) or i.beskrivelse.equals(s)) {
|
||||
if (i.tittel.lowercase().contains(processed) or i.beskrivelse.lowercase().contains(processed) or processed.equals("")) {
|
||||
println(i.toString() + " matcher" + processed)
|
||||
resultat.add(i)
|
||||
}else{
|
||||
println(i.toString() + " matcher ikke")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,11 +14,13 @@ import io.ktor.server.request.*
|
|||
import no.nav.helse.sprik.Test
|
||||
import no.nav.helse.sprik.db.FeilmeldingRepository
|
||||
import no.nav.helse.sprik.modell.Feilmelding
|
||||
import no.nav.helse.sprik.modell.Sokemotor
|
||||
import java.time.LocalDateTime
|
||||
|
||||
fun configureRouting(): ApplicationEngine = embeddedServer(CIO, applicationEngineEnvironment {
|
||||
//Repositories for handlinger mot database:
|
||||
val feilmeldingRepository = FeilmeldingRepository()
|
||||
val sokemotor = Sokemotor()
|
||||
|
||||
module {
|
||||
install(CORS) {
|
||||
|
@ -57,6 +59,10 @@ fun configureRouting(): ApplicationEngine = embeddedServer(CIO, applicationEngin
|
|||
val testMelding = feilmeldingRepository.hentAlleFeilmeldinger()
|
||||
call.respond(status = HttpStatusCode.Created, message = testMelding)
|
||||
}
|
||||
post("/api/hentsok"){
|
||||
val sokestreng = call.receive<String>()
|
||||
call.respond(status = HttpStatusCode.Created, message = sokestreng + ": " + sokemotor.sok(sokestreng))
|
||||
}
|
||||
}
|
||||
}
|
||||
connector {
|
||||
|
|
Reference in a new issue