Skip to content

Commit

Permalink
endre filters til å være extensions på RoutingContext
Browse files Browse the repository at this point in the history
  • Loading branch information
sondrele committed Oct 28, 2024
1 parent fc751ae commit 955055d
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package no.nav.mulighetsrommet.api.okonomi.refusjon

import arrow.core.getOrElse
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.plugins.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.util.*
import io.ktor.util.pipeline.*
import kotlinx.serialization.Serializable
import no.nav.mulighetsrommet.api.okonomi.models.DeltakelsePeriode
import no.nav.mulighetsrommet.api.okonomi.models.RefusjonKravBeregningAft
Expand Down Expand Up @@ -44,7 +42,7 @@ fun Route.arrangorflateRoutes() {
val refusjonskrav: RefusjonskravRepository by inject()
val deltakerRepository: DeltakerRepository by inject()

suspend fun <T : Any> PipelineContext<T, ApplicationCall>.arrangorerMedTilgang(): List<UUID> {
suspend fun RoutingContext.arrangorerMedTilgang(): List<UUID> {
return call.principal<ArrangorflatePrincipal>()
?.organisasjonsnummer
?.map {
Expand All @@ -57,7 +55,7 @@ fun Route.arrangorflateRoutes() {
?: throw StatusException(HttpStatusCode.Unauthorized)
}

fun <T : Any> PipelineContext<T, ApplicationCall>.requireTilgangHosArrangor(organisasjonsnummer: Organisasjonsnummer) {
fun RoutingContext.requireTilgangHosArrangor(organisasjonsnummer: Organisasjonsnummer) {
call.principal<ArrangorflatePrincipal>()
?.organisasjonsnummer
?.find { it == organisasjonsnummer }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package no.nav.mulighetsrommet.api.parameters

import io.ktor.server.application.*
import io.ktor.util.pipeline.*
import io.ktor.server.routing.*
import no.nav.mulighetsrommet.database.utils.Pagination

const val FIRST_PAGE = 1

const val DEFAULT_PAGE_SIZE = 50

fun <T : Any> PipelineContext<T, ApplicationCall>.getPaginationParams(): Pagination {
fun RoutingContext.getPaginationParams(): Pagination {
return Pagination.of(
page = call.parameters["page"]?.toIntOrNull() ?: FIRST_PAGE,
size = call.parameters["size"]?.toIntOrNull() ?: DEFAULT_PAGE_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fun Route.authenticate(
* Gets a NAVident from the underlying [JWTPrincipal], or throws a [StatusException]
* if the claim is not available.
*/
fun <T : Any> PipelineContext<T, ApplicationCall>.getNavIdent(): NavIdent {
fun RoutingContext.getNavIdent(): NavIdent {
return call.principal<JWTPrincipal>()?.get("NAVident")?.let { NavIdent(it) } ?: throw StatusException(
HttpStatusCode.Forbidden,
"NAVident mangler i JWTPrincipal",
Expand All @@ -66,7 +66,7 @@ fun <T : Any> PipelineContext<T, ApplicationCall>.getNavIdent(): NavIdent {
* Gets a NavAnsattAzureId from the underlying [JWTPrincipal], or throws a [StatusException]
* if the claim is not available.
*/
fun <T : Any> PipelineContext<T, ApplicationCall>.getNavAnsattAzureId(): UUID {
fun RoutingContext.getNavAnsattAzureId(): UUID {
return call.principal<JWTPrincipal>()?.get("oid")?.let { UUID.fromString(it) } ?: throw StatusException(
HttpStatusCode.Forbidden,
"NavAnsattAzureId mangler i JWTPrincipal",
Expand All @@ -77,7 +77,7 @@ fun <T : Any> PipelineContext<T, ApplicationCall>.getNavAnsattAzureId(): UUID {
* Gets a pid from the underlying [JWTPrincipal], or throws a [StatusException]
* if the claim is not available.
*/
fun <T : Any> PipelineContext<T, ApplicationCall>.getPid(): NorskIdent {
fun RoutingContext.getPid(): NorskIdent {
return call.principal<JWTPrincipal>()?.get("pid")?.let { NorskIdent(it) } ?: throw StatusException(
HttpStatusCode.Forbidden,
"pid mangler i JWTPrincipal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ enum class ApentForInnsok {
APENT_ELLER_STENGT,
}

fun <T : Any> PipelineContext<T, ApplicationCall>.getArbeidsmarkedstiltakFilter(): ArbeidsmarkedstiltakFilter {
fun RoutingContext.getArbeidsmarkedstiltakFilter(): ArbeidsmarkedstiltakFilter {
val queryParameters = call.request.queryParameters

val enheter = queryParameters.getAll("enheter")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ data class ArrangorFilter(
val sortering: String? = null,
)

fun <T : Any> PipelineContext<T, ApplicationCall>.getArrangorFilter(): ArrangorFilter {
fun RoutingContext.getArrangorFilter(): ArrangorFilter {
val til = call.request.queryParameters["til"]
val sok = call.request.queryParameters["sok"]
val sortering = call.request.queryParameters["sortering"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.nav.mulighetsrommet.api.routes.v1

import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
Expand Down Expand Up @@ -241,7 +240,7 @@ fun Route.avtaleRoutes() {
}
}

fun <T : Any> PipelineContext<T, ApplicationCall>.getAvtaleFilter(): AvtaleFilter {
fun RoutingContext.getAvtaleFilter(): AvtaleFilter {
val tiltakstypeIder = call.parameters.getAll("tiltakstyper")?.map { it.toUUID() } ?: emptyList()
val search = call.request.queryParameters["search"]
val statuser = call.parameters.getAll("statuser")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.nav.mulighetsrommet.api.routes.v1

import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.util.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package no.nav.mulighetsrommet.api.routes.v1

import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.util.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.util.*
import io.ktor.util.pipeline.*
import no.nav.mulighetsrommet.api.domain.dbo.NavAnsattRolle
import no.nav.mulighetsrommet.api.plugins.getNavAnsattAzureId
import no.nav.mulighetsrommet.api.services.NavAnsattService
Expand Down Expand Up @@ -38,7 +37,7 @@ fun Route.navAnsattRoutes() {
}
}

fun <T : Any> PipelineContext<T, ApplicationCall>.getNavAnsattFilter(): NavAnsattFilter {
fun RoutingContext.getNavAnsattFilter(): NavAnsattFilter {
val azureIder = call.parameters.getAll("roller")
?.map { NavAnsattRolle.valueOf(it) }
?: emptyList()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package no.nav.mulighetsrommet.api.routes.v1

import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.util.*
import io.ktor.util.pipeline.*
import no.nav.mulighetsrommet.api.clients.norg2.Norg2Type
import no.nav.mulighetsrommet.api.domain.dbo.NavEnhetStatus
import no.nav.mulighetsrommet.api.services.EnhetFilter
Expand Down Expand Up @@ -38,7 +36,7 @@ fun Route.navEnhetRoutes() {
}
}

fun <T : Any> PipelineContext<T, ApplicationCall>.getEnhetFilter(): EnhetFilter {
fun RoutingContext.getEnhetFilter(): EnhetFilter {
val statuser = call.parameters.getAll("statuser")
?.map { NavEnhetStatus.valueOf(it) }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.nav.mulighetsrommet.api.routes.v1

import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
Expand Down Expand Up @@ -61,7 +60,7 @@ data class SetNotificationStatusRequest(
)
}

fun <T : Any> PipelineContext<T, ApplicationCall>.getNotificationFilter(): NotificationFilter {
fun RoutingContext.getNotificationFilter(): NotificationFilter {
val status = call.request.queryParameters["status"]
return NotificationFilter(
status = status?.let { NotificationStatus.valueOf(it) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ data class AdminTiltaksgjennomforingFilter(
val publisert: Boolean? = null,
)

fun <T : Any> PipelineContext<T, ApplicationCall>.getAdminTiltaksgjennomforingsFilter(): AdminTiltaksgjennomforingFilter {
fun RoutingContext.getAdminTiltaksgjennomforingsFilter(): AdminTiltaksgjennomforingFilter {
val search = call.request.queryParameters["search"]
val navEnheter = call.parameters.getAll("navEnheter") ?: emptyList()
val tiltakstypeIder = call.parameters.getAll("tiltakstyper")?.map { UUID.fromString(it) } ?: emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ data class TiltakstypeFilter(
val sortering: String? = null,
)

fun <T : Any> PipelineContext<T, ApplicationCall>.getTiltakstypeFilter(): TiltakstypeFilter {
fun RoutingContext.getTiltakstypeFilter(): TiltakstypeFilter {
val sortering = call.request.queryParameters["sort"]
return TiltakstypeFilter(
sortering = sortering,
Expand Down

0 comments on commit 955055d

Please sign in to comment.