Skip to content

Commit

Permalink
Oppdaterte feilhåndtering til å stemme med RCF, endret bekreftelse-ap…
Browse files Browse the repository at this point in the history
…i til å benytte generert API modell
  • Loading branch information
naviktthomas committed Dec 5, 2024
1 parent fc772a6 commit 5d785ee
Show file tree
Hide file tree
Showing 39 changed files with 279 additions and 183 deletions.
45 changes: 43 additions & 2 deletions apps/bekreftelse-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
id("org.openapi.generator")
Expand Down Expand Up @@ -90,6 +88,22 @@ application {
mainClass.set("no.nav.paw.bekreftelse.api.ApplicationKt")
}

sourceSets {
main {
kotlin {
srcDir("${layout.buildDirectory.get()}/generated/src/main/kotlin")
}
}
}

tasks.named("compileKotlin") {
dependsOn("openApiValidate", "openApiGenerate")
}

tasks.named("compileTestKotlin") {
dependsOn("openApiValidate", "openApiGenerate")
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
Expand All @@ -102,6 +116,33 @@ tasks.withType(Jar::class) {
}
}

val openApiDocFile = "${layout.projectDirectory}/src/main/resources/openapi/documentation.yaml"

openApiValidate {
inputSpec = openApiDocFile
}

openApiGenerate {
generatorName = "kotlin"
inputSpec = openApiDocFile
outputDir = "${layout.buildDirectory.get()}/generated/"
packageName = "no.nav.paw.bekreftelse.api"
configOptions = mapOf(
"serializationLibrary" to "jackson",
"enumPropertyNaming" to "original",
)
globalProperties = mapOf(
"apis" to "none",
"models" to ""
)
typeMappings = mapOf(
"DateTime" to "Instant"
)
importMappings = mapOf(
"Instant" to "java.time.Instant"
)
}

