-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ta bruk api i etterlatte-api og rename klasser
- Loading branch information
Showing
13 changed files
with
144 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
apps/etterlatte-api/src/main/kotlin/no/nav/etterlatte/vedtak/VedtakRoute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package no.nav.etterlatte.vedtak | ||
|
||
import com.typesafe.config.Config | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.server.application.call | ||
import io.ktor.server.request.receive | ||
import io.ktor.server.response.respond | ||
import io.ktor.server.response.respondNullable | ||
import io.ktor.server.routing.Route | ||
import io.ktor.server.routing.post | ||
import io.ktor.server.routing.route | ||
import no.nav.etterlatte.libs.common.vedtak.VedtakForPersonRequest | ||
|
||
fun Route.vedtakRoute( | ||
vedtaksvurderingKlient: VedtaksvurderingKlient, | ||
config: Config, | ||
) { | ||
// Tiltenkt for eksternt for etterlatte men internt i Nav. Initelt gjelder dette EESSI. | ||
route("api/vedtak/personident") { | ||
post { | ||
// TODO mer autentisering? | ||
try { | ||
val request = call.receive<VedtakForPersonRequest>() | ||
val vedtak = vedtaksvurderingKlient.hentVedtak(request) | ||
call.respond(vedtak) | ||
} catch (e: IllegalArgumentException) { | ||
call.respondNullable(HttpStatusCode.BadRequest, e.message) | ||
} | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
apps/etterlatte-api/src/main/kotlin/no/nav/etterlatte/vedtak/VedtaksvurderingKlient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package no.nav.etterlatte.vedtak | ||
|
||
import com.typesafe.config.Config | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.plugins.ClientRequestException | ||
import io.ktor.client.request.post | ||
import io.ktor.client.request.setBody | ||
import io.ktor.client.request.url | ||
import io.ktor.http.HttpStatusCode | ||
import no.nav.etterlatte.libs.common.logging.sikkerlogger | ||
import no.nav.etterlatte.libs.common.vedtak.VedtakForEksterntDto | ||
import no.nav.etterlatte.libs.common.vedtak.VedtakForPersonRequest | ||
import no.nav.etterlatte.samordning.vedtak.VedtakvurderingIkkeFunnetException | ||
import no.nav.etterlatte.samordning.vedtak.VedtakvurderingManglendeTilgangException | ||
import no.nav.etterlatte.samordning.vedtak.VedtakvurderingUgyldigForesporselException | ||
import org.slf4j.LoggerFactory | ||
|
||
class VedtaksvurderingKlient( | ||
config: Config, | ||
private val httpClient: HttpClient, | ||
) { | ||
private val logger = LoggerFactory.getLogger(VedtaksvurderingKlient::class.java) | ||
|
||
private val vedtaksvurderingUrl = "${config.getString("vedtak.url")}/api/vedtak/for/eksternt" | ||
|
||
suspend fun hentVedtak(request: VedtakForPersonRequest): VedtakForEksterntDto { | ||
sikkerlogger().info("Henter vedtak med fnr=${request.fnr}") | ||
|
||
return try { | ||
httpClient | ||
.post { | ||
url(vedtaksvurderingUrl) | ||
setBody(request) | ||
}.body() | ||
} catch (e: ClientRequestException) { | ||
logger.error("Det oppstod feil i kall til vedtak API", e) | ||
when (e.response.status) { | ||
HttpStatusCode.Unauthorized -> throw VedtakvurderingManglendeTilgangException("Vedtak: Ikke tilgang") | ||
HttpStatusCode.BadRequest -> throw VedtakvurderingUgyldigForesporselException("Vedtak: Ugyldig forespørsel") | ||
HttpStatusCode.NotFound -> throw VedtakvurderingIkkeFunnetException("Vedtak: Ressurs ikke funnet") | ||
else -> throw e | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 11 additions & 14 deletions
25
...edtaksvurdering/OffentligVedtakService.kt → ...taksvurdering/VedtakForEksterntService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters