-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Api for gebyr og lagre om rolle har gebyrsøknad (#614)
* Lagre om rolle har gebyrsøknad * Lagre om rolle har gebyrsøknad * Lagre om rolle har gebyrsøknad * Gebyr api * Oppgrader felles for endringer i beregninger * Oppgrader felles for endringer i beregninger * Gebyr service WIP * Gebyr api * Gebyr api * Gebyr api * Fiks gebyr grunnlagsliste * Lagt til flere tester * Lagt til flere tester og diverse justeringer * Lagt til flere tester og diverse justeringer * Lagt til flere tester og diverse justeringer
- Loading branch information
Showing
40 changed files
with
1,883 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/kotlin/no/nav/bidrag/behandling/controller/v2/GebyrController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package no.nav.bidrag.behandling.controller.v2 | ||
|
||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement | ||
import jakarta.validation.Valid | ||
import no.nav.bidrag.behandling.dto.v2.gebyr.OppdaterGebyrResponsDto | ||
import no.nav.bidrag.behandling.dto.v2.gebyr.OppdaterManueltGebyrDto | ||
import no.nav.bidrag.behandling.service.BehandlingService | ||
import no.nav.bidrag.behandling.service.GebyrService | ||
import no.nav.bidrag.behandling.transformers.behandling.tilDto | ||
import no.nav.bidrag.behandling.transformers.gebyr.tilDto | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.PutMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
|
||
@BehandlingRestControllerV2 | ||
class GebyrController( | ||
private val gebyrService: GebyrService, | ||
private val behandlingService: BehandlingService, | ||
) { | ||
@Suppress("unused") | ||
@PutMapping("/behandling/{behandlingsid}/gebyr") | ||
@Operation( | ||
description = | ||
"Oppdater manuelt overstyr gebyr for en behandling.", | ||
security = [SecurityRequirement(name = "bearer-key")], | ||
) | ||
fun oppdaterManueltOverstyrtGebyr( | ||
@PathVariable behandlingsid: Long, | ||
@Valid | ||
@RequestBody(required = true) | ||
request: OppdaterManueltGebyrDto, | ||
): OppdaterGebyrResponsDto { | ||
gebyrService.oppdaterManueltOverstyrtGebyr(behandlingService.hentBehandlingById(behandlingsid), request) | ||
return tilRespons(behandlingsid, request.rolleId) | ||
} | ||
|
||
private fun tilRespons( | ||
behandlingsId: Long, | ||
rolleId: Long, | ||
): OppdaterGebyrResponsDto { | ||
val behandling = behandlingService.hentBehandlingById(behandlingsId) | ||
return behandling.roller.find { it.id == rolleId }!!.let { rolle -> | ||
OppdaterGebyrResponsDto( | ||
rolle.tilDto(), | ||
rolle.manueltOverstyrtGebyr?.tilDto(), | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/no/nav/bidrag/behandling/dto/v2/gebyr/GebyrValideringsfeilDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package no.nav.bidrag.behandling.dto.v2.gebyr | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore | ||
import no.nav.bidrag.behandling.database.datamodell.Behandling | ||
import no.nav.bidrag.behandling.dto.v1.behandling.RolleDto | ||
import no.nav.bidrag.behandling.transformers.behandling.tilDto | ||
|
||
fun Behandling.validerGebyr() = | ||
roller | ||
.filter { it.harGebyrsøknad } | ||
.map { | ||
GebyrValideringsfeilDto( | ||
gjelder = it.tilDto(), | ||
måBestemmeGebyr = avslag != null && it.manueltOverstyrtGebyr?.ilagtGebyr == null, | ||
manglerBegrunnelse = | ||
if (it.manueltOverstyrtGebyr?.overstyrGebyr == true) { | ||
it.manueltOverstyrtGebyr?.begrunnelse.isNullOrEmpty() | ||
} else { | ||
false | ||
}, | ||
) | ||
}.filter { it.harFeil } | ||
|
||
data class GebyrValideringsfeilDto( | ||
val gjelder: RolleDto, | ||
val måBestemmeGebyr: Boolean, | ||
val manglerBegrunnelse: Boolean, | ||
) { | ||
@get:JsonIgnore | ||
val harFeil | ||
get() = manglerBegrunnelse || måBestemmeGebyr | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/no/nav/bidrag/behandling/dto/v2/gebyr/OppdaterManueltGebyr.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package no.nav.bidrag.behandling.dto.v2.gebyr | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema | ||
import no.nav.bidrag.behandling.dto.v1.behandling.RolleDto | ||
|
||
data class OppdaterManueltGebyrDto( | ||
val rolleId: Long, | ||
val overstyrtGebyr: ManueltOverstyrGebyrDto?, | ||
) | ||
|
||
data class OppdaterGebyrResponsDto( | ||
val rolle: RolleDto, | ||
val overstyrtGebyr: ManueltOverstyrGebyrDto?, | ||
) | ||
|
||
data class ManueltOverstyrGebyrDto( | ||
val begrunnelse: String? = null, | ||
@Schema(description = "Skal bare settes hvis det er avslag") | ||
val ilagtGebyr: Boolean? = null, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/main/kotlin/no/nav/bidrag/behandling/service/GebyrService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package no.nav.bidrag.behandling.service | ||
|
||
import no.nav.bidrag.behandling.database.datamodell.Behandling | ||
import no.nav.bidrag.behandling.database.datamodell.RolleManueltOverstyrtGebyr | ||
import no.nav.bidrag.behandling.dto.v2.gebyr.OppdaterManueltGebyrDto | ||
import no.nav.bidrag.behandling.transformers.tilType | ||
import no.nav.bidrag.behandling.transformers.validerSann | ||
import no.nav.bidrag.behandling.transformers.vedtak.mapping.tilvedtak.VedtakGrunnlagMapper | ||
import no.nav.bidrag.behandling.ugyldigForespørsel | ||
import no.nav.bidrag.domene.enums.behandling.TypeBehandling | ||
import no.nav.bidrag.transport.felles.ifTrue | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class GebyrService( | ||
private val vedtakGrunnlagMapper: VedtakGrunnlagMapper, | ||
) { | ||
@Transactional | ||
fun oppdaterGebyrEtterEndringÅrsakAvslag(behandling: Behandling) { | ||
behandling | ||
.roller | ||
.filter { it.harGebyrsøknad } | ||
.forEach { rolle -> | ||
rolle.manueltOverstyrtGebyr = | ||
(rolle.manueltOverstyrtGebyr ?: RolleManueltOverstyrtGebyr()).let { | ||
it.copy( | ||
overstyrGebyr = behandling.avslag != null, | ||
ilagtGebyr = | ||
(behandling.avslag == null).ifTrue { | ||
val beregning = vedtakGrunnlagMapper.beregnGebyr(behandling, rolle) | ||
!beregning.ilagtGebyr | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Transactional | ||
fun oppdaterManueltOverstyrtGebyr( | ||
behandling: Behandling, | ||
request: OppdaterManueltGebyrDto, | ||
) { | ||
val rolle = | ||
behandling.roller.find { it.id == request.rolleId } | ||
?: ugyldigForespørsel("Fant ikke rolle ${request.rolleId} i behandling ${behandling.id}") | ||
val beregning = vedtakGrunnlagMapper.beregnGebyr(behandling, rolle) | ||
behandling.validerOppdatering(request) | ||
rolle.manueltOverstyrtGebyr = | ||
(rolle.manueltOverstyrtGebyr ?: RolleManueltOverstyrtGebyr()).let { | ||
it.copy( | ||
overstyrGebyr = request.overstyrtGebyr != null, | ||
ilagtGebyr = request.overstyrtGebyr?.ilagtGebyr ?: (behandling.avslag == null).ifTrue { !beregning.ilagtGebyr }, | ||
begrunnelse = request.overstyrtGebyr?.begrunnelse ?: it.begrunnelse, | ||
) | ||
} | ||
} | ||
|
||
private fun Behandling.validerOppdatering(request: OppdaterManueltGebyrDto) { | ||
val feilListe = mutableSetOf<String>() | ||
|
||
feilListe.validerSann(tilType() == TypeBehandling.BIDRAG, "Kan bare oppdatere gebyr på en bidragsbehandling") | ||
|
||
val rolle = | ||
roller.find { it.id == request.rolleId } | ||
?: ugyldigForespørsel("Fant ikke rolle ${request.rolleId} i behandling $id") | ||
|
||
feilListe.validerSann( | ||
rolle.harGebyrsøknad, | ||
"Kan ikke endre gebyr på en rolle som ikke har gebyrsøknad", | ||
) | ||
|
||
if (avslag == null) { | ||
feilListe.validerSann( | ||
request.overstyrtGebyr?.ilagtGebyr == null, | ||
"Kan ikke sette gebyr til samme som beregnet gebyr når det ikke er avslag", | ||
) | ||
} | ||
|
||
if (feilListe.isNotEmpty()) { | ||
ugyldigForespørsel(feilListe.toSet().joinToString("\n")) | ||
} | ||
} | ||
} |
Oops, something went wrong.