From 10dc477f9a56730ed46860c473e89ecb2fd1e7f9 Mon Sep 17 00:00:00 2001 From: JeremiahUy Date: Mon, 13 Nov 2023 10:32:48 +0100 Subject: [PATCH] ADD: endpoint for getting krav priority by tema --- .../KravPrioriteringController.java | 20 ++++++++++++++++++- .../KravPrioriteringService.java | 7 ++++--- .../domain/KravPrioriteringRepo.java | 3 +++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/apps/backend/src/main/java/no/nav/data/etterlevelse/kravprioritering/KravPrioriteringController.java b/apps/backend/src/main/java/no/nav/data/etterlevelse/kravprioritering/KravPrioriteringController.java index 56d56d586..21cc6ec61 100644 --- a/apps/backend/src/main/java/no/nav/data/etterlevelse/kravprioritering/KravPrioriteringController.java +++ b/apps/backend/src/main/java/no/nav/data/etterlevelse/kravprioritering/KravPrioriteringController.java @@ -9,6 +9,8 @@ import no.nav.data.common.exceptions.ValidationException; import no.nav.data.common.rest.PageParameters; import no.nav.data.common.rest.RestResponsePage; +import no.nav.data.etterlevelse.codelist.CodelistService; +import no.nav.data.etterlevelse.codelist.domain.ListName; import no.nav.data.etterlevelse.kravprioritering.domain.KravPrioritering; import no.nav.data.etterlevelse.kravprioritering.dto.KravPrioriteringRequest; import no.nav.data.etterlevelse.kravprioritering.dto.KravPrioriteringResponse; @@ -38,6 +40,7 @@ public class KravPrioriteringController { private final KravPrioriteringService service; + private final CodelistService codelistService; @Operation(summary = "Get all krav prioritering") @ApiResponse(description = "ok") @@ -53,7 +56,7 @@ public ResponseEntity> getAll( @Operation(summary = "Get krav prioritering by KravNummer and KravVersjon") @ApiResponse(description = "ok") @GetMapping({"/kravnummer/{kravNummer}/{kravVersjon}", "/kravNummer/{kraVnummer}"}) - public ResponseEntity> getById( + public ResponseEntity> getByKravNummer( @PathVariable Integer kravNummer, @PathVariable(required = false) Integer kravVersjon ) { @@ -62,6 +65,21 @@ public ResponseEntity> getById( return ResponseEntity.ok(new RestResponsePage<>(kravPrioriteringList).convert(KravPrioritering::toResponse)); } + @Operation(summary = "Get krav prioritering by tema code") + @ApiResponse(description = "ok") + @GetMapping("/tema/{temacode}") + public ResponseEntity> getByTemaCode(@PathVariable String temacode) { + log.info("Get krav prioritering for tema={}", temacode); + if(temacode.length() < 3) { + throw new ValidationException("Tema code must be more than 3 characters"); + } + + codelistService.validateListNameAndCode(ListName.TEMA.name(), temacode); + + List kravPrioriteringList = service.getByTema(temacode); + return ResponseEntity.ok(new RestResponsePage<>(kravPrioriteringList).convert(KravPrioritering::toResponse)); + } + @Operation(summary = "Get one krav prioritering") @ApiResponse(description = "ok") @GetMapping("/{id}") diff --git a/apps/backend/src/main/java/no/nav/data/etterlevelse/kravprioritering/KravPrioriteringService.java b/apps/backend/src/main/java/no/nav/data/etterlevelse/kravprioritering/KravPrioriteringService.java index ee88a76d4..5d864c101 100644 --- a/apps/backend/src/main/java/no/nav/data/etterlevelse/kravprioritering/KravPrioriteringService.java +++ b/apps/backend/src/main/java/no/nav/data/etterlevelse/kravprioritering/KravPrioriteringService.java @@ -2,10 +2,7 @@ import no.nav.data.common.rest.PageParameters; import no.nav.data.common.storage.domain.GenericStorage; -import no.nav.data.common.validator.Validator; import no.nav.data.etterlevelse.common.domain.DomainService; -import no.nav.data.etterlevelse.etterlevelse.domain.Etterlevelse; -import no.nav.data.etterlevelse.etterlevelse.dto.EtterlevelseRequest; import no.nav.data.etterlevelse.kravprioritering.domain.KravPrioritering; import no.nav.data.etterlevelse.kravprioritering.domain.KravPrioriteringRepo; import no.nav.data.etterlevelse.kravprioritering.dto.KravPrioriteringRequest; @@ -41,6 +38,10 @@ public List getByKravNummer(int kravNummer, @Nullable Integer return GenericStorage.to(repo.findByKravNummer(kravNummer, kravVersjon), KravPrioritering.class); } + public List getByTema(String tema) { + return GenericStorage.to(repo.findByTema(tema.substring(0, 3)), KravPrioritering.class); + } + public KravPrioritering save(KravPrioriteringRequest request) { var kravprioritering = request.isUpdate() ? storage.get(request.getIdAsUUID(), KravPrioritering.class) : new KravPrioritering(); diff --git a/apps/backend/src/main/java/no/nav/data/etterlevelse/kravprioritering/domain/KravPrioriteringRepo.java b/apps/backend/src/main/java/no/nav/data/etterlevelse/kravprioritering/domain/KravPrioriteringRepo.java index 0e25b209d..9329c91df 100644 --- a/apps/backend/src/main/java/no/nav/data/etterlevelse/kravprioritering/domain/KravPrioriteringRepo.java +++ b/apps/backend/src/main/java/no/nav/data/etterlevelse/kravprioritering/domain/KravPrioriteringRepo.java @@ -25,6 +25,9 @@ public interface KravPrioriteringRepo extends JpaRepository findByKravNummer(int nummer, int versjon); + @Query(value = "select * from generic_storage where data -> 'prioriteringsId' ilike %?1% and type = 'KravPrioritering'", nativeQuery = true) + List findByTema(String tema); + @Modifying(clearAutomatically = true) @Transactional @Query(value = "update generic_storage set DATA = jsonb_set(DATA, '{kravVersjon}', to_jsonb(?1) , false ) where data -> 'kravNummer' = to_jsonb(?2) and type = 'KravPrioritering'", nativeQuery = true)