Skip to content

Commit

Permalink
Refactor and add Skattekort retrieval functionality #deploy-skattekor…
Browse files Browse the repository at this point in the history
…t-service

SokosResponse was renamed to SokosGetRequest and moved to a separate libraries. Updated relevant fields of the class to align with new requirements. Introduced new GET API for Skattekort retrieval in the SkattekortController. Implemented the retrieval functionality in SkattekortService and SokosSkattekortConsumer using a new SokosGetCommand.
  • Loading branch information
krharum committed Jun 13, 2024
1 parent bc3ae87 commit a61226e
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package no.nav.skattekortservice.consumer;

import no.nav.skattekortservice.config.Consumers;
import no.nav.skattekortservice.consumer.command.SokosGetCommand;
import no.nav.skattekortservice.consumer.command.SokosPostCommand;
import no.nav.skattekortservice.dto.SokosRequest;
import no.nav.testnav.libs.dto.skattekortservice.v1.SokosGetRequest;
import no.nav.testnav.libs.reactivesecurity.exchange.TokenExchange;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -30,4 +32,11 @@ public Mono<String> sendSkattekort(SokosRequest request) {
return tokenExchange.exchange(serverProperties)
.flatMap(token -> new SokosPostCommand(webClient, request, token.getTokenValue()).call());
}

public Mono<String> hentSkattekort(SokosGetRequest request) {

return tokenExchange.exchange(serverProperties)
.flatMap(token -> new SokosGetCommand(webClient, request.getIdent(),
request.getInntektsar(), token.getTokenValue()).call());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package no.nav.skattekortservice.consumer.command;

import lombok.RequiredArgsConstructor;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

import java.util.UUID;
import java.util.concurrent.Callable;

import static org.apache.hc.core5.http.HttpHeaders.AUTHORIZATION;

@RequiredArgsConstructor
public class SokosGetCommand implements Callable<Mono<String>> {

private static final String SOKOS_URL = "/api/v1/skattekort/hent/{fnr}/{inntektsaar}";

private final WebClient webClient;
private final String ident;
private final String inntektsaar;
private final String token;

@Override
public Mono<String> call() {

return webClient
.get()
.uri(uriBuilder -> uriBuilder.path(SOKOS_URL)
.build(ident, inntektsaar))
.header(AUTHORIZATION, "Bearer " + token)
.header("korrelasjonsid", UUID.randomUUID().toString())
.retrieve()
.bodyToMono(String.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ public class SokosRequest {
private String fnr;
private String inntektsar;
private String skattekort;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import lombok.RequiredArgsConstructor;
import no.nav.skattekortservice.service.SkattekortService;
import no.nav.testnav.libs.dto.skattekortservice.v1.SkattekortTilArbeidsgiverDTO;
import no.nav.testnav.libs.dto.skattekortservice.v1.SokosGetRequest;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -17,9 +19,15 @@ public class SkattekortController {

private final SkattekortService skattekortService;

@PostMapping(value = "/arbeidsgiver", produces = MediaType.ALL_VALUE)
public Mono<String> sendSkattekortTilArbeidsgiver(@RequestBody SkattekortTilArbeidsgiverDTO skattekort) {
@PostMapping(produces = MediaType.ALL_VALUE)
public Mono<String> sendSkattekort(@RequestBody SkattekortTilArbeidsgiverDTO skattekort) {

return skattekortService.sendSkattekort(skattekort);
}

@GetMapping(produces = MediaType.ALL_VALUE)
public Mono<String> hentSkattekort(@RequestBody SokosGetRequest request) {

return skattekortService.hentSkattekort(request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import no.nav.skattekortservice.dto.SokosRequest;
import no.nav.skattekortservice.utility.SkattekortValidator;
import no.nav.testnav.libs.dto.skattekortservice.v1.SkattekortTilArbeidsgiverDTO;
import no.nav.testnav.libs.dto.skattekortservice.v1.SokosGetRequest;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -69,4 +70,9 @@ private String encodeRequest(String request) {
return Base64.getEncoder()
.encodeToString(request.getBytes(StandardCharsets.UTF_8));
}

public Mono<String> hentSkattekort(SokosGetRequest request) {

return skattekortConsumer.hentSkattekort(request);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.skattekortservice.dto;
package no.nav.testnav.libs.dto.skattekortservice.v1;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -9,9 +9,8 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SokosResponse {
public class SokosGetRequest {

private String fnr;
private Integer inntektsar;
private String status;
}
private String ident;
private String inntektsar;
}

0 comments on commit a61226e

Please sign in to comment.