Compare commits

...

3 Commits

Author SHA1 Message Date
b58316bb88 Merge pull request 'develop' (#78) from develop into main
All checks were successful
CD - Deploy on main / deploy (push) Successful in 49s
Reviewed-on: #78
2026-02-02 23:04:11 +00:00
08b68f9e08 Merge pull request 'gestion revu de code en utilisant uniquement les DTO' (#77) from features/crud_entites into develop
Reviewed-on: #77
2026-02-02 23:03:26 +00:00
fc6ff679f0 gestion revu de code en utilisant uniquement les DTO
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 33s
2026-02-03 00:01:45 +01:00
19 changed files with 837 additions and 308 deletions

View File

@@ -6,6 +6,7 @@ import io.gmss.fiscad.exceptions.*;
import io.gmss.fiscad.interfaces.decoupage.ArrondissementService;
import io.gmss.fiscad.interfaces.infocad.parametre.StructureService;
import io.gmss.fiscad.paylaods.ApiResponse;
import io.gmss.fiscad.paylaods.request.crudweb.StructurePaylaodWeb;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
@@ -27,7 +28,7 @@ import org.springframework.web.client.HttpClientErrorException;
@SecurityRequirement(name = "bearer")
@Tag(name = "Structure")
@CrossOrigin(origins = "*")
@PreAuthorize("hasRole('ADMIN') or hasRole('SUPERVISEUR') or hasRole('ENQUETEUR')")
//@PreAuthorize("hasRole('ADMIN') or hasRole('SUPERVISEUR') or hasRole('ENQUETEUR')")
public class StructureController {
private final StructureService structureService;
@@ -40,11 +41,11 @@ public class StructureController {
}
@PostMapping("/create")
public ResponseEntity<?> createStructure(@RequestBody @Valid @Validated Structure structure) {
public ResponseEntity<?> createStructure(@RequestBody @Valid @Validated StructurePaylaodWeb structurePaylaodWeb) {
try {
structure = structureService.createStructure(structure);
structurePaylaodWeb = structureService.createStructure(structurePaylaodWeb);
return new ResponseEntity<>(
new ApiResponse<>(true, structure, "Structure créé avec succès."),
new ApiResponse<>(true, structurePaylaodWeb, "Structure créé avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
@@ -64,10 +65,10 @@ public class StructureController {
}
@PutMapping("/update/{id}")
public ResponseEntity<?> updateStructure(@PathVariable Long id, @RequestBody Structure structure) {
public ResponseEntity<?> updateStructure(@PathVariable Long id, @RequestBody StructurePaylaodWeb structurePaylaodWeb) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, structureService.updateStructure(id, structure), "Structure mise à jour avec succès."),
new ApiResponse<>(true, structureService.updateStructure(id, structurePaylaodWeb), "Structure mise à jour avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
@@ -134,36 +135,6 @@ public class StructureController {
}
@GetMapping("/all-by-arrondissement")
public ResponseEntity<?> getAllStructureListByArrondissement(@RequestParam Long arrondissementId) {
try {
if (arrondissementService.getArrondissementById(arrondissementId).isPresent()) {
return new ResponseEntity<>(
new ApiResponse<>(true, structureService.getStructuresByArrondissement(arrondissementId), "Liste des structures chargée avec succès."),
HttpStatus.OK
);
} else {
return new ResponseEntity<>(
new ApiResponse<>(false, "Impossible de trouver l'arrondissement spécifiée."),
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);
}
}
@GetMapping("/all-paged")
public ResponseEntity<?> getAllStructurePaged(@RequestParam int pageNo, @RequestParam int pageSize) {
try {
@@ -189,11 +160,58 @@ public class StructureController {
}
@GetMapping("/by-commune/{communeId}")
public ResponseEntity<?> getAllStructureListByCommune(@PathVariable Long communeId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, structureService.getStructureListByCommuneId(communeId), "Liste des structures 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);
}
}
@GetMapping("/page/by-commune/{communeId}")
public ResponseEntity<?> getAllStructureListByCommunePageable(@PathVariable Long communeId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
return new ResponseEntity<>(
new ApiResponse<>(true, structureService.getStructureListByCommuneId(communeId,pageable), "Liste des structures 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);
}
}
@GetMapping("/id/{id}")
public ResponseEntity<?> getStructureById(@PathVariable Long id) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, structureService.getStructureById(id), "Structure trouvé avec succès."),
new ApiResponse<>(true, structureService.getStructureByIdToDto(id), "Structure trouvé avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {

View File

@@ -11,6 +11,7 @@ import io.gmss.fiscad.paylaods.ApiResponse;
import io.gmss.fiscad.paylaods.JwtAuthenticationResponse;
import io.gmss.fiscad.paylaods.Login;
import io.gmss.fiscad.paylaods.UserRequest;
import io.gmss.fiscad.paylaods.request.crudweb.UserPaylaodWeb;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
@@ -90,13 +91,13 @@ public class AuthController {
}
@PostMapping("/signup")
public ResponseEntity<?> createUser(@RequestBody @Valid @Validated UserRequest userRequest) {
public ResponseEntity<?> createUser(@RequestBody @Valid @Validated UserPaylaodWeb userPaylaodWeb) {
try {
User user = getUser(userRequest);
user.setUsername(userRequest.getEmail());
user = userService.createUser(user, true);
//User user = getUser(userRequest);
//user.setUsername(userRequest.getEmail());
userPaylaodWeb = userService.createUser(userPaylaodWeb);
return new ResponseEntity<>(
new ApiResponse<>(true, user, "Inscription effectué avec succès."),
new ApiResponse<>(true, userPaylaodWeb, "Inscription effectué avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {

View File

@@ -39,9 +39,8 @@ public class AvoirFonctionController {
@PostMapping("/create")
public ResponseEntity<?> createAvoirFonction(@RequestBody @Valid @Validated AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb ) {
try {
AvoirFonction avoirFonction = avoirFonctionService.createAvoirFonction(avoirFonctionPaylaodWeb);
return new ResponseEntity<>(
new ApiResponse<>(true, avoirFonction, "Fonction utilisateur créée avec succès."),
new ApiResponse<>(true, avoirFonctionService.createAvoirFonction(avoirFonctionPaylaodWeb), "Fonction utilisateur créée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
@@ -131,52 +130,6 @@ public class AvoirFonctionController {
}
}
@GetMapping("/id/{id}")
public ResponseEntity<?> getById(@PathVariable Long id) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, avoirFonctionService.getAvoirFonctionById(id), "Fonction utilisateur trouvés 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);
}
}
@GetMapping("/utilisateur-id/{userId}")
public ResponseEntity<?> getByUserId(@PathVariable Long userId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, avoirFonctionService.getUserAvoirFonctionById(userId), "Fonctions de utilisateur trouvées 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);
}
}
@GetMapping("/all-paged")
public ResponseEntity<?> getAllPaged(@RequestParam int pageNo, @RequestParam int pageSize) {
@@ -203,4 +156,79 @@ public class AvoirFonctionController {
}
}
@GetMapping("/id/{id}")
public ResponseEntity<?> getById(@PathVariable Long id) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, avoirFonctionService.getAvoirFonctionById(id), "Fonction utilisateur trouvés 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);
}
}
@GetMapping("/by-utilisateur-id/{userId}")
public ResponseEntity<?> getByUserId(@PathVariable Long userId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, avoirFonctionService.getAvoirFonctionByUserId(userId), "Fonctions de utilisateur trouvées 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);
}
}
@GetMapping("/page/by-utilisateur-id/{userId}")
public ResponseEntity<?> getByUserIdPageable(@PathVariable Long userId,@RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
return new ResponseEntity<>(
new ApiResponse<>(true, avoirFonctionService.getAvoirFonctionByUserId(userId,pageable), "Fonctions de utilisateur trouvées 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);
}
}
}

View File

@@ -8,6 +8,7 @@ import io.gmss.fiscad.exceptions.*;
import io.gmss.fiscad.interfaces.user.UserService;
import io.gmss.fiscad.paylaods.ApiResponse;
import io.gmss.fiscad.paylaods.Login;
import io.gmss.fiscad.paylaods.request.crudweb.UserPaylaodWeb;
import io.gmss.fiscad.security.CurrentUser;
import io.gmss.fiscad.security.UserPrincipal;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -21,6 +22,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.HttpClientErrorException;
import java.util.Optional;
import java.util.Set;
@@ -40,12 +42,11 @@ public class UserController {
}
@PostMapping("/create")
public ResponseEntity<?> createUser(@RequestBody @Valid @Validated User user) {
public ResponseEntity<?> createUser(@RequestBody @Valid @Validated UserPaylaodWeb userPaylaodWeb) {
try {
user.setUsername(user.getEmail());
user = userService.createUser(user, true);
userPaylaodWeb = userService.createUser(userPaylaodWeb);
return new ResponseEntity<>(
new ApiResponse<>(true, user, "Utilisateur créé avec succès"),
new ApiResponse<>(true, userPaylaodWeb, "Utilisateur créé avec succès"),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
@@ -91,9 +92,9 @@ public class UserController {
@PostMapping("/reset-password")
public ResponseEntity<?> resetUserPassword(@RequestBody @Valid @Validated Login login) {
try {
User user = userService.resetPassword(login.getUsername(), login.getPassword());
UserPaylaodWeb userPaylaodWeb= userService.resetPassword(login.getUsername(), login.getPassword());
return new ResponseEntity<>(
new ApiResponse<>(true, user, "Votre mot de passe à été réinitialisée avec succès."),
new ApiResponse<>(true, userPaylaodWeb, "Votre mot de passe à été réinitialisée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
@@ -138,10 +139,10 @@ public class UserController {
@PutMapping("/update/{id}")
public ResponseEntity<?> updateUser(@PathVariable Long id, @RequestBody User user) {
public ResponseEntity<?> updateUser(@PathVariable Long id, @RequestBody UserPaylaodWeb userPaylaodWeb) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, userService.updateUser(id, user), "Utilisateur modifié avec succès."),
new ApiResponse<>(true, userService.updateUser(id, userPaylaodWeb), "Utilisateur modifié avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
@@ -343,26 +344,5 @@ public class UserController {
}
}
@GetMapping("/all-by-role/{userrole}")
public ResponseEntity<?> getUserByUserRole(@PathVariable UserRole userrole) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, userService.getUserByProfil(userrole), "Users found."),
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);
}
}
}

View File

@@ -49,7 +49,7 @@ public class Structure extends BaseEntity implements Serializable {
private String tel;
private String email;
private String adresse;
@NotNull
@NotNull(message = "Veuillez préciser la commune du centre d'impôts")
@ManyToOne
private Commune commune;

View File

@@ -30,6 +30,7 @@ public class SectionServiceImpl implements SectionService {
throw new BadRequestException("Impossible de créer une nouvelle section ayant un id non null.");
}
Section section= entityFromPayLoadService.getSectionFromPayLoadWeb(sectionPaylaodWeb);
section=sectionRepository.save(section);
return sectionRepository.findSectionToDtoById(section.getId()).orElse(null);
}
@@ -43,7 +44,7 @@ public class SectionServiceImpl implements SectionService {
throw new NotFoundException("Impossible de trouver le section spécifié.");
}
Section section= entityFromPayLoadService.getSectionFromPayLoadWeb(sectionPaylaodWeb);
sectionRepository.findSectionToDtoById(section.getId()).orElse(null);
section=sectionRepository.save(section);
return sectionRepository.findSectionToDtoById(section.getId()).orElse(null);
}

View File

@@ -1,60 +1,86 @@
package io.gmss.fiscad.implementations.infocad.parametre;
import io.gmss.fiscad.entities.decoupage.Section;
import io.gmss.fiscad.entities.infocad.parametre.Structure;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.interfaces.infocad.parametre.StructureService;
import io.gmss.fiscad.paylaods.request.crudweb.StructurePaylaodWeb;
import io.gmss.fiscad.paylaods.response.StructureResponse;
import io.gmss.fiscad.persistence.repositories.infocad.parametre.StructureRepository;
import io.gmss.fiscad.service.EntityFromPayLoadService;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@AllArgsConstructor
@Service
public class StructureServiceImpl implements StructureService {
private final StructureRepository structureRepository;
private final EntityFromPayLoadService entityFromPayLoadService;
public StructureServiceImpl(StructureRepository structureRepository) {
this.structureRepository = structureRepository;
}
// @Override
// public StructurePaylaodWeb createStructure(StructurePaylaodWeb structurePaylaodWeb) throws BadRequestException {
// if (structure.getId() != null) {
// throw new BadRequestException("Impossible de créer une structure ayant un id non null.");
// }
// StringBuilder builder = new StringBuilder();
// builder.append("C");
// builder.append(structureRepository.getLastRecordId() + 1);
// structure.setCode(builder.toString());
// return structureRepository.save(structure);
// }
//
// @Override
// public Structure updateStructure(Long id, Structure structure) throws NotFoundException {
//
// System.out.println("structure = " + structure);
//
// if (structure.getId() == null) {
// throw new BadRequestException("Impossible de mettre à jour une structure ayant un id null.");
// }
// if (!structureRepository.existsById(structure.getId())) {
// throw new NotFoundException("Impossible de trouver la structure spécifiée dans notre base de données.");
// }
// try {
// structureRepository.save(structure);
//
// }catch (Exception e){
// e.printStackTrace();
// }
//
// Structure structure1 = structureRepository.getById(structure.getId());
//
// return structure1;
// }
//
@Override
public Structure createStructure(Structure structure) throws BadRequestException {
if (structure.getId() != null) {
throw new BadRequestException("Impossible de créer une structure ayant un id non null.");
public StructurePaylaodWeb createStructure(StructurePaylaodWeb structurePaylaodWeb) throws BadRequestException {
if (structurePaylaodWeb.getId() != null) {
throw new BadRequestException("Impossible de créer un nouveau centre ayant un id non null.");
}
StringBuilder builder = new StringBuilder();
builder.append("C");
builder.append(structureRepository.getLastRecordId() + 1);
structure.setCode(builder.toString());
return structureRepository.save(structure);
}
@Override
public Structure updateStructure(Long id, Structure structure) throws NotFoundException {
System.out.println("structure = " + structure);
if (structure.getId() == null) {
throw new BadRequestException("Impossible de mettre à jour une structure ayant un id null.");
}
if (!structureRepository.existsById(structure.getId())) {
throw new NotFoundException("Impossible de trouver la structure spécifiée dans notre base de données.");
}
try {
Structure structure= entityFromPayLoadService.getStructureFromPayLoadWeb(structurePaylaodWeb);
structureRepository.save(structure);
}catch (Exception e){
e.printStackTrace();
return structureRepository.findStructureToDtoById(structure.getId()).orElse(null);
}
Structure structure1 = structureRepository.getById(structure.getId());
@Override
public StructurePaylaodWeb updateStructure(Long id, StructurePaylaodWeb structurePaylaodWeb) throws NotFoundException {
if (structurePaylaodWeb.getId() == null) {
throw new BadRequestException("Impossible de mettre à jour un nouveau centre ayant un id null.");
}
return structure1;
if (!structureRepository.existsById(structurePaylaodWeb.getId())) {
throw new NotFoundException("Impossible de trouver le centre spécifiée.");
}
Structure structure= entityFromPayLoadService.getStructureFromPayLoadWeb(structurePaylaodWeb);
structure = structureRepository.save(structure);
// structureRepository.findStructureToDtoById(structure.getId()).orElse(null);
return structureRepository.findStructureToDtoById(structure.getId()).orElse(null);
}
@Override
@@ -68,18 +94,28 @@ public class StructureServiceImpl implements StructureService {
}
@Override
public Page<Structure> getStructureList(Pageable pageable) {
return structureRepository.findAll(pageable);
public Page<StructurePaylaodWeb> getStructureList(Pageable pageable) {
return structureRepository.findAllStructureToDtoPageable(pageable);
}
@Override
public List<Structure> getStructureList() {
return structureRepository.findAll();
public List<StructurePaylaodWeb> getStructureList() {
return structureRepository.findAllStructureToDto();
}
@Override
public List<StructureResponse> getStructuresByArrondissement(Long arrondissementID) {
return structureRepository.getStructureByArrondissement(arrondissementID);
public List<StructurePaylaodWeb> getStructureListByCommuneId(Long communeId) {
return structureRepository.findAllStructureByCommuneToDto(communeId);
}
@Override
public Page<StructurePaylaodWeb> getStructureListByCommuneId(Long communeId, Pageable pageable) {
return structureRepository.findAllStructureByCommuneToDtoPageable(communeId,pageable);
}
@Override
public Optional<StructurePaylaodWeb> getStructureByIdToDto(Long id) {
return structureRepository.findStructureToDtoById(id);
}
@Override

View File

@@ -22,25 +22,27 @@ public class AvoirFonctionServiceImpl implements AvoirFonctionService {
private final EntityFromPayLoadService entityFromPayLoadService ;
@Override
public AvoirFonction createAvoirFonction(AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb) throws BadRequestException {
public AvoirFonctionPaylaodWeb createAvoirFonction(AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb) throws BadRequestException {
if (avoirFonctionPaylaodWeb.getId() != null) {
throw new BadRequestException("A new avoirFonction id to save must be null or empty.");
}
AvoirFonction avoirFonction = entityFromPayLoadService.getAvoirFonctionFromPayLoadWeb(avoirFonctionPaylaodWeb);
return avoirFonctionRepository.save(avoirFonction);
AvoirFonction avoirFonction= entityFromPayLoadService.getAvoirFonctionFromPayLoadWeb(avoirFonctionPaylaodWeb);
avoirFonction=avoirFonctionRepository.save(avoirFonction);
return avoirFonctionRepository.findAvoirFonctionToDtoById(avoirFonction.getId()).orElse(null);
}
@Override
public AvoirFonction updateAvoirFonction(Long id, AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb) throws NotFoundException {
public AvoirFonctionPaylaodWeb updateAvoirFonction(Long id, AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb) throws NotFoundException {
if (avoirFonctionPaylaodWeb.getId() == null) {
throw new BadRequestException("A new avoirFonction id to save must be null or empty.");
throw new BadRequestException("La fonction utilisateur à modifier n'est pas précisée");
}
Optional<AvoirFonction> optionalAvoirFonction= avoirFonctionRepository.findAvoirFonctionById(avoirFonctionPaylaodWeb.getId());
Optional<AvoirFonction> optionalAvoirFonction= avoirFonctionRepository.findById(avoirFonctionPaylaodWeb.getId());
if(optionalAvoirFonction.isEmpty()){
throw new BadRequestException("Impossible de trouver la Fonction utilisateur à modifier");
}
AvoirFonction avoirFonction = entityFromPayLoadService.getAvoirFonctionFromPayLoadWeb(avoirFonctionPaylaodWeb);
return avoirFonctionRepository.save(avoirFonction);
AvoirFonction avoirFonction= entityFromPayLoadService.getAvoirFonctionFromPayLoadWeb(avoirFonctionPaylaodWeb);
avoirFonction=avoirFonctionRepository.save(avoirFonction);
return avoirFonctionRepository.findAvoirFonctionToDtoById(avoirFonction.getId()).orElse(null);
}
@Override
@@ -48,7 +50,7 @@ public class AvoirFonctionServiceImpl implements AvoirFonctionService {
if (id == null) {
throw new BadRequestException("Impossible de supprimer un avoirFonction null ");
}
Optional<AvoirFonction> optionalAvoirFonction= avoirFonctionRepository.findAvoirFonctionById(id);
Optional<AvoirFonction> optionalAvoirFonction= avoirFonctionRepository.findById(id);
if(optionalAvoirFonction.isEmpty()){
throw new BadRequestException("Impossible de trouver le avoirFonction à supprimer");
}
@@ -56,25 +58,28 @@ public class AvoirFonctionServiceImpl implements AvoirFonctionService {
}
@Override
public Page<AvoirFonction> getAvoirFonctionList(Pageable pageable) {
return avoirFonctionRepository.findAll(pageable);
public Page<AvoirFonctionPaylaodWeb> getAvoirFonctionList(Pageable pageable) {
return avoirFonctionRepository.findAllAvoirFonctionToDtoPageable(pageable);
}
@Override
public List<AvoirFonction> getAvoirFonctionList() {
return avoirFonctionRepository.findAll();
}
@Override
public Optional<AvoirFonction> getAvoirFonctionById(Long id) {
return avoirFonctionRepository.findAvoirFonctionById(id);
public List<AvoirFonctionPaylaodWeb> getAvoirFonctionList() {
return avoirFonctionRepository.findAllAvoirFonctionToDto();
}
@Override
public List<AvoirFonction> getUserAvoirFonctionById(Long userId) {
return avoirFonctionRepository.findAvoirFonctionByUser_Id(userId);
public Optional<AvoirFonctionPaylaodWeb> getAvoirFonctionById(Long id) {
return avoirFonctionRepository.findAvoirFonctionToDtoById(id);
}
@Override
public List<AvoirFonctionPaylaodWeb> getAvoirFonctionByUserId(Long userId) {
return avoirFonctionRepository.findAllAvoirFonctionByUserToDto(userId);
}
@Override
public Page<AvoirFonctionPaylaodWeb> getAvoirFonctionByUserId(Long userId, Pageable pageable) {
return avoirFonctionRepository.findAllAvoirFonctionByUserToDtoPageable(userId,pageable);
}
}

View File

@@ -12,8 +12,11 @@ import io.gmss.fiscad.paylaods.JwtAuthenticationResponse;
import io.gmss.fiscad.paylaods.Login;
import io.gmss.fiscad.paylaods.UserListByStructureResponse;
import io.gmss.fiscad.paylaods.UserResponse;
import io.gmss.fiscad.paylaods.request.crudweb.UserPaylaodWeb;
import io.gmss.fiscad.persistence.repositories.user.UserRepository;
import io.gmss.fiscad.security.TokenAuthentificationProvider;
import io.gmss.fiscad.service.EntityFromPayLoadService;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.authentication.AuthenticationManager;
@@ -26,7 +29,7 @@ import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
@AllArgsConstructor
@Service
public class UserServiceImpl implements UserService {
@@ -36,42 +39,28 @@ public class UserServiceImpl implements UserService {
private final AuthenticationManager authenticationManager;
private final TokenAuthentificationProvider tokenAuthentificationProvider;
private final StructureService structureService;
private final EntityFromPayLoadService entityFromPayLoadService;
public UserServiceImpl(UserRepository userRepository, PasswordEncoder passwordEncoder, RoleService roleService, AuthenticationManager authenticationManager, TokenAuthentificationProvider tokenAuthentificationProvider, StructureService structureService) {
this.userRepository = userRepository;
this.passwordEncoder = passwordEncoder;
this.roleService = roleService;
this.authenticationManager = authenticationManager;
this.tokenAuthentificationProvider = tokenAuthentificationProvider;
this.structureService = structureService;
}
@Override
public User createUser(User user, boolean resetPassword) {
public UserPaylaodWeb createUser(UserPaylaodWeb userPaylaodWeb) {
if (userRepository.findByUsername(user.getUsername()).isPresent()) {
throw new BadRequestException("Ce nom d'utilisateur existe déjà.");
if ((userRepository.findByUsername(userPaylaodWeb.getLogin()).isPresent())
|| (userRepository.findByEmail(userPaylaodWeb.getEmail()).isPresent())) {
throw new BadRequestException("Cet utilisateur existe déjà.");
}
if (userPaylaodWeb.getId() != null) {
throw new BadRequestException("Cet utilisateur existe déjà.");
}
if (user.getId() != null) {
throw new BadRequestException("Cet utilisateur existe déjà dans la base de donnéees.");
}
// Set<Role> roleSet = new HashSet<>();
// user.getRoles().stream().forEach(role -> {
// if (roleService.roleExistByRoleName(role.getNom())) {
// roleSet.add(roleService.retrieveRoleByRoleName(role.getNom()));
// }
// });
user.setUsername(user.getEmail());
user.setResetPassword(resetPassword);
// user.setRoles(roleSet);
user.setPassword(passwordEncoder.encode(user.getPassword()));
User user = entityFromPayLoadService.getUserFromPayLoadWeb(userPaylaodWeb);
user.setPassword(passwordEncoder.encode(userPaylaodWeb.getPassword()));
userRepository.save(user);
return user;
return userPaylaodWeb;
}
@Override
@@ -98,29 +87,23 @@ public class UserServiceImpl implements UserService {
}
@Override
public User updateUser(Long id, User user) {
User user1 = userRepository.findById(id)
.orElseThrow(() -> new NotFoundException(
String.format("L'utilisateur ayant pour id %s n'existe pas.", id)
)
);
// if (user.getRoles() == null || user.getRoles().isEmpty()) {
// user.setRoles(user1.getRoles());
// }
public UserPaylaodWeb updateUser(Long id, UserPaylaodWeb userPaylaodWeb) {
if (user.getPassword() == null || user.getPassword().isBlank()) {
user.setPassword(user1.getPassword());
} else {
user.setPassword(passwordEncoder.encode(user.getPassword()));
if ((userRepository.findByUsername(userPaylaodWeb.getLogin()).isEmpty())
|| (userRepository.findByEmail(userPaylaodWeb.getEmail()).isEmpty())) {
throw new BadRequestException("Cet utilisateur n'existe pas.");
}
if (user.getEmail() == null || user.getEmail().isEmpty()) {
user.setEmail(user1.getEmail());
} else {
user.setEmail(user.getEmail());
if (userPaylaodWeb.getId() == null) {
throw new BadRequestException("Cet utilisateur n'existe déjà.");
}
user.setResetPassword(user1.isResetPassword());
return userRepository.save(user);
if(userRepository.findUserToDtoById(userPaylaodWeb.getId()).isEmpty()){
throw new BadRequestException("Cet utilisateur n'existe pas.");
}
User user = entityFromPayLoadService.getUserFromPayLoadWeb(userPaylaodWeb);
user.setActive(true);
user.setResetPassword(false);
userRepository.save(user);
return userRepository.findUserToDtoById(userPaylaodWeb.getId()).orElse(null);
}
@Override
@@ -145,43 +128,29 @@ public class UserServiceImpl implements UserService {
}
@Override
public Page<User> getUserList(Pageable pageable) {
return userRepository.findAll(pageable);
public Page<UserPaylaodWeb> getUserList(Pageable pageable) {
return userRepository.findAllUserToDtoPageable(pageable);
}
@Override
public List<User> getUserList() {
return userRepository.findAll();
public List<UserPaylaodWeb> getUserList() {
return userRepository.findAllUserToDto();
}
@Override
public List<UserResponse> getAllUserListResponse() {
return getUserResponses(getUserList());
return null ;//getUserResponses(getUserList());
}
@Override
public List<User> getActivatedUserListByStructure(Long structureId) {
// Set<Role> roleSet = new HashSet<>();
// roleSet.add(roleService.retrieveRoleByRoleName(UserRole.ROLE_ANONYMOUS));
// Optional<Structure> structureOptional = structureService.getStructureById(structureId);
// if (structureOptional.isPresent()) {
// return userRepository.findAllByStructureAndRolesNotIn(structureOptional.get(), roleSet);
// } else {
// throw new NotFoundException("Impossible de trouver la structure spécifiée.");
// }
return null;
}
@Override
public List<User> getUserUnActivatedListByStructure(Long structureId) {
// Set<Role> roleSet = new HashSet<>();
// roleSet.add(roleService.retrieveRoleByRoleName(UserRole.ROLE_ANONYMOUS));
// Optional<Structure> structureOptional = structureService.getStructureById(structureId);
// if (structureOptional.isPresent()) {
// return userRepository.findAllByStructureAndRolesIn(structureOptional.get(), roleSet);
// } else {
// throw new NotFoundException("Impossible de trouver la structure spécifiée.");
// }
return null;
}
@@ -215,15 +184,9 @@ public class UserServiceImpl implements UserService {
String.format("L'utilisateur ayant pour id %s n'existe pas.", id)
)
);
}
@Override
public List<User> getUserByProfil(UserRole userRole) {
//return userRepository.findAllByRolesContains(userRole);
return null;
}
@Override
public User getUserByUsername(String username) {
return userRepository.findByUsername(username).orElseThrow(() -> new NotFoundException(
@@ -246,15 +209,15 @@ public class UserServiceImpl implements UserService {
}
@Override
public User resetPassword(String username, String password) {
public UserPaylaodWeb resetPassword(String username, String password) {
User user = userRepository.findByUsername(username).orElseThrow(() -> new NotFoundException(
String.format("L'utilisateur %s n'existe pas.", username)
));
//String pwd = PasswordGenerator.generatePassword();
user.setPassword(passwordEncoder.encode(password));
user.setResetPassword(true);
userRepository.save(user);
return user;
user= userRepository.save(user);
Optional<UserPaylaodWeb> optionalUserPaylaodWeb = userRepository.findUserToDtoById(user.getId());
return optionalUserPaylaodWeb.orElse(null);
}
@Override
@@ -267,11 +230,6 @@ public class UserServiceImpl implements UserService {
User user = userRepository.findByUsername(username).orElseThrow(() -> new NotFoundException(
String.format("L'utilisateur %s n'existe pas.", username)
));
// Set<Role> roleSet = new HashSet<>();
// if (roleService.roleExistByRoleName(userRole)) {
// roleSet.add(roleService.retrieveRoleByRoleName(userRole));
// }
//user.setRoles(roleSet);
user.setResetPassword(false);
return userRepository.save(user);
}
@@ -307,19 +265,4 @@ public class UserServiceImpl implements UserService {
}
// private static List<UserResponse> getUserResponses(List<User> users) {
// return users.stream()
// .map(user -> new UserResponse(
// user.getId(),
// user.getNom(),
// user.getPrenom(),
// user.getTel(),
// user.getEmail(),
// user.getUsername(),
// user.isActive(),
// user.isResetPassword(),
// user.getRoles(),
// user.getStructure()))
// .collect(Collectors.toList());
// }
}

View File

@@ -3,6 +3,7 @@ package io.gmss.fiscad.interfaces.infocad.parametre;
import io.gmss.fiscad.entities.infocad.parametre.Structure;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.paylaods.request.crudweb.StructurePaylaodWeb;
import io.gmss.fiscad.paylaods.response.StructureResponse;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -12,17 +13,30 @@ import java.util.Optional;
public interface StructureService {
Structure createStructure(Structure structure) throws BadRequestException;
// Structure createStructure(Structure structure) throws BadRequestException;
//
// Structure updateStructure(Long id, Structure structure) throws NotFoundException;
//
// void deleteStructure(Long id) throws NotFoundException;
//
// Page<Structure> getStructureList(Pageable pageable);
//
// List<Structure> getStructureList();
StructurePaylaodWeb createStructure(StructurePaylaodWeb structurePaylaodWeb) throws BadRequestException;
Structure updateStructure(Long id, Structure structure) throws NotFoundException;
StructurePaylaodWeb updateStructure(Long id, StructurePaylaodWeb structurePaylaodWeb) throws NotFoundException;
void deleteStructure(Long id) throws NotFoundException;
Page<Structure> getStructureList(Pageable pageable);
Page<StructurePaylaodWeb> getStructureList(Pageable pageable);
List<StructurePaylaodWeb> getStructureList();
List<StructurePaylaodWeb> getStructureListByCommuneId(Long structureId);
Page<StructurePaylaodWeb> getStructureListByCommuneId(Long structureId,Pageable pageable);
List<Structure> getStructureList();
Optional<StructurePaylaodWeb> getStructureByIdToDto(Long id);
List<StructureResponse> getStructuresByArrondissement(Long arrondissementID);
//List<StructureResponse> getStructuresByArrondissement(Long arrondissementID);
Optional<Structure> getStructureById(Long id);
}

View File

@@ -12,17 +12,18 @@ import java.util.Optional;
public interface AvoirFonctionService {
AvoirFonction createAvoirFonction(AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb) throws BadRequestException;
AvoirFonctionPaylaodWeb createAvoirFonction(AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb) throws BadRequestException;
AvoirFonction updateAvoirFonction(Long id, AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb) throws NotFoundException;
AvoirFonctionPaylaodWeb updateAvoirFonction(Long id, AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb) throws NotFoundException;
void deleteAvoirFonction(Long id) throws NotFoundException;
Page<AvoirFonction> getAvoirFonctionList(Pageable pageable);
Page<AvoirFonctionPaylaodWeb> getAvoirFonctionList(Pageable pageable);
List<AvoirFonction> getAvoirFonctionList();
List<AvoirFonctionPaylaodWeb> getAvoirFonctionList();
Optional<AvoirFonction> getAvoirFonctionById(Long id);
List<AvoirFonction> getUserAvoirFonctionById(Long userId);
Optional<AvoirFonctionPaylaodWeb> getAvoirFonctionById(Long id);
List<AvoirFonctionPaylaodWeb> getAvoirFonctionByUserId(Long userId);
Page<AvoirFonctionPaylaodWeb> getAvoirFonctionByUserId(Long userId,Pageable pageable);
}

View File

@@ -7,26 +7,26 @@ import io.gmss.fiscad.paylaods.JwtAuthenticationResponse;
import io.gmss.fiscad.paylaods.Login;
import io.gmss.fiscad.paylaods.UserListByStructureResponse;
import io.gmss.fiscad.paylaods.UserResponse;
import io.gmss.fiscad.paylaods.request.crudweb.UserPaylaodWeb;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
public interface UserService {
User createUser(User user, boolean resetPassword);
UserPaylaodWeb createUser(UserPaylaodWeb userPaylaodWeb);
JwtAuthenticationResponse loginUser(Login login);
User updateUser(Long id, User user);
UserPaylaodWeb updateUser(Long id, UserPaylaodWeb userPaylaodWeb);
void updatePassword(String username, String pwd);
void deleteUser(Long id);
Page<User> getUserList(Pageable pageable);
Page<UserPaylaodWeb> getUserList(Pageable pageable);
List<User> getUserList();
List<UserPaylaodWeb> getUserList();
List<UserResponse> getAllUserListResponse();
@@ -42,7 +42,7 @@ public interface UserService {
User activateOrNotUser(Long id);
User resetPassword(String username, String password);
UserPaylaodWeb resetPassword(String username, String password);
User assignStructureToUser(Structure structure);
@@ -54,6 +54,5 @@ public interface UserService {
UserResponse getUserResponseFromUser(User user);
List<User> getUserByProfil(UserRole userRole);
}

View File

@@ -20,9 +20,41 @@ public class AvoirFonctionPaylaodWeb {
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateFin;
private Long fonctionId;
private String fonctionCode;
private String fonctionNom;
private Long userId ;
private Long userNom ;
@Enumerated(EnumType.STRING)
private String userLogin ;
private String userNom ;
private String userPrenom ;
private String email ;
//@Enumerated(EnumType.STRING)
private Titre titre;
public AvoirFonctionPaylaodWeb(
Long id,
LocalDate dateDebut,
LocalDate dateFin,
Long fonctionId,
String fonctionCode,
String fonctionNom,
Long userId,
String userLogin,
String userNom,
String userPrenom,
String email,
Titre titre)
{
this.id = id;
this.dateDebut = dateDebut;
this.dateFin = dateFin;
this.fonctionId = fonctionId;
this.fonctionCode = fonctionCode;
this.fonctionNom = fonctionNom;
this.userId = userId;
this.userLogin = userLogin;
this.userNom = userNom;
this.userPrenom = userPrenom;
this.email = email;
this.titre = titre;
}
}

View File

@@ -0,0 +1,36 @@
package io.gmss.fiscad.paylaods.request.crudweb;
import io.gmss.fiscad.entities.decoupage.Commune;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Data
public class StructurePaylaodWeb {
private Long id;
private String code ;
private String nom ;
private Long communeId ;
private String communeCode ;
private String communeNom ;
private String ifu;
private String rccm;
private String tel;
private String email;
private String adresse;
public StructurePaylaodWeb(Long id, String code, String nom, Long communeId, String communeCode, String communeNom, String ifu, String rccm, String tel, String email, String adresse) {
this.id = id;
this.code = code;
this.nom = nom;
this.communeId = communeId;
this.communeCode = communeCode;
this.communeNom = communeNom;
this.ifu = ifu;
this.rccm = rccm;
this.tel = tel;
this.email = email;
this.adresse = adresse;
}
}

View File

@@ -0,0 +1,43 @@
package io.gmss.fiscad.paylaods.request.crudweb;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.gmss.fiscad.deserializer.LocalDateDeserializer;
import io.gmss.fiscad.enums.Titre;
import lombok.Data;
import java.time.LocalDate;
@Data
public class UserPaylaodWeb {
private Long id;
private String nom;
private String prenom;
private String telephone;
private String login;
private String email;
private String password;
private Long structureId;
private String structureCode;
private String structureNom;
public UserPaylaodWeb(Long id,
String nom,
String prenom,
String telephone,
String login,
String email,
Long structureId,
String structureCode,
String structureNom) {
this.id = id;
this.nom = nom;
this.prenom = prenom;
this.telephone = telephone;
this.login = login;
this.email = email;
this.structureId = structureId;
this.structureCode = structureCode;
this.structureNom = structureNom;
}
}

View File

@@ -1,13 +1,18 @@
package io.gmss.fiscad.persistence.repositories.infocad.parametre;
import io.gmss.fiscad.entities.infocad.parametre.Structure;
import io.gmss.fiscad.paylaods.request.crudweb.StructurePaylaodWeb;
import io.gmss.fiscad.paylaods.response.ArrondissementEnqResponse;
import io.gmss.fiscad.paylaods.response.StructureEnqResponse;
import io.gmss.fiscad.paylaods.response.StructureResponse;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
import java.util.Optional;
public interface StructureRepository extends JpaRepository<Structure, Long> {
boolean existsDistinctByCode(String code);
@@ -54,4 +59,119 @@ public interface StructureRepository extends JpaRepository<Structure, Long> {
group by s.id,s.code,s.nom,c.id ;
""", nativeQuery = true)
List<StructureEnqResponse> getStructureEnqResponse(Long structure_id);
@Query("""
SELECT new io.gmss.fiscad.paylaods.request.crudweb.StructurePaylaodWeb(
st.id,
st.code,
st.nom,
c.id,
c.code,
c.nom,
st.ifu,
st.rccm,
st.tel,
st.email,
st.adresse
)
FROM Structure st
LEFT JOIN st.commune c
""")
List<StructurePaylaodWeb> findAllStructureToDto();
@Query("""
SELECT new io.gmss.fiscad.paylaods.request.crudweb.StructurePaylaodWeb(
st.id,
st.code,
st.nom,
c.id,
c.code,
c.nom,
st.ifu,
st.rccm,
st.tel,
st.email,
st.adresse
)
FROM Structure st
LEFT JOIN st.commune c
WHERE st.id = :idStructure
""")
Optional<StructurePaylaodWeb> findStructureToDtoById(@Param("idStructure") Long idStructure);
@Query(
value = """
SELECT new io.gmss.fiscad.paylaods.request.crudweb.StructurePaylaodWeb(
st.id,
st.code,
st.nom,
c.id,
c.code,
c.nom,
st.ifu,
st.rccm,
st.tel,
st.email,
st.adresse
)
FROM Structure st
LEFT JOIN st.commune c
""",
countQuery = """
SELECT COUNT(DISTINCT st.id)
FROM Structure st
LEFT JOIN st.commune c
"""
)
Page<StructurePaylaodWeb> findAllStructureToDtoPageable(Pageable pageable);
@Query("""
SELECT new io.gmss.fiscad.paylaods.request.crudweb.StructurePaylaodWeb(
st.id,
st.code,
st.nom,
c.id,
c.code,
c.nom,
st.ifu,
st.rccm,
st.tel,
st.email,
st.adresse
)
FROM Structure st
LEFT JOIN st.commune c
WHERE c.id = :communeId
""")
List<StructurePaylaodWeb> findAllStructureByCommuneToDto(@Param("communeId") Long communeId);
@Query(value = """
SELECT new io.gmss.fiscad.paylaods.request.crudweb.StructurePaylaodWeb(
st.id,
st.code,
st.nom,
c.id,
c.code,
c.nom,
st.ifu,
st.rccm,
st.tel,
st.email,
st.adresse
)
FROM Structure st
LEFT JOIN st.commune c
WHERE c.id = :communeId
""",
countQuery = """
SELECT COUNT(DISTINCT st.id)
FROM Structure st
LEFT JOIN st.commune c
WHERE c.id = :communeId
""")
Page<StructurePaylaodWeb> findAllStructureByCommuneToDtoPageable(@Param("communeId") Long communeId, Pageable pageable);
}

View File

@@ -1,14 +1,143 @@
package io.gmss.fiscad.persistence.repositories.user;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.gmss.fiscad.deserializer.LocalDateDeserializer;
import io.gmss.fiscad.entities.user.AvoirFonction;
import io.gmss.fiscad.entities.user.AvoirFonction;
import io.gmss.fiscad.enums.Titre;
import io.gmss.fiscad.paylaods.request.crudweb.AvoirFonctionPaylaodWeb;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
public interface AvoirFonctionRepository extends JpaRepository<AvoirFonction, Long> {
Optional<AvoirFonction> findAvoirFonctionById(Long id);
List<AvoirFonction> findAvoirFonctionByUser_Id(Long userId);
@Query("""
SELECT new io.gmss.fiscad.paylaods.request.crudweb.AvoirFonctionPaylaodWeb(
af.id,
af.dateDebut,
af.dateFin,
f.id,
f.code,
f.nom,
u.id,
u.username,
u.nom,
u.prenom,
u.email,
af.titre
)
FROM AvoirFonction af
LEFT JOIN af.user u
LEFT JOIN af.fonction f
""")
List<AvoirFonctionPaylaodWeb> findAllAvoirFonctionToDto();
@Query("""
SELECT new io.gmss.fiscad.paylaods.request.crudweb.AvoirFonctionPaylaodWeb(
af.id,
af.dateDebut,
af.dateFin,
f.id,
f.code,
f.nom,
u.id,
u.username,
u.nom,
u.prenom,
u.email,
af.titre
)
FROM AvoirFonction af
LEFT JOIN af.user u
LEFT JOIN af.fonction f
WHERE af.id = :idAvoirFonction
""")
Optional<AvoirFonctionPaylaodWeb> findAvoirFonctionToDtoById(@Param("idAvoirFonction") Long idAvoirFonction);
@Query(
value = """
SELECT new io.gmss.fiscad.paylaods.request.crudweb.AvoirFonctionPaylaodWeb(
af.id,
af.dateDebut,
af.dateFin,
f.id,
f.code,
f.nom,
u.id,
u.username,
u.nom,
u.prenom,
u.email,
af.titre
)
FROM AvoirFonction af
LEFT JOIN af.user u
LEFT JOIN af.fonction f
"""
)
Page<AvoirFonctionPaylaodWeb> findAllAvoirFonctionToDtoPageable(Pageable pageable);
@Query("""
SELECT new io.gmss.fiscad.paylaods.request.crudweb.AvoirFonctionPaylaodWeb(
af.id,
af.dateDebut,
af.dateFin,
f.id,
f.code,
f.nom,
u.id,
u.username,
u.nom,
u.prenom,
u.email,
af.titre
)
FROM AvoirFonction af
LEFT JOIN af.user u
LEFT JOIN af.fonction f
WHERE u.id = :userId
""")
List<AvoirFonctionPaylaodWeb> findAllAvoirFonctionByUserToDto(@Param("userId") Long userId);
@Query(value = """
SELECT new io.gmss.fiscad.paylaods.request.crudweb.AvoirFonctionPaylaodWeb(
af.id,
af.dateDebut,
af.dateFin,
f.id,
f.code,
f.nom,
u.id,
u.username,
u.nom,
u.prenom,
u.email,
af.titre
)
FROM AvoirFonction af
LEFT JOIN af.user u
LEFT JOIN af.fonction f
WHERE u.id = :userId
""",
countQuery = """
SELECT COUNT(DISTINCT af.id)
FROM AvoirFonction af
LEFT JOIN af.user u
LEFT JOIN af.fonction f
WHERE u.id = :userId
""")
Page<AvoirFonctionPaylaodWeb> findAllAvoirFonctionByUserToDtoPageable(@Param("userId") Long userId, Pageable pageable);
List<AvoirFonction> findAvoirFonctionByUser_Id(Long userId);
}

View File

@@ -4,7 +4,12 @@ import io.gmss.fiscad.entities.infocad.parametre.Structure;
import io.gmss.fiscad.entities.user.Role;
import io.gmss.fiscad.entities.user.User;
import io.gmss.fiscad.enums.UserRole;
import io.gmss.fiscad.paylaods.request.crudweb.UserPaylaodWeb;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
import java.util.Optional;
@@ -13,14 +18,114 @@ import java.util.Set;
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByUsername(String username);
Optional<User> findByEmail(String email);
boolean existsByUsername(String username);
long countAllByUsernameIsNotNull();
// List<User> findAllByStructureAndRolesIn(Structure structure, Set<Role> roleSet);
// List<User> findAllByStructureAndRolesNotIn(Structure structure, Set<Role> roleSet);
// List<User> findAllByRolesContains(UserRole userRole);
@Query("""
SELECT new io.gmss.fiscad.paylaods.request.crudweb.UserPaylaodWeb(
u.id,
u.nom,
u.prenom,
u.tel,
u.username,
u.email,
st.id,
st.code,
st.nom
)
FROM User u
LEFT JOIN u.structure st
""")
List<UserPaylaodWeb> findAllUserToDto();
@Query("""
SELECT new io.gmss.fiscad.paylaods.request.crudweb.UserPaylaodWeb(
u.id,
u.nom,
u.prenom,
u.tel,
u.username,
u.email,
st.id,
st.code,
st.nom
)
FROM User u
LEFT JOIN u.structure st
WHERE u.id = :idUser
""")
Optional<UserPaylaodWeb> findUserToDtoById(@Param("idUser") Long idUser);
@Query(
value = """
SELECT new io.gmss.fiscad.paylaods.request.crudweb.UserPaylaodWeb(
u.id,
u.nom,
u.prenom,
u.tel,
u.username,
u.email,
st.id,
st.code,
st.nom
)
FROM User u
LEFT JOIN u.structure st
""",
countQuery = """
SELECT COUNT(DISTINCT u.id)
FROM User u
LEFT JOIN u.structure st
"""
)
Page<UserPaylaodWeb> findAllUserToDtoPageable(Pageable pageable);
@Query("""
SELECT new io.gmss.fiscad.paylaods.request.crudweb.UserPaylaodWeb(
u.id,
u.nom,
u.prenom,
u.tel,
u.username,
u.email,
st.id,
st.code,
st.nom
)
FROM User u
LEFT JOIN u.structure st
WHERE st.id = :structureId
""")
List<UserPaylaodWeb> findAllUserByStructureToDto(@Param("structureId") Long structureId);
@Query(value = """
SELECT new io.gmss.fiscad.paylaods.request.crudweb.UserPaylaodWeb(
u.id,
u.nom,
u.prenom,
u.tel,
u.username,
u.email,
st.id,
st.code,
st.nom
)
FROM User u
LEFT JOIN u.structure st
WHERE st.id = :structureId
""",
countQuery = """
SELECT COUNT(DISTINCT u.id)
FROM User u
LEFT JOIN u.structure st
WHERE st.id = :structureId
""")
Page<UserPaylaodWeb> findAllUserByStructureToDtoPageable(@Param("structureId") Long structureId, Pageable pageable);
}

View File

@@ -238,6 +238,24 @@ public class EntityFromPayLoadService {
return section ;
}
public Structure getStructureFromPayLoadWeb(StructurePaylaodWeb structurePaylaodWeb){
Structure structure =new Structure();
Optional<Commune> optionalCommune = Optional.empty();
if(structurePaylaodWeb.getCommuneId()!=null)
optionalCommune=communeRepository.findById(structurePaylaodWeb.getCommuneId());
structure.setId(structurePaylaodWeb.getId());
structure.setCommune(optionalCommune.orElse(null));
structure.setCode(structurePaylaodWeb.getCode());
structure.setNom(structurePaylaodWeb.getNom());
structure.setAdresse(structurePaylaodWeb.getAdresse());
structure.setIfu(structurePaylaodWeb.getIfu());
structure.setEmail(structurePaylaodWeb.getEmail());
structure.setTel(structurePaylaodWeb.getTel());
return structure ;
}
public Secteur getSecteurFromPayLoadWeb(SecteurPaylaodWeb secteurPaylaodWeb){
Secteur secteur =new Secteur();
Optional<Section> optionalSection = Optional.empty();
@@ -427,4 +445,24 @@ public class EntityFromPayLoadService {
enqueteActivite.setChiffreAffaire(enqueteActivitePayLoadWeb.getChiffreAffaire());
return enqueteActivite ;
}
public User getUserFromPayLoadWeb(UserPaylaodWeb userPaylaodWeb){
User user =new User();
Optional<Structure> optionalStructure = Optional.empty();
if(userPaylaodWeb.getStructureId()!=null)
optionalStructure=structureRepository.findById(userPaylaodWeb.getStructureId());
user.setId(userPaylaodWeb.getId());
user.setStructure(optionalStructure.orElse(null));
user.setUsername(userPaylaodWeb.getLogin());
user.setEmail(userPaylaodWeb.getEmail());
user.setNom(userPaylaodWeb.getNom());
user.setPrenom(userPaylaodWeb.getPrenom());
user.setTel(userPaylaodWeb.getTelephone());
user.setActive(false);
user.setResetPassword(true);
return user ;
}
}