Skip to content

Commit

Permalink
Legger til grunnlagspakkeId til behandling (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
unorsk authored Sep 26, 2023
1 parent 38098ff commit 3ae4e5b
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import no.nav.bidrag.behandling.dto.behandling.CreateBehandlingRequest
import no.nav.bidrag.behandling.dto.behandling.CreateBehandlingResponse
import no.nav.bidrag.behandling.dto.behandling.RolleDto
import no.nav.bidrag.behandling.dto.behandling.SyncRollerRequest
import no.nav.bidrag.behandling.dto.behandling.UpdateBehandlingRequest
import no.nav.bidrag.behandling.service.BehandlingService
import no.nav.bidrag.behandling.transformers.toHusstandsBarnDto
import no.nav.bidrag.behandling.transformers.toLocalDate
Expand Down Expand Up @@ -84,6 +85,19 @@ class BehandlingController(private val behandlingService: BehandlingService) {
return CreateBehandlingResponse(behandlingDo.id!!)
}

@Suppress("unused")
@PutMapping("/behandling/{behandlingId}")
@Operation(
description = "Oppdatere behandling",
security = [SecurityRequirement(name = "bearer-key")],
)
fun updateBehandling(
@PathVariable behandlingId: Long,
@Valid @RequestBody(required = true) request: UpdateBehandlingRequest,
) {
behandlingService.updateBehandling(behandlingId, request.grunnlagspakkeId)
}

@Suppress("unused")
@PutMapping("/behandling/{behandlingId}/roller/sync")
@Operation(
Expand Down Expand Up @@ -169,6 +183,7 @@ class BehandlingController(private val behandlingService: BehandlingService) {
behandling.sivilstand.toSivilstandDto(),
behandling.virkningsDato?.toLocalDate(),
behandling.soknadRefId,
behandling.grunnlagspakkeId,
behandling.aarsak,
behandling.virkningsTidspunktBegrunnelseMedIVedtakNotat,
behandling.virkningsTidspunktBegrunnelseKunINotat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Behandling(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
var grunnlagspakkeId: Long? = null,
@OneToMany(fetch = FetchType.EAGER, mappedBy = "behandling", cascade = [CascadeType.ALL], orphanRemoval = true)
var roller: MutableSet<Rolle> = mutableSetOf(),
@OneToMany(fetch = FetchType.EAGER, mappedBy = "behandling", cascade = [CascadeType.ALL], orphanRemoval = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ data class BehandlingDto(
@JsonFormat(pattern = "yyyy-MM-dd")
val virkningsDato: LocalDate? = null,
val soknadRefId: Long? = null,
val grunnlagspakkeId: Long? = null,
val aarsak: ForskuddAarsakType? = null,
val virkningsTidspunktBegrunnelseMedIVedtakNotat: String? = null,
val virkningsTidspunktBegrunnelseKunINotat: String? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package no.nav.bidrag.behandling.dto.behandling

data class UpdateBehandlingRequest(
val grunnlagspakkeId: Long? = null,
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ class BehandlingService(
enhet = behandling.behandlerEnhet,
roller = behandling.tilForsendelseRolleDto(),
behandlingInfo =
BehandlingInfoDto(
behandlingId = behandling.id,
soknadId = behandling.soknadId,
soknadFra = behandling.soknadFra,
behandlingType = behandling.behandlingType.name,
stonadType = behandling.stonadType,
engangsBelopType = behandling.engangsbelopType,
vedtakType = behandling.soknadType.tilVedtakType(),
),
BehandlingInfoDto(
behandlingId = behandling.id,
soknadId = behandling.soknadId,
soknadFra = behandling.soknadFra,
behandlingType = behandling.behandlingType.name,
stonadType = behandling.stonadType,
engangsBelopType = behandling.engangsbelopType,
vedtakType = behandling.soknadType.tilVedtakType(),
),
),
)
}
Expand Down Expand Up @@ -184,4 +184,14 @@ class BehandlingService(
behandlingRepository.delete(behandling)
}
}

fun updateBehandling(
behandlingId: Long,
grunnlagspakkeId: Long?,
) {
hentBehandlingById(behandlingId).let {
it.grunnlagspakkeId = grunnlagspakkeId
behandlingRepository.save(it)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE BEHANDLING
ADD COLUMN GRUNNLAGSPAKKE_ID INT DEFAULT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import no.nav.bidrag.behandling.database.datamodell.SoknadType
import no.nav.bidrag.behandling.dto.behandling.BehandlingDto
import no.nav.bidrag.behandling.dto.behandling.CreateBehandlingResponse
import no.nav.bidrag.behandling.dto.behandling.CreateRolleRolleType
import no.nav.bidrag.behandling.dto.behandling.UpdateBehandlingRequest
import no.nav.bidrag.behandling.service.BehandlingService
import no.nav.bidrag.behandling.service.BehandlingServiceTest
import no.nav.bidrag.domain.enums.StonadType
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -94,6 +96,31 @@ class BehandlingControllerTest() : KontrollerTestRunner() {
assertEquals(3, behandling.body!!.roller.size)
}

@Test
fun `skal oppdatere behandling`() {
val b = behandlingService.createBehandling(BehandlingServiceTest.prepareBehandling())

val behandlingRes =
httpHeaderTestRestTemplate.exchange(
"${rootUri()}/behandling/" + b.id,
HttpMethod.PUT,
HttpEntity(UpdateBehandlingRequest(123L)),
Void::class.java,
)
assertEquals(HttpStatus.OK, behandlingRes.statusCode)

val updatedBehandling =
httpHeaderTestRestTemplate.exchange(
"${rootUri()}/behandling/${b!!.id}",
HttpMethod.GET,
HttpEntity.EMPTY,
BehandlingDto::class.java,
)

assertNotNull(updatedBehandling.body)
assertEquals(123L, updatedBehandling.body!!.grunnlagspakkeId)
}

@Test
fun `skal opprette en behandling`() {
val roller =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ class BehandlingServiceTest : TestContainerRunner() {
assertEquals(1L, deletedCount)
}

@Test
fun `skal opprette en behandling med grunnlagspakkeId`() {
val b = createBehandling()

behandlingService.updateBehandling(b.id!!, 123L)

assertEquals(123L, behandlingService.hentBehandlingById(b.id!!).grunnlagspakkeId)
}

@Test
fun `skal opprette en behandling med inntekter`() {
val behandling = prepareBehandling()
Expand Down

0 comments on commit 3ae4e5b

Please sign in to comment.