Skip to content

Commit

Permalink
Merge pull request #700 from navikt/graphql-underoppfolging
Browse files Browse the repository at this point in the history
Legg til erUnderOppfolging på graphql endepunkt
  • Loading branch information
tu55eladd authored Jan 21, 2025
2 parents 73a1308 + 5732109 commit e05ebd1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package no.nav.veilarboppfolging.controller
import no.nav.common.client.aktoroppslag.AktorOppslagClient
import no.nav.common.client.norg2.Norg2Client
import no.nav.common.types.identer.Fnr
import no.nav.veilarboppfolging.repository.OppfolgingsStatusRepository
import no.nav.veilarboppfolging.service.AuthService
import no.nav.veilarboppfolging.service.OppfolgingsEnhetService
import org.springframework.graphql.data.method.annotation.Argument
Expand All @@ -27,9 +28,14 @@ enum class KildeDto {
ARENA
}

data class OppfolgingDto(
val erUnderOppfolging: Boolean,
)

@Controller
class GraphqlController(
private val oppfolgingsEnhetService: OppfolgingsEnhetService,
private val oppfolgingsStatusRepository: OppfolgingsStatusRepository,
private val norg2Client: Norg2Client,
private val aktorOppslagClient: AktorOppslagClient,
private val authService: AuthService
Expand All @@ -43,6 +49,16 @@ class GraphqlController(
return OppfolgingsEnhetQueryDto(fnr = fnr, enhet = null, kilde = KildeDto.ARENA)
}

@QueryMapping
fun oppfolging(@Argument fnr: String?): OppfolgingDto {
if (fnr == null || fnr.isEmpty()) throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Fnr er påkrevd")
if (authService.erEksternBruker()) throw ResponseStatusException(HttpStatus.FORBIDDEN)

val aktorId = aktorOppslagClient.hentAktorId(Fnr.of(fnr))
val maybeOppfolgingsStatus = oppfolgingsStatusRepository.hentOppfolging(aktorId)
return OppfolgingDto(erUnderOppfolging = maybeOppfolgingsStatus.map { it.isUnderOppfolging }.orElse(false))
}

@SchemaMapping(typeName="OppfolgingsEnhetsInfo", field="enhet")
fun arenaOppfolgingsEnhet(oppfolgingsEnhet: OppfolgingsEnhetQueryDto): EnhetDto? {
val aktorId = aktorOppslagClient.hentAktorId(Fnr.of(oppfolgingsEnhet.fnr))
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/graphql/schema.graphqls
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type Query {
oppfolgingsEnhet(fnr: String!): OppfolgingsEnhetsInfo
oppfolging(fnr: String!): OppfolgingDto
}

type OppfolgingsEnhetsInfo {
Expand All @@ -15,3 +16,7 @@ type EnhetDto {
enum Kilde {
ARENA
}

type OppfolgingDto {
erUnderOppfolging: Boolean!
}

0 comments on commit e05ebd1

Please sign in to comment.