jib {
from.image = "$baseImage:$jvmMajorVersion"
to.image = "${image ?: project.name}:${project.version}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package no.nav.paw.bekreftelse.api.context

import no.nav.paw.bekreftelse.api.model.BekreftelserTable.registerColumn
import no.nav.paw.bekreftelse.api.models.BekreftelserTable.registerColumn
import org.jetbrains.exposed.sql.IColumnType
import org.postgresql.util.PGobject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package no.nav.paw.bekreftelse.api.exception

import io.ktor.http.HttpStatusCode
import no.nav.paw.error.exception.ServerResponseException
import no.nav.paw.error.model.ErrorType

class DataIkkeFunnetForIdException(message: String) :
ServerResponseException(HttpStatusCode.BadRequest, "PAW_DATA_IKKE_FUNNET_FOR_ID", message)
ServerResponseException(
HttpStatusCode.BadRequest,
ErrorType.domain("bekreftelse").error("ikke-funnet-for-id").build(),
message
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package no.nav.paw.bekreftelse.api.exception

import io.ktor.http.HttpStatusCode
import no.nav.paw.error.exception.ServerResponseException
import no.nav.paw.error.model.ErrorType

class DataTilhoererIkkeBrukerException(message: String) :
ServerResponseException(HttpStatusCode.BadRequest, "PAW_DATA_TILHOERER_IKKE_BRUKER", message)
ServerResponseException(
HttpStatusCode.BadRequest,
ErrorType.domain("bekreftelse").error("tilhører-ikke-bruker").build(),
message
)

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.paw.bekreftelse.api.model
package no.nav.paw.bekreftelse.api.models

import no.nav.paw.bekreftelse.internehendelser.BekreftelseTilgjengelig
import org.jetbrains.exposed.sql.ResultRow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.paw.bekreftelse.api.model
package no.nav.paw.bekreftelse.api.models

import no.nav.paw.bekreftelse.api.utils.JsonbSerde
import org.jetbrains.exposed.sql.Table
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.paw.bekreftelse.api.model
package no.nav.paw.bekreftelse.api.models

import no.nav.paw.bekreftelse.internehendelser.BekreftelseTilgjengelig
import no.nav.paw.bekreftelse.melding.v1.Bekreftelse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package no.nav.paw.bekreftelse.api.model
package no.nav.paw.bekreftelse.api.models

typealias TilgjengeligBekreftelserResponse = List<TilgjengeligBekreftelse>
typealias TilgjengeligBekreftelserResponse = List<TilgjengeligBekreftelse>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SluttbrukerAccessPolicy(
is Sluttbruker -> {
// TODO Håndtere verge
if (identitetsnummer != null && identitetsnummer != bruker.ident) {
return Deny("Sluttbruke kan ikke hente data for annen bruker")
return Deny("Sluttbruker har ikke tilgang til data for annen bruker")
}
return Permit("Sluttbruker har tilgang")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package no.nav.paw.bekreftelse.api.repository

import no.nav.paw.bekreftelse.api.model.BekreftelseRow
import no.nav.paw.bekreftelse.api.model.BekreftelserTable
import no.nav.paw.bekreftelse.api.model.asBekreftelseRow
import no.nav.paw.bekreftelse.api.models.BekreftelseRow
import no.nav.paw.bekreftelse.api.models.BekreftelserTable
import no.nav.paw.bekreftelse.api.models.asBekreftelseRow
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.deleteWhere
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import io.ktor.server.routing.get
import io.ktor.server.routing.post
import io.ktor.server.routing.route
import no.nav.paw.bekreftelse.api.context.ApplicationContext
import no.nav.paw.bekreftelse.api.model.MottaBekreftelseRequest
import no.nav.paw.bekreftelse.api.model.TilgjengeligeBekreftelserRequest
import no.nav.paw.bekreftelse.api.models.MottaBekreftelseRequest
import no.nav.paw.bekreftelse.api.models.TilgjengeligeBekreftelserRequest
import no.nav.paw.bekreftelse.api.utils.hentSluttbrukerIdentitet
import no.nav.paw.security.authentication.model.asIdentitetsnummer
import no.nav.paw.security.authentication.token.AzureAd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import io.ktor.server.plugins.swagger.swaggerUI
import io.ktor.server.routing.Route

fun Route.swaggerRoutes() {
swaggerUI(path = "docs", swaggerFile = "openapi/api.yaml")
swaggerUI(path = "docs", swaggerFile = "openapi/documentation.yaml")
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import no.nav.paw.bekreftelse.api.config.ApplicationConfig
import no.nav.paw.bekreftelse.api.config.ServerConfig
import no.nav.paw.bekreftelse.api.exception.DataIkkeFunnetForIdException
import no.nav.paw.bekreftelse.api.exception.DataTilhoererIkkeBrukerException
import no.nav.paw.bekreftelse.api.model.MottaBekreftelseRequest
import no.nav.paw.bekreftelse.api.model.TilgjengeligBekreftelserResponse
import no.nav.paw.bekreftelse.api.model.asBekreftelse
import no.nav.paw.bekreftelse.api.model.asBekreftelseBruker
import no.nav.paw.bekreftelse.api.model.asBekreftelseRow
import no.nav.paw.bekreftelse.api.model.asTilgjengeligBekreftelse
import no.nav.paw.bekreftelse.api.models.MottaBekreftelseRequest
import no.nav.paw.bekreftelse.api.models.TilgjengeligBekreftelserResponse
import no.nav.paw.bekreftelse.api.models.asBekreftelse
import no.nav.paw.bekreftelse.api.models.asBekreftelseBruker
import no.nav.paw.bekreftelse.api.models.asBekreftelseRow
import no.nav.paw.bekreftelse.api.models.asTilgjengeligBekreftelse
import no.nav.paw.bekreftelse.api.producer.BekreftelseKafkaProducer
import no.nav.paw.bekreftelse.api.repository.BekreftelseRepository
import no.nav.paw.bekreftelse.api.utils.buildLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ servers:
paths:
/api/v1/tilgjengelige-bekreftelser:
get:
operationId: getTilgjengeligBekreftelser
description: "Endepunkt for å hende tilgjengelige bekreftelser for innlogget sluttbruker"
parameters:
- name: "traceparent"
Expand All @@ -34,6 +35,7 @@ paths:
schema:
$ref: "#/components/schemas/ProblemDetails"
post:
operationId: postTilgjengeligBekreftelser
description: "Endepunkt for å hende tilgjengelige bekreftelser for en arbeidssøker"
parameters:
- name: "traceparent"
Expand All @@ -56,6 +58,12 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/TilgjengeligBekreftelserResponse"
"400":
description: "Bad Request"
content:
application/json:
schema:
$ref: "#/components/schemas/ProblemDetails"
"403":
description: "Forbidden"
content:
Expand All @@ -64,6 +72,7 @@ paths:
$ref: "#/components/schemas/ProblemDetails"
/api/v1/bekreftelse:
post:
operationId: postMottaBekreftelse
description: "Endepunkt for å registrere en bekreftelse for en arbeidssøker"
parameters:
- name: "traceparent"
Expand All @@ -77,11 +86,17 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/BekreftelseRequest"
$ref: "#/components/schemas/MottaBekreftelseRequest"
required: true
responses:
"200":
description: "OK"
"400":
description: "Bad Request"
content:
application/json:
schema:
$ref: "#/components/schemas/ProblemDetails"
"403":
description: "Forbidden"
content:
Expand All @@ -90,6 +105,7 @@ paths:
$ref: "#/components/schemas/ProblemDetails"
/internal/isAlive:
get:
operationId: getIsAlive
description: "Service is alive probe"
responses:
"503":
Expand All @@ -106,6 +122,7 @@ paths:
$ref: "#/components/schemas/HealthStatus"
/internal/isReady:
get:
operationId: getIsReady
description: "Service is ready probe"
responses:
"503":
Expand All @@ -122,6 +139,7 @@ paths:
$ref: "#/components/schemas/HealthStatus"
/internal/metrics:
get:
operationId: getMetrics
description: "Prometheus metrics"
responses:
"200":
Expand All @@ -137,8 +155,6 @@ components:
properties:
identitetsnummer:
type: "string"
required:
- "identitetsnummer"
example:
identitetsnummer: "01017012345"
TilgjengeligBekreftelserResponse:
Expand Down Expand Up @@ -170,7 +186,7 @@ components:
bekreftelseId: "ec6b5a10-b67c-42c1-b6e7-a642c36bd78e"
gjelderFra: "2020-01-01T11:22:33.444Z"
gjelderTil: "2020-02-02T11:22:33.444Z"
BekreftelseRequest:
MottaBekreftelseRequest:
type: "object"
properties:
identitetsnummer:
Expand All @@ -183,7 +199,6 @@ components:
vilFortsetteSomArbeidssoeker:
type: "boolean"
required:
- "identitetsnummer"
- "bekreftelseId"
- "harJobbetIDennePerioden"
- "vilFortsetteSomArbeidssoeker"
Expand All @@ -195,31 +210,33 @@ components:
ProblemDetails:
type: object
properties:
type:
id:
type: "string"
code:
format: "uuid"
type:
type: "string"
format: "uri"
status:
type: "integer"
title:
type: "string"
status:
type: "number"
detail:
type: "string"
instance:
type: "string"
required:
- id
- type
- code
- title
- status
- title
- detail
- instance
example:
type: "about:blank"
code: "BRUKER_HAR_IKKE_TILGANG"
title: "Forbidden"
id: "3cd944fb-6187-41a8-91b2-b172f2baf890"
type: "urn:paw:sikkerhet:bruker-har-ikke-tilgang"
status: 403
detail: "Access denied"
title: "Forbidden"
detail: "Bruker har ikke tilgang"
instance: "/api/endpoint"
HealthStatus:
type: "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.ktor.server.application.hooks.MonitoringEvent
import io.ktor.server.application.install
import io.ktor.server.application.log
import io.ktor.util.KtorDsl
import no.nav.paw.bekreftelse.api.model.BekreftelseRow
import no.nav.paw.bekreftelse.api.models.BekreftelseRow
import no.nav.paw.bekreftelse.api.plugins.custom.FlywayMigrationCompleted
import no.nav.paw.bekreftelse.api.repository.BekreftelseRepository
import no.nav.paw.bekreftelse.api.test.TestData
Expand Down
Loading

0 comments on commit 5d785ee

Please sign in to comment.