diff --git a/apps/levende-arbeidsforhold-ansettelse/build.gradle b/apps/levende-arbeidsforhold-ansettelse/build.gradle index 0cacdce2eb4..8af63f81cbc 100644 --- a/apps/levende-arbeidsforhold-ansettelse/build.gradle +++ b/apps/levende-arbeidsforhold-ansettelse/build.gradle @@ -22,8 +22,6 @@ dependencies { implementation "org.springframework.boot:spring-boot-starter-oauth2-client" implementation "org.springframework.boot:spring-boot-starter-data-r2dbc" - implementation "org.springframework.cloud:spring-cloud-starter-vault-config" - implementation "io.r2dbc:r2dbc-h2" implementation "org.postgresql:r2dbc-postgresql" implementation "org.flywaydb:flyway-core" @@ -36,14 +34,6 @@ dependencies { implementation "org.springdoc:springdoc-openapi-starter-webflux-ui:$versions.springdoc" implementation "io.swagger.core.v3:swagger-annotations-jakarta:$versions.swagger" - implementation "org.hibernate.validator:hibernate-validator" - - testImplementation "org.springframework.boot:spring-boot-starter-test" - - implementation "org.projectlombok:lombok" - annotationProcessor "org.projectlombok:lombok" - testAnnotationProcessor "org.projectlombok:lombok" - implementation "com.zaxxer:HikariCP" } diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/config/WebConfig.java b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/config/WebConfig.java new file mode 100644 index 00000000000..e228460b2fc --- /dev/null +++ b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/config/WebConfig.java @@ -0,0 +1,15 @@ +package no.nav.testnav.levendearbeidsforholdansettelse.config; + +import no.nav.testnav.levendearbeidsforholdansettelse.utility.PageableHandlerMethodArgumentResolver; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.reactive.config.WebFluxConfigurer; +import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer; + +@Configuration +public class WebConfig implements WebFluxConfigurer { + + @Override + public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) { + configurer.addCustomResolver(new PageableHandlerMethodArgumentResolver()); + } +} diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/controller/LoggController.java b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/controller/LoggController.java index d00b0c403aa..1d67f42ced9 100644 --- a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/controller/LoggController.java +++ b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/controller/LoggController.java @@ -5,12 +5,15 @@ import no.nav.testnav.levendearbeidsforholdansettelse.entity.AnsettelseLogg; import no.nav.testnav.levendearbeidsforholdansettelse.service.LoggService; import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; @RestController @RequestMapping("/api/v1/logg") @@ -21,8 +24,11 @@ public class LoggController { @GetMapping @Operation(description = "Henter logger i hht forespørsel") - public Flux> getAnsettelser(Pageable pageable) { + public Mono> getAnsettelser(@RequestParam(defaultValue = "0") int page, + @RequestParam(defaultValue = "10") int size, + @RequestParam(defaultValue = "id") String... sort) { + var pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, sort)); return loggService.getAnsettelseLogg(pageable); } diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/entity/AnsettelseLogg.java b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/entity/AnsettelseLogg.java index 57a2fc39696..363a592c87b 100644 --- a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/entity/AnsettelseLogg.java +++ b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/entity/AnsettelseLogg.java @@ -1,5 +1,6 @@ package no.nav.testnav.levendearbeidsforholdansettelse.entity; +import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; @@ -15,7 +16,7 @@ import org.springframework.data.relational.core.mapping.Table; import java.time.LocalDate; -import java.time.OffsetDateTime; +import java.time.LocalDateTime; @Data @Builder @@ -28,6 +29,8 @@ public class AnsettelseLogg implements Persistable { private boolean isNew; @Id + @NotNull + @Column("id") private Integer id; @Size(max = 255) @@ -42,7 +45,7 @@ public class AnsettelseLogg implements Persistable { @NotNull @Column("timestamp") - private OffsetDateTime timestamp; + private LocalDateTime timestamp; @NotNull @Column("ansattfra") @@ -70,6 +73,7 @@ public int hashCode() { } @Override + @JsonIgnore public boolean isNew() { return isNew; } diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/entity/JobbParameter.java b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/entity/JobbParameter.java index abc326613cb..ae87f7e5b36 100644 --- a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/entity/JobbParameter.java +++ b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/entity/JobbParameter.java @@ -1,5 +1,6 @@ package no.nav.testnav.levendearbeidsforholdansettelse.entity; +import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.Data; @@ -55,6 +56,7 @@ public String getId() { } @Override + @JsonIgnore public boolean isNew() { return isNew; } diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/repository/LoggRepository.java b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/repository/LoggRepository.java index 0985cce7e37..143b4704fc2 100644 --- a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/repository/LoggRepository.java +++ b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/repository/LoggRepository.java @@ -1,12 +1,14 @@ package no.nav.testnav.levendearbeidsforholdansettelse.repository; import no.nav.testnav.levendearbeidsforholdansettelse.entity.AnsettelseLogg; -import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.repository.reactive.ReactiveSortingRepository; import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; public interface LoggRepository extends ReactiveSortingRepository { - Flux> findAllBy(Pageable pageable); + Flux findAllBy(Pageable pageable); + + Mono countAllBy(); } diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/service/AnsettelseLoggService.java b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/service/AnsettelseLoggService.java index de67a9b12ac..d9690643582 100644 --- a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/service/AnsettelseLoggService.java +++ b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/service/AnsettelseLoggService.java @@ -9,7 +9,7 @@ import reactor.core.publisher.Mono; import java.time.LocalDate; -import java.time.OffsetDateTime; +import java.time.LocalDateTime; import java.util.Map; import static no.nav.testnav.levendearbeidsforholdansettelse.entity.JobbParameterNavn.ARBEIDSFORHOLD_TYPE; @@ -36,7 +36,7 @@ public Mono lagreAnsettelse(KanAnsettesDTO kanAnsette, Map Flux.range(0, (int) getParameterValue(tuple.getT1(), ANTALL_ORGANISASJONER)) diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/service/ArbeidsforholdService.java b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/service/ArbeidsforholdService.java index c6cfaa45974..c73bd0c13e2 100644 --- a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/service/ArbeidsforholdService.java +++ b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/service/ArbeidsforholdService.java @@ -16,6 +16,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; +import java.time.Duration; import java.time.LocalDate; import java.util.List; @@ -53,8 +54,8 @@ public Flux getArbeidsforhold(String ident) { public Flux opprettArbeidsforhold(KanAnsettesDTO kanAnsettes, String yrke, String arbeidsforholdstype, Integer stillingsprosent) { - return aaregConsumer.opprettArbeidsforhold(lagArbeidsforhold(kanAnsettes, yrke, arbeidsforholdstype, stillingsprosent)); - + return aaregConsumer.opprettArbeidsforhold(lagArbeidsforhold(kanAnsettes, yrke, arbeidsforholdstype, stillingsprosent)) + .delayElements(Duration.ofSeconds(1)); } /** diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/service/LoggService.java b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/service/LoggService.java index db91b15c5e3..720c7b6fc97 100644 --- a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/service/LoggService.java +++ b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/service/LoggService.java @@ -5,9 +5,11 @@ import no.nav.testnav.levendearbeidsforholdansettelse.repository.AnsettelseLoggRepository; import no.nav.testnav.levendearbeidsforholdansettelse.repository.LoggRepository; import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; @Service @RequiredArgsConstructor @@ -16,9 +18,12 @@ public class LoggService { private final LoggRepository loggRepository; private final AnsettelseLoggRepository ansettelseLoggRepository; - public Flux> getAnsettelseLogg(Pageable pageable) { + public Mono> getAnsettelseLogg(Pageable pageable) { - return loggRepository.findAllBy(pageable); + return loggRepository.findAllBy(pageable) + .collectList() + .zipWith(loggRepository.countAllBy()) + .map(tuple -> new PageImpl<>(tuple.getT1(), pageable, tuple.getT2())); } public Flux getIdent(String ident) { diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/utility/PageableHandlerMethodArgumentResolver.java b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/utility/PageableHandlerMethodArgumentResolver.java new file mode 100644 index 00000000000..3e2f14ef144 --- /dev/null +++ b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/utility/PageableHandlerMethodArgumentResolver.java @@ -0,0 +1,63 @@ +package no.nav.testnav.levendearbeidsforholdansettelse.utility; + +import org.springframework.core.MethodParameter; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.web.reactive.BindingContext; +import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +import java.util.List; + +import static java.util.Objects.nonNull; + +public class PageableHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { + + private static final String DEFAULT_PAGE = "0"; + private static final String DEFAULT_SIZE = "10"; + private static final Integer MAX_SIZE = 50; + + @Override + public boolean supportsParameter(MethodParameter parameter) { + return Pageable.class.equals(parameter.getParameterType()); + } + + @Override + public Mono resolveArgument(MethodParameter methodParameter, + BindingContext bindingContext, + ServerWebExchange serverWebExchange) { + + var pageValues = serverWebExchange.getRequest() + .getQueryParams() + .getOrDefault("page", List.of(DEFAULT_PAGE)); + var sizeValues = serverWebExchange.getRequest() + .getQueryParams() + .getOrDefault("size", List.of(DEFAULT_SIZE)); + + var page = pageValues.getFirst(); + + var sortParam = serverWebExchange.getRequest() + .getQueryParams().getFirst("sort"); + + var sort = Sort.unsorted(); + + if (nonNull(sortParam)) { + var parts = sortParam.split(","); + if (parts.length == 2) { + var property = parts[0]; + var direction = Sort.Direction.fromString(parts[1]); + sort = Sort.by(direction, property); + } + } + + return Mono.just( + PageRequest.of( + Integer.parseInt(page), + Math.min(Integer.parseInt(sizeValues.getFirst()), + MAX_SIZE), sort + ) + ); + } +} \ No newline at end of file diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/resources/db/migration/V1.2.0__ModifyPrimaryKey.sql b/apps/levende-arbeidsforhold-ansettelse/src/main/resources/db/migration/V1.2.0__ModifyPrimaryKey.sql new file mode 100644 index 00000000000..9db5c6b644f --- /dev/null +++ b/apps/levende-arbeidsforhold-ansettelse/src/main/resources/db/migration/V1.2.0__ModifyPrimaryKey.sql @@ -0,0 +1,6 @@ +----------------------------------- +-- M O D I F Y I N D E C I E S -- +----------------------------------- + +ALTER TABLE ansettelse_logg +ALTER COLUMN id SET DEFAULT NEXTVAL('ansettelse_logg_id_seq'); diff --git a/docs/compose.yaml b/docs/compose.yaml index c957309a956..02a8dafd3c2 100644 --- a/docs/compose.yaml +++ b/docs/compose.yaml @@ -27,4 +27,14 @@ services: - POSTGRES_HOST_AUTH_METHOD=trust ports: - "5434:5432" + restart: always + + postgres-levende-arbeidforhold: + container_name: postgres-levende-arbeidforhold-test + image: postgres:latest + environment: + - POSTGRES_DB=postgres-levende-arbeidforhold-test + - POSTGRES_HOST_AUTH_METHOD=trust + ports: + - "5435:5432" restart: always \ No newline at end of file