diff --git a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CommuneCentreAssignationController.java b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CommuneCentreAssignationController.java index 26bd8e4..db619b0 100644 --- a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CommuneCentreAssignationController.java +++ b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CommuneCentreAssignationController.java @@ -276,4 +276,39 @@ public class CommuneCentreAssignationController { } } + + + @Operation(summary = "Vérifier l'assignation d'un contribuable",description = "permet de vérifier si un contribuable a déjà un centre d'assignation dans la commune de l'utilisateur connecté") + @GetMapping("/contribuable/{personneId}") + public ResponseEntity getAssignationPersonne(@CurrentUser UserPrincipal currentUser, @PathVariable Long personneId) { + try { + if(currentUser==null){ + return new ResponseEntity<>( + new ApiResponse<>(false, null, "vous ne pouvez pas faire cette action."), + HttpStatus.OK + ); + } + User user = currentUser.getUser(); + + + return new ResponseEntity<>( + new ApiResponse<>(true, communeCentreAssignationService.getCommuneCentreAssignationByPersonneIdCommune(user,personneId).orElse(null), "Assignation chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } + } diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CommuneCentreAssignationServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CommuneCentreAssignationServiceImpl.java index 55317e2..93c9eb5 100644 --- a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CommuneCentreAssignationServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CommuneCentreAssignationServiceImpl.java @@ -71,6 +71,9 @@ public class CommuneCentreAssignationServiceImpl implements CommuneCentreAssigna return communeCentreAssignationRepository.findUnique(communeCentreAssignation.getId()).orElse(null); } + + + @Override public CommuneCentreAssignationPaylaodWeb updateCommuneCentreAssignation(Long id,CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) throws NotFoundException { if (communeCentreAssignationPaylaodWeb.getId() == null) { @@ -152,6 +155,29 @@ public class CommuneCentreAssignationServiceImpl implements CommuneCentreAssigna } } + @Override + public Optional getCommuneCentreAssignationByPersonneIdCommune(User user,Long personneId) { + + if (user.getStructure() == null) { + throw new BadRequestException("Impossible de récuperer l'assignation: Votre centre doit être précisé."); + } + + if (user.getStructure().getCommune() == null) { + throw new BadRequestException("Impossible de récuperer une assignation: votre commune doit être précisée."); + } + + if (personneId == null) { + throw new BadRequestException("Impossible de récuperer l'assignation: Le contribuable doit être précisée."); + }else { + if(!personneRepository.existsById(personneId)) + throw new BadRequestException("Impossible de récuperer l'assignation: Le contribuable précisée n'existe pas."); + } + + Optional communeCentreAssignationPaylaodWebOptional=communeCentreAssignationRepository.findbyCommuneAndPersonne(user.getStructure().getCommune().getId(),personneId); + + return communeCentreAssignationPaylaodWebOptional; + } + @Override public Page getCommuneCentreAssignationListByCentrePageable(Long centreId, Pageable pageable) { return communeCentreAssignationRepository.findByStructureId(centreId,pageable); diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CommuneCentreAssignationService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CommuneCentreAssignationService.java index ec579ad..102855f 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CommuneCentreAssignationService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CommuneCentreAssignationService.java @@ -28,7 +28,11 @@ public interface CommuneCentreAssignationService { Optional getCommuneCentreAssignationById(Long id); + Optional getCommuneCentreAssignationByPersonneIdCommune(User user,Long personneId); + Page getCommuneCentreAssignationListByCentrePageable(Long centreId, Pageable pageable); + + // public CommuneCentreAssignationPaylaodWeb getCommuneCentreAssignationPersonneCommune(User user, Long personneId); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 17ab386..7a2dd25 100755 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ -#spring.profiles.active=${SPRING_PROFILES_ACTIVE} +spring.profiles.active=${SPRING_PROFILES_ACTIVE} #spring.profiles.active=abomey -spring.profiles.active=test +#spring.profiles.active=test spring.jpa.properties.hibernate.id.new_generator_mappings=false spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true spring.jpa.open-in-view=false