Skip to content

Commit

Permalink
Legger til forenklet validatekall. På sikt ønsker vi å returnere spes…
Browse files Browse the repository at this point in the history
…ifikke feilkoder per felt. (#1676)
  • Loading branch information
stiangre authored Nov 21, 2023
1 parent d004825 commit c701728
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ import io.ktor.server.locations.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.Route
import no.nav.k9.los.integrasjon.abac.IPepClient
import no.nav.k9.los.integrasjon.rest.RequestContextService
import no.nav.k9.los.integrasjon.rest.idToken
import no.nav.k9.los.nyoppgavestyring.query.db.OppgaveQueryRepository
import no.nav.k9.los.nyoppgavestyring.query.dto.query.OppgaveQuery
import no.nav.k9.los.tjenester.avdelingsleder.nokkeltall.tilCsv
import org.koin.java.KoinJavaComponent
import org.koin.ktor.ext.inject
import java.util.*

fun Route.OppgaveQueryApis() {
val requestContextService by inject<RequestContextService>()
val oppgaveQueryRepository by inject<OppgaveQueryRepository>()
val oppgaveQueryService by inject<OppgaveQueryService>()
val pepClient by KoinJavaComponent.inject<IPepClient>(IPepClient::class.java)

@Location("/query")
class queryOppgave
Expand All @@ -30,6 +32,19 @@ fun Route.OppgaveQueryApis() {
}
}

@Location("/validate")
class validateOppgave

post { _: validateOppgave ->
val oppgaveQuery = call.receive<OppgaveQuery>()
requestContextService.withRequestContext(call) {
if (!pepClient.erOppgaveStyrer()) {
call.respond(HttpStatusCode.Forbidden);
}
call.respond(oppgaveQueryService.validate(oppgaveQuery))
}
}

@Location("/queryToFile")
class queryOppgaveToFile

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import no.nav.k9.los.nyoppgavestyring.visningoguttrekk.Oppgave
import no.nav.k9.los.nyoppgavestyring.visningoguttrekk.OppgaveRepository
import no.nav.k9.los.tjenester.saksbehandler.IIdToken
import org.koin.java.KoinJavaComponent.inject
import java.lang.RuntimeException
import javax.sql.DataSource

class OppgaveQueryService() {
Expand Down Expand Up @@ -134,4 +135,14 @@ class OppgaveQueryService() {
it.transaction { tx -> queryToFile(tx, oppgaveQuery, idToken) }
}
}

fun validate(oppgaveQuery: OppgaveQuery): Boolean {
try {
queryForOppgaveId(oppgaveQuery)
} catch (e: RuntimeException) {
return false
}

return true
}
}

0 comments on commit c701728

Please sign in to comment.