Skip to content

Commit

Permalink
ADD: endpoint for getting krav priority by tema
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremiahUy committed Nov 13, 2023
1 parent d175305 commit 10dc477
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,6 +40,7 @@ public class KravPrioriteringController {


private final KravPrioriteringService service;
private final CodelistService codelistService;

@Operation(summary = "Get all krav prioritering")
@ApiResponse(description = "ok")
Expand All @@ -53,7 +56,7 @@ public ResponseEntity<RestResponsePage<KravPrioriteringResponse>> getAll(
@Operation(summary = "Get krav prioritering by KravNummer and KravVersjon")
@ApiResponse(description = "ok")
@GetMapping({"/kravnummer/{kravNummer}/{kravVersjon}", "/kravNummer/{kraVnummer}"})
public ResponseEntity<RestResponsePage<KravPrioriteringResponse>> getById(
public ResponseEntity<RestResponsePage<KravPrioriteringResponse>> getByKravNummer(
@PathVariable Integer kravNummer,
@PathVariable(required = false) Integer kravVersjon
) {
Expand All @@ -62,6 +65,21 @@ public ResponseEntity<RestResponsePage<KravPrioriteringResponse>> 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<RestResponsePage<KravPrioriteringResponse>> 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<KravPrioritering> kravPrioriteringList = service.getByTema(temacode);
return ResponseEntity.ok(new RestResponsePage<>(kravPrioriteringList).convert(KravPrioritering::toResponse));
}

@Operation(summary = "Get one krav prioritering")
@ApiResponse(description = "ok")
@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,6 +38,10 @@ public List<KravPrioritering> getByKravNummer(int kravNummer, @Nullable Integer
return GenericStorage.to(repo.findByKravNummer(kravNummer, kravVersjon), KravPrioritering.class);
}

public List<KravPrioritering> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public interface KravPrioriteringRepo extends JpaRepository<GenericStorage, UUID
@Query(value = "select * from generic_storage where data -> 'kravNummer' = to_jsonb(?1) and data -> 'kravVersjon' = to_jsonb(?2) and type = 'KravPrioritering'", nativeQuery = true)
List<GenericStorage> findByKravNummer(int nummer, int versjon);

@Query(value = "select * from generic_storage where data -> 'prioriteringsId' ilike %?1% and type = 'KravPrioritering'", nativeQuery = true)
List<GenericStorage> 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)
Expand Down

0 comments on commit 10dc477

Please sign in to comment.