@@ -14,7 +14,6 @@ import io.ktor.server.routing.Route
14
14
import io.ktor.server.routing.get
15
15
import io.ktor.server.routing.post
16
16
import io.ktor.server.routing.route
17
- import io.ktor.util.pipeline.PipelineContext
18
17
import io.prometheus.client.Counter
19
18
import kotlinx.coroutines.Dispatchers
20
19
import kotlinx.coroutines.withContext
@@ -60,7 +59,7 @@ fun Route.uklassifisertInntekt(
60
59
route(" /uklassifisert/{aktørId}/{kontekstType}/{kontekstId}/{beregningsDato}" ) {
61
60
get {
62
61
withContext(Dispatchers .IO ) {
63
- withInntektRequest(" GET /uklassifisert/" ) {
62
+ call. withInntektRequest(" GET /uklassifisert/" ) {
64
63
val person = personOppslag.hentPerson(this .aktørId)
65
64
inntektStore.getInntektId(
66
65
Inntektparametre (
@@ -82,7 +81,7 @@ fun Route.uklassifisertInntekt(
82
81
}
83
82
post {
84
83
withContext(Dispatchers .IO ) {
85
- withInntektRequest(" POST /uklassifisert/" ) {
84
+ call. withInntektRequest(" POST /uklassifisert/" ) {
86
85
val person = personOppslag.hentPerson(this .aktørId)
87
86
val guiInntekt = call.receive<GUIInntekt >()
88
87
mapToStoredInntekt(guiInntekt).let {
@@ -99,7 +98,7 @@ fun Route.uklassifisertInntekt(
99
98
manueltRedigert =
100
99
ManueltRedigert .from(
101
100
guiInntekt.redigertAvSaksbehandler,
102
- getSubject(),
101
+ call. getSubject(),
103
102
),
104
103
),
105
104
)
@@ -124,7 +123,7 @@ fun Route.uklassifisertInntekt(
124
123
get {
125
124
val callId = call.callId
126
125
withContext(Dispatchers .IO ) {
127
- withInntektRequest(" GET /uklassifisert/uncached/" ) {
126
+ call. withInntektRequest(" GET /uklassifisert/uncached/" ) {
128
127
val person = personOppslag.hentPerson(this .aktørId)
129
128
val opptjeningsperiode = Opptjeningsperiode (this .beregningsDato)
130
129
toInntektskomponentRequest(person, opptjeningsperiode).let {
@@ -146,7 +145,7 @@ fun Route.uklassifisertInntekt(
146
145
147
146
post {
148
147
withContext(Dispatchers .IO ) {
149
- withInntektRequest(" POST /uklassifisert/uncached/" ) {
148
+ call. withInntektRequest(" POST /uklassifisert/uncached/" ) {
150
149
val guiInntekt = call.receive<GUIInntekt >()
151
150
val person = personOppslag.hentPerson(this .aktørId)
152
151
mapToDetachedInntekt(guiInntekt).let {
@@ -163,7 +162,7 @@ fun Route.uklassifisertInntekt(
163
162
manueltRedigert =
164
163
ManueltRedigert .from(
165
164
guiInntekt.redigertAvSaksbehandler,
166
- getSubject(),
165
+ call. getSubject(),
167
166
),
168
167
),
169
168
)
@@ -193,27 +192,27 @@ fun Route.uklassifisertInntekt(
193
192
}
194
193
}
195
194
196
- private fun PipelineContext < Unit , ApplicationCall > .getSubject (): String {
195
+ private fun ApplicationCall.getSubject (): String {
197
196
return runCatching {
198
- call .authentication.principal<JWTPrincipal >()?.payload?.subject
197
+ this .authentication.principal<JWTPrincipal >()?.payload?.subject
199
198
? : throw JWTDecodeException (" Unable to get subject from JWT" )
200
199
}.getOrElse {
201
200
logger.error(it) { " Unable to get subject" }
202
201
return @getOrElse " UNKNOWN"
203
202
}
204
203
}
205
204
206
- private inline fun PipelineContext < Unit , ApplicationCall > .withInntektRequest (
205
+ private inline fun ApplicationCall.withInntektRequest (
207
206
route : String ,
208
207
block : InntektRequest .() -> Unit ,
209
208
) {
210
209
val inntektRequest =
211
210
runCatching {
212
211
InntektRequest (
213
- aktørId = call .parameters[" aktørId" ]!! ,
214
- kontekstId = call .parameters[" kontekstId" ]!! ,
215
- kontekstType = call .parameters[" kontekstType" ]!! ,
216
- beregningsDato = LocalDate .parse(call .parameters[" beregningsDato" ]!! ),
212
+ aktørId = this .parameters[" aktørId" ]!! ,
213
+ kontekstId = this .parameters[" kontekstId" ]!! ,
214
+ kontekstType = this .parameters[" kontekstType" ]!! ,
215
+ beregningsDato = LocalDate .parse(this .parameters[" beregningsDato" ]!! ),
217
216
)
218
217
}.getOrElse { t -> throw IllegalArgumentException (" Failed to parse parameters" , t) }
219
218
0 commit comments