@@ -62,7 +62,7 @@ fun Route.uklassifisertInntekt(
62
62
route(" /uklassifisert/{aktørId}/{kontekstType}/{kontekstId}/{beregningsDato}" ) {
63
63
get {
64
64
withContext(Dispatchers .IO ) {
65
- parseUrlPathParameters(). run {
65
+ withInntektRequest {
66
66
inntektStore.getInntektId(
67
67
Inntektparametre (
68
68
aktørId = this .aktørId,
@@ -83,7 +83,7 @@ fun Route.uklassifisertInntekt(
83
83
}
84
84
post {
85
85
withContext(Dispatchers .IO ) {
86
- parseUrlPathParameters(). run {
86
+ withInntektRequest {
87
87
val guiInntekt = call.receive<GUIInntekt >()
88
88
mapToStoredInntekt(guiInntekt).let {
89
89
inntektStore.storeInntekt(
@@ -121,7 +121,7 @@ fun Route.uklassifisertInntekt(
121
121
get {
122
122
val callId = call.callId
123
123
withContext(Dispatchers .IO ) {
124
- parseUrlPathParameters(). run {
124
+ withInntektRequest {
125
125
withLoggingContext(
126
126
" route" to " /uklassifisert/uncached" ,
127
127
" aktørId" to aktørId,
@@ -151,7 +151,7 @@ fun Route.uklassifisertInntekt(
151
151
152
152
post {
153
153
withContext(Dispatchers .IO ) {
154
- parseUrlPathParameters(). run {
154
+ withInntektRequest {
155
155
val guiInntekt = call.receive<GUIInntekt >()
156
156
mapToDetachedInntekt(guiInntekt).let {
157
157
inntektStore.storeInntekt(
@@ -209,14 +209,23 @@ private fun PipelineContext<Unit, ApplicationCall>.getSubject(): String {
209
209
}
210
210
}
211
211
212
- private fun PipelineContext <Unit , ApplicationCall >.parseUrlPathParameters (): InntektRequest = runCatching {
213
- InntektRequest (
214
- aktørId = call.parameters[" aktørId" ]!! ,
215
- kontekstId = call.parameters[" kontekstId" ]!! ,
216
- kontekstType = call.parameters[" kontekstType" ]!! ,
217
- beregningsDato = LocalDate .parse(call.parameters[" beregningsDato" ]!! )
218
- )
219
- }.getOrElse { t -> throw IllegalArgumentException (" Failed to parse parameters" , t) }
212
+ private inline fun PipelineContext <Unit , ApplicationCall >.withInntektRequest (block : InntektRequest .() -> Unit ) {
213
+ val inntektRequest = runCatching {
214
+ InntektRequest (
215
+ aktørId = call.parameters[" aktørId" ]!! ,
216
+ kontekstId = call.parameters[" kontekstId" ]!! ,
217
+ kontekstType = call.parameters[" kontekstType" ]!! ,
218
+ beregningsDato = LocalDate .parse(call.parameters[" beregningsDato" ]!! )
219
+ )
220
+ }.getOrElse { t -> throw IllegalArgumentException (" Failed to parse parameters" , t) }
221
+
222
+ withLoggingContext(
223
+ " kontekstId" to inntektRequest.kontekstId,
224
+ " kontekstType" to inntektRequest.kontekstType
225
+ ) {
226
+ block(inntektRequest)
227
+ }
228
+ }
220
229
221
230
data class InntektRequest (
222
231
val aktørId : String ,
0 commit comments