Skip to content

Commit

Permalink
Merge pull request #106 from navikt/ikke-bruke-fnr-i-path-og-query-pa…
Browse files Browse the repository at this point in the history
…rams

Ikke bruke fnr i path og query params
  • Loading branch information
slovrid authored Oct 25, 2023
2 parents 5150e33 + 72998a0 commit 9bdaa0b
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.veilarboppgave.controller;
package no.nav.veilarboppgave.controller.v1;

import lombok.RequiredArgsConstructor;
import no.nav.common.types.identer.AktorId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.veilarboppgave.controller;
package no.nav.veilarboppgave.controller.v1;

import lombok.RequiredArgsConstructor;
import no.nav.common.health.selftest.SelfTestChecks;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.veilarboppgave.controller;
package no.nav.veilarboppgave.controller.v1;

import lombok.RequiredArgsConstructor;
import no.nav.common.types.identer.AktorId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.veilarboppgave.controller;
package no.nav.veilarboppgave.controller.v1;

import lombok.RequiredArgsConstructor;
import no.nav.common.types.identer.AktorId;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package no.nav.veilarboppgave.controller.v2;

import lombok.RequiredArgsConstructor;
import no.nav.common.types.identer.AktorId;
import no.nav.common.types.identer.Fnr;
import no.nav.veilarboppgave.domain.EnheterRequest;
import no.nav.veilarboppgave.domain.OppfolgingEnhet;
import no.nav.veilarboppgave.service.AuthService;
import no.nav.veilarboppgave.service.EnheterService;
import no.nav.veilarboppgave.util.Valider;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static no.nav.veilarboppgave.util.OppgaveUtils.tilTemaDto;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api/v2/enheter")
public class EnheterControllerV2 {

private final EnheterService enheterService;
private final AuthService authService;

@PostMapping
public List<OppfolgingEnhet> hentEnheter(@RequestBody EnheterRequest enheterRequest, @RequestParam("tema") String tema) {
Fnr fnr = enheterRequest.fnr();
AktorId aktorid = authService.getAktorIdOrThrow(fnr);

authService.sjekkLesetilgangMedAktorId(aktorid);

Valider.validerTema(tema);

return enheterService.hentEnheter(fnr, tilTemaDto(tema));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package no.nav.veilarboppgave.controller.v2;

import lombok.RequiredArgsConstructor;
import no.nav.common.types.identer.AktorId;
import no.nav.veilarboppgave.domain.Oppgavehistorikk;
import no.nav.veilarboppgave.domain.OppgavehistorikkRequest;
import no.nav.veilarboppgave.service.AuthService;
import no.nav.veilarboppgave.service.OppgavehistorikkService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api/v2/oppgavehistorikk")
public class OppgavehistorikkControllerV2 {

private final AuthService authService;
private final OppgavehistorikkService oppgavehistorikkService;

@PostMapping
public List<Oppgavehistorikk> getOppgavehistorikk(@RequestBody OppgavehistorikkRequest oppgavehistorikkRequest) {
AktorId aktorId = authService.getAktorIdOrThrow(oppgavehistorikkRequest.fnr());

authService.sjekkLesetilgangMedAktorId(aktorId);

return oppgavehistorikkService.hentOppgavehistorikk(aktorId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package no.nav.veilarboppgave.domain;

import no.nav.common.types.identer.Fnr;

public record EnheterRequest(
Fnr fnr
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package no.nav.veilarboppgave.domain;

import no.nav.common.types.identer.Fnr;

public record OppgavehistorikkRequest(
Fnr fnr
) {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nav.veilarboppgave.controller;
package no.nav.veilarboppgave.controller.v1;

import no.nav.common.types.identer.Fnr;
import no.nav.veilarboppgave.controller.v1.EnheterController;
import no.nav.veilarboppgave.domain.TemaDTO;
import no.nav.veilarboppgave.service.AuthService;
import no.nav.veilarboppgave.service.EnheterService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.veilarboppgave.controller;
package no.nav.veilarboppgave.controller.v1;

import no.nav.veilarboppgave.controller.v1.OppgaveController;
import no.nav.veilarboppgave.domain.OppgaveDTO;
import no.nav.veilarboppgave.service.AuthService;
import no.nav.veilarboppgave.service.OppgaveService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package no.nav.veilarboppgave.controller;
package no.nav.veilarboppgave.controller.v1;


import no.nav.common.types.identer.AktorId;
import no.nav.common.types.identer.Fnr;
import no.nav.veilarboppgave.controller.v1.OppgavehistorikkController;
import no.nav.veilarboppgave.domain.Oppgavehistorikk;
import no.nav.veilarboppgave.domain.OppgavehistorikkDTO;
import no.nav.veilarboppgave.repositoyry.OppgavehistorikkRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package no.nav.veilarboppgave.controller.v2;

import no.nav.veilarboppgave.domain.EnheterRequest;
import no.nav.veilarboppgave.domain.TemaDTO;
import no.nav.veilarboppgave.service.AuthService;
import no.nav.veilarboppgave.service.EnheterService;
import no.nav.veilarboppgave.utils.TestData;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.web.server.ResponseStatusException;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.*;

public class EnhetControllerV2Test {

private EnheterControllerV2 enheterControllerV2;
private AuthService authServiceMock;

@BeforeEach
public void setUp() {
authServiceMock = mock(AuthService.class);
enheterControllerV2 = new EnheterControllerV2(mock(EnheterService.class), authServiceMock);
}

@Test
public void skal_sjekke_tilgang() {
EnheterRequest enheterRequest = new EnheterRequest(TestData.genererTilfeldigFnrUtenTilgang());

enheterControllerV2.hentEnheter(enheterRequest, TemaDTO.OPPFOLGING.name());

verify(authServiceMock, atLeastOnce()).sjekkLesetilgangMedAktorId(any());
}

@Test
public void skal_kaste_exception_ved_validering_av_ugyldig_tema() {
assertThrows(ResponseStatusException.class, () -> {
EnheterRequest enheterRequest = new EnheterRequest(TestData.genererTilfeldigFnrMedTilgang());
enheterControllerV2.hentEnheter(enheterRequest, "UGYLDIG_TEMA");
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package no.nav.veilarboppgave.controller.v2;


import no.nav.common.types.identer.AktorId;
import no.nav.common.types.identer.Fnr;
import no.nav.veilarboppgave.domain.Oppgavehistorikk;
import no.nav.veilarboppgave.domain.OppgavehistorikkDTO;
import no.nav.veilarboppgave.domain.OppgavehistorikkRequest;
import no.nav.veilarboppgave.repositoyry.OppgavehistorikkRepository;
import no.nav.veilarboppgave.service.AuthService;
import no.nav.veilarboppgave.service.OppgavehistorikkService;
import no.nav.veilarboppgave.utils.SingletonPostgresContainer;
import org.junit.Before;
import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.Timestamp;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;

public class OppgavehistorikkControllerV2Test {

private AuthService authService = mock(AuthService.class);

private OppgavehistorikkRepository oppgavehistorikkRepository;

private OppgavehistorikkControllerV2 oppgavehistorikkControllerV2;

@Before
public void resetMocks() {
JdbcTemplate db = SingletonPostgresContainer.init().createJdbcTemplate();
oppgavehistorikkRepository = new OppgavehistorikkRepository(db);
OppgavehistorikkService oppgavehistorikkService = new OppgavehistorikkService(oppgavehistorikkRepository);
oppgavehistorikkControllerV2 = new OppgavehistorikkControllerV2(authService, oppgavehistorikkService);

reset(authService);
}

@Test
public void skalHenteOppgavehistorikk() {
AktorId aktoerid = AktorId.of("4444");
OppgavehistorikkRequest oppgavehistorikkRequest = new OppgavehistorikkRequest(Fnr.of("3333"));

when(authService.getAktorIdOrThrow(any())).thenReturn(aktoerid);

oppgavehistorikkRepository.insertOppgaveHistorikk(getOppgaveHitorikk(aktoerid));
oppgavehistorikkRepository.insertOppgaveHistorikk(getOppgaveHitorikk(aktoerid));

List<Oppgavehistorikk> oppgavehistorikkDTOS = oppgavehistorikkControllerV2.getOppgavehistorikk(oppgavehistorikkRequest);
assertEquals(2, oppgavehistorikkDTOS.size());
}

private OppgavehistorikkDTO getOppgaveHitorikk(AktorId aktorId) {
return new OppgavehistorikkDTO("tema",
"type",
new Timestamp(0),
"X000000",
"GSAKID",
aktorId.get());
}

}

0 comments on commit 9bdaa0b

Please sign in to comment.