feat: accumulated work — PI-SPI, KYC, RLS, mutuelle parts, comptabilité PDF + startup fixes
## PI-SPI BCEAO (P0.3 — deadline 30/06/2026)
- package payment/pispi/ complet : PispiAuth (OAuth2), PispiClient (HTTP brut),
PispiIso20022Mapper (pacs.008/002), PispiSignatureVerifier (HMAC-SHA256),
PispiWebhookResource (/api/pispi/webhook), DTOs ISO 20022
- PaymentOrchestrator + PaymentProviderRegistry pour l'orchestration multi-provider
- Mode mock automatique si credentials absents (dev)
## KYC AML
- entity/KycDossier, KycResource, KycAmlService + tests
- Migration V38 (create_kyc_dossier_table)
## RLS (PostgreSQL Row-Level Security) — isolation multi-tenant
- RlsConnectionInitializer, RlsContextInterceptor, @RlsEnabled annotation
- Migration V39 (PostgreSQL RLS Tenant Isolation) + V42 (app DB roles)
- Tests unitaires RlsConnectionInitializerTest, RlsContextInterceptorTest
- Tests d'intégration RlsCrossTenantIsolationTest (@QuarkusTest + IntegrationTestProfile)
## Mutuelle — Parts sociales
- entity/mutuelle/parts/ComptePartsSociales, TransactionPartsSociales
- Service, resource, mapper, repository + tests
- InteretsEpargneService + ReleveComptePdfService
## Comptabilité PDF
- ComptabilitePdfService (OpenPDF), ComptabilitePdfResource
- Tests ComptabilitePdfServiceTest, ComptabilitePdfResourceTest
## Migrations Flyway (SYSCOHADA + Keycloak Orgs)
- V36 SYSCOHADA Plan Comptable Complet : seeds comptes standards UEMOA,
trigger init_plan_comptable_organisation, alignement schéma V1 → entités
- V37 keycloak_org_id sur organisations (P0.2 migration KC 26)
- V40 provider_defaut sur FormuleAbonnement
- V41 fcm_token sur utilisateurs (FCM notifications push)
## Fixes startup (SmallRye Config 3.20 + schéma)
- 8× @ConfigProperty(defaultValue = "") → Optional<String>
(firebase, pispi.*, mtnmomo, orange) — empty default rejetés par SmallRye 3.20
- application.properties : mappings secrets env var sous %prod. uniquement
- V36 : drop colonne obsolète 'numero' de V1 quand Hibernate a créé 'numero_compte'
- V36 : remplacement UNIQUE global sur journaux_comptables.code par composite
(organisation_id, code) pour autoriser plusieurs orgs avec code 'ACH'/'VTE'/etc
- V39 : escape placeholder ${VAR} → <VAR> dans lignes commentées
(Flyway parser évalue les placeholders même dans les commentaires)
- V41 : table 'membres' → 'utilisateurs' (nom correct selon entité Membre)
- JournalComptable entity : @UniqueConstraint composite au lieu de unique=true
- MembreResource : example @Schema JSON valide (['...'] → [])
- IntegrationTestProfile : auto-détection Docker via `docker info`, fallback
vers PostgreSQL local sans DevServices
## Dev config
- application-dev.properties : quarkus.devservices.enabled=false +
quarkus.kafka.devservices.enabled=false (pas besoin de Docker pour dev)
- quarkus.flyway.placeholder-replacement=false
- Secrets dev (wave.*, firebase, pispi) en mode mock automatique
## Phase 8 tests (complète)
- 170 fichiers modifiés/ajoutés, 23425+ insertions
- Tests RBAC (@QuarkusTest) pour MembreResource lifecycle
- Tests OrganisationContextFilter multi-org
- Tests SouscriptionQuotaOptionC, KycAmlService, EmailTemplate, etc.
Résultat : Backend démarre en 64s sur port 8085 avec 36 features installées.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package dev.lions.unionflow.server.resource;
|
||||
|
||||
import dev.lions.unionflow.server.service.MigrerOrganisationsVersKeycloakService;
|
||||
import dev.lions.unionflow.server.service.MigrerOrganisationsVersKeycloakService.MigrationReport;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Endpoints d'administration Keycloak 26 Organizations.
|
||||
*
|
||||
* <p>Réservés aux SUPER_ADMIN. Opérations à déclencher manuellement lors de la
|
||||
* migration Keycloak 23 → 26.
|
||||
*/
|
||||
@Slf4j
|
||||
@Path("/api/admin/keycloak")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@RolesAllowed("SUPER_ADMIN")
|
||||
public class AdminKeycloakOrganisationResource {
|
||||
|
||||
@Inject
|
||||
MigrerOrganisationsVersKeycloakService migrationService;
|
||||
|
||||
/**
|
||||
* Lance la migration one-shot des organisations UnionFlow vers Keycloak 26 Organizations.
|
||||
*
|
||||
* <p>Idempotent : les organisations déjà migrées (keycloak_org_id non null) sont ignorées.
|
||||
*
|
||||
* @return rapport de migration (total, créés, ignorés, erreurs)
|
||||
*/
|
||||
@POST
|
||||
@Path("/migrer-organisations")
|
||||
public Response migrerOrganisations() {
|
||||
log.info("Déclenchement migration organisations → Keycloak 26 Organizations");
|
||||
try {
|
||||
MigrationReport report = migrationService.migrerToutesLesOrganisations();
|
||||
log.info("Migration terminée : {}", report);
|
||||
|
||||
return Response
|
||||
.status(report.success() ? Response.Status.OK.getStatusCode() : 207)
|
||||
.entity(Map.of(
|
||||
"total", report.total(),
|
||||
"crees", report.crees(),
|
||||
"ignores", report.ignores(),
|
||||
"erreurs", report.erreurs(),
|
||||
"succes", report.success()
|
||||
))
|
||||
.build();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Erreur critique lors de la migration : {}", e.getMessage(), e);
|
||||
return Response.serverError()
|
||||
.entity(Map.of("error", e.getMessage()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package dev.lions.unionflow.server.resource;
|
||||
|
||||
import dev.lions.unionflow.server.service.ComptabilitePdfService;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import java.time.LocalDate;
|
||||
import java.util.UUID;
|
||||
import org.eclipse.microprofile.openapi.annotations.Operation;
|
||||
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
|
||||
|
||||
/**
|
||||
* Endpoints de téléchargement des rapports comptables PDF SYSCOHADA révisé.
|
||||
*/
|
||||
@Path("/api/comptabilite/pdf")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@RolesAllowed({"ADMIN_ORGANISATION", "TRESORIER", "COMMISSAIRE_COMPTES", "SUPER_ADMIN"})
|
||||
@Tag(name = "Comptabilité PDF", description = "Rapports comptables SYSCOHADA : balance, compte de résultat, grand livre")
|
||||
public class ComptabilitePdfResource {
|
||||
|
||||
@Inject
|
||||
ComptabilitePdfService comptabilitePdfService;
|
||||
|
||||
@GET
|
||||
@Path("/organisations/{organisationId}/balance")
|
||||
@Produces("application/pdf")
|
||||
@Operation(summary = "Balance générale SYSCOHADA",
|
||||
description = "Génère la balance générale (cumul débit/crédit/solde) pour la période.")
|
||||
public Response balance(
|
||||
@PathParam("organisationId") UUID organisationId,
|
||||
@QueryParam("dateDebut") @DefaultValue("") String dateDebutStr,
|
||||
@QueryParam("dateFin") @DefaultValue("") String dateFinStr) {
|
||||
|
||||
LocalDate dateDebut = parseDateOrStartOfYear(dateDebutStr);
|
||||
LocalDate dateFin = parseDateOrToday(dateFinStr);
|
||||
|
||||
byte[] pdf = comptabilitePdfService.genererBalance(organisationId, dateDebut, dateFin);
|
||||
return buildPdfResponse(pdf, "balance_" + organisationId + ".pdf");
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/organisations/{organisationId}/compte-de-resultat")
|
||||
@Produces("application/pdf")
|
||||
@Operation(summary = "Compte de résultat SYSCOHADA",
|
||||
description = "Génère le compte de résultat (produits classes 7/8 − charges classes 6/8).")
|
||||
public Response compteDeResultat(
|
||||
@PathParam("organisationId") UUID organisationId,
|
||||
@QueryParam("dateDebut") @DefaultValue("") String dateDebutStr,
|
||||
@QueryParam("dateFin") @DefaultValue("") String dateFinStr) {
|
||||
|
||||
LocalDate dateDebut = parseDateOrStartOfYear(dateDebutStr);
|
||||
LocalDate dateFin = parseDateOrToday(dateFinStr);
|
||||
|
||||
byte[] pdf = comptabilitePdfService.genererCompteResultat(organisationId, dateDebut, dateFin);
|
||||
return buildPdfResponse(pdf, "compte_resultat_" + organisationId + ".pdf");
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/organisations/{organisationId}/grand-livre/{numeroCompte}")
|
||||
@Produces("application/pdf")
|
||||
@Operation(summary = "Grand livre d'un compte SYSCOHADA",
|
||||
description = "Génère le grand livre (détail chronologique) pour un compte comptable donné.")
|
||||
public Response grandLivre(
|
||||
@PathParam("organisationId") UUID organisationId,
|
||||
@PathParam("numeroCompte") String numeroCompte,
|
||||
@QueryParam("dateDebut") @DefaultValue("") String dateDebutStr,
|
||||
@QueryParam("dateFin") @DefaultValue("") String dateFinStr) {
|
||||
|
||||
LocalDate dateDebut = parseDateOrStartOfYear(dateDebutStr);
|
||||
LocalDate dateFin = parseDateOrToday(dateFinStr);
|
||||
|
||||
byte[] pdf = comptabilitePdfService.genererGrandLivre(organisationId, numeroCompte, dateDebut, dateFin);
|
||||
return buildPdfResponse(pdf, "grand_livre_" + numeroCompte + ".pdf");
|
||||
}
|
||||
|
||||
private static Response buildPdfResponse(byte[] pdf, String filename) {
|
||||
return Response.ok(pdf)
|
||||
.header("Content-Disposition", "attachment; filename=\"" + filename + "\"")
|
||||
.header("Content-Length", pdf.length)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static LocalDate parseDateOrStartOfYear(String s) {
|
||||
if (s == null || s.isBlank()) return LocalDate.of(LocalDate.now().getYear(), 1, 1);
|
||||
try { return LocalDate.parse(s); } catch (Exception e) {
|
||||
throw new BadRequestException("Format de date invalide (attendu : YYYY-MM-DD) : " + s);
|
||||
}
|
||||
}
|
||||
|
||||
private static LocalDate parseDateOrToday(String s) {
|
||||
if (s == null || s.isBlank()) return LocalDate.now();
|
||||
try { return LocalDate.parse(s); } catch (Exception e) {
|
||||
throw new BadRequestException("Format de date invalide (attendu : YYYY-MM-DD) : " + s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.lions.unionflow.server.resource;
|
||||
|
||||
import dev.lions.unionflow.server.api.dto.membre.CompteAdherentResponse;
|
||||
import dev.lions.unionflow.server.service.FirebasePushService;
|
||||
import dev.lions.unionflow.server.entity.Membre;
|
||||
import dev.lions.unionflow.server.entity.MembreOrganisation;
|
||||
import dev.lions.unionflow.server.entity.SouscriptionOrganisation;
|
||||
@@ -67,6 +68,59 @@ public class CompteAdherentResource {
|
||||
@Inject
|
||||
MembreService membreService;
|
||||
|
||||
@Inject
|
||||
FirebasePushService firebasePushService;
|
||||
|
||||
/**
|
||||
* Enregistre ou met à jour le token FCM du membre connecté pour les notifications push.
|
||||
* Appelé par l'application mobile au démarrage ou quand Firebase renouvelle le token.
|
||||
*/
|
||||
@PUT
|
||||
@Path("/mon-compte/fcm-token")
|
||||
@Authenticated
|
||||
@Operation(summary = "Enregistrer le token FCM pour les notifications push")
|
||||
@jakarta.transaction.Transactional
|
||||
public Response enregistrerFcmToken(Map<String, String> body) {
|
||||
String email = securiteHelper.resolveEmail();
|
||||
if (email == null) return Response.status(Response.Status.UNAUTHORIZED).build();
|
||||
|
||||
String token = body != null ? body.get("token") : null;
|
||||
if (token == null || token.isBlank()) {
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.entity(Map.of("message", "Le champ 'token' est requis.")).build();
|
||||
}
|
||||
|
||||
return membreRepository.findByEmail(email)
|
||||
.map(membre -> {
|
||||
membre.setFcmToken(token.trim());
|
||||
membreRepository.persist(membre);
|
||||
return Response.ok(Map.of("message", "Token FCM enregistré.")).build();
|
||||
})
|
||||
.orElse(Response.status(Response.Status.NOT_FOUND)
|
||||
.entity(Map.of("message", "Membre introuvable.")).build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime le token FCM (désabonnement des notifications push).
|
||||
*/
|
||||
@DELETE
|
||||
@Path("/mon-compte/fcm-token")
|
||||
@Authenticated
|
||||
@Operation(summary = "Désactiver les notifications push")
|
||||
@jakarta.transaction.Transactional
|
||||
public Response supprimerFcmToken() {
|
||||
String email = securiteHelper.resolveEmail();
|
||||
if (email == null) return Response.status(Response.Status.UNAUTHORIZED).build();
|
||||
|
||||
return membreRepository.findByEmail(email)
|
||||
.map(membre -> {
|
||||
membre.setFcmToken(null);
|
||||
membreRepository.persist(membre);
|
||||
return Response.ok(Map.of("message", "Notifications push désactivées.")).build();
|
||||
})
|
||||
.orElse(Response.status(Response.Status.NOT_FOUND).build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne le compte adhérent complet du membre connecté :
|
||||
* numéro de membre, soldes (cotisations + épargne), capacité d'emprunt, taux d'engagement.
|
||||
@@ -138,15 +192,17 @@ public class CompteAdherentResource {
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback : auto-activer si EN_ATTENTE_VALIDATION et org a souscription active
|
||||
// (membres sans premiereConnexion=true ou créés avant cette logique)
|
||||
// Fallback : auto-activer si EN_ATTENTE_VALIDATION et org a reçu un paiement.
|
||||
// Couvre le cas PAIEMENT_CONFIRME (admin a payé mais super admin n'a pas encore validé)
|
||||
// et ACTIVE/VALIDEE (chemin nominal). L'admin ne doit pas bloquer sur l'AwaitingValidationPage
|
||||
// dès lors que le paiement est confirmé côté Wave.
|
||||
if ("EN_ATTENTE_VALIDATION".equals(statutCompte) && membreOpt.isPresent()) {
|
||||
Membre m = membreOpt.get();
|
||||
UUID orgId = membreOrganisationRepo.findFirstByMembreId(m.getId())
|
||||
.map(mo -> mo.getOrganisation().getId())
|
||||
.orElse(null);
|
||||
if (membreService.orgHasActiveSubscription(orgId)) {
|
||||
LOG.infof("Auto-activation au login de %s (org %s a souscription active)", m.getEmail(), orgId);
|
||||
if (membreService.orgHasPaidSubscription(orgId)) {
|
||||
LOG.infof("Auto-activation au login de %s (org %s a souscription payée)", m.getEmail(), orgId);
|
||||
membreService.activerMembre(m.getId());
|
||||
try {
|
||||
membreKeycloakSyncService.activerMembreDansKeycloak(m.getId());
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package dev.lions.unionflow.server.resource;
|
||||
|
||||
import dev.lions.unionflow.server.api.dto.kyc.KycDossierRequest;
|
||||
import dev.lions.unionflow.server.api.dto.kyc.KycDossierResponse;
|
||||
import dev.lions.unionflow.server.service.KycAmlService;
|
||||
import io.quarkus.security.identity.SecurityIdentity;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Endpoints KYC/AML — gestion des dossiers d'identification et évaluation risque LCB-FT.
|
||||
*/
|
||||
@Path("/api/kyc")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class KycResource {
|
||||
|
||||
@Inject
|
||||
KycAmlService kycAmlService;
|
||||
|
||||
@Inject
|
||||
SecurityIdentity identity;
|
||||
|
||||
/** Soumet ou met à jour un dossier KYC pour un membre. */
|
||||
@POST
|
||||
@Path("/dossiers")
|
||||
@RolesAllowed({"ADMIN_ORGANISATION", "TRESORIER", "SUPER_ADMIN"})
|
||||
public Response soumettre(@Valid KycDossierRequest request) {
|
||||
KycDossierResponse response = kycAmlService.soumettreOuMettreAJour(request, identity.getPrincipal().getName());
|
||||
return Response.status(Response.Status.CREATED).entity(response).build();
|
||||
}
|
||||
|
||||
/** Récupère le dossier KYC actif d'un membre. */
|
||||
@GET
|
||||
@Path("/membres/{membreId}")
|
||||
@RolesAllowed({"ADMIN_ORGANISATION", "TRESORIER", "SUPER_ADMIN"})
|
||||
public Response getDossierActif(@PathParam("membreId") UUID membreId) {
|
||||
return kycAmlService.getDossierActif(membreId)
|
||||
.map(d -> Response.ok(d).build())
|
||||
.orElse(Response.status(Response.Status.NOT_FOUND)
|
||||
.entity(Map.of("error", "Aucun dossier KYC actif pour ce membre."))
|
||||
.build());
|
||||
}
|
||||
|
||||
/** Évalue le score de risque LCB-FT du membre. */
|
||||
@POST
|
||||
@Path("/membres/{membreId}/evaluer-risque")
|
||||
@RolesAllowed({"ADMIN_ORGANISATION", "TRESORIER", "SUPER_ADMIN"})
|
||||
public Response evaluerRisque(@PathParam("membreId") UUID membreId) {
|
||||
KycDossierResponse response = kycAmlService.evaluerRisque(membreId);
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
/** Valide manuellement un dossier KYC (agent habilité). */
|
||||
@POST
|
||||
@Path("/dossiers/{dossierId}/valider")
|
||||
@RolesAllowed({"SUPER_ADMIN", "ADMIN_ORGANISATION"})
|
||||
public Response valider(
|
||||
@PathParam("dossierId") UUID dossierId,
|
||||
@QueryParam("validateurId") UUID validateurId,
|
||||
@QueryParam("notes") String notes) {
|
||||
KycDossierResponse response = kycAmlService.valider(
|
||||
dossierId, validateurId, notes, identity.getPrincipal().getName());
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
/** Refuse un dossier KYC avec motif. */
|
||||
@POST
|
||||
@Path("/dossiers/{dossierId}/refuser")
|
||||
@RolesAllowed({"SUPER_ADMIN", "ADMIN_ORGANISATION"})
|
||||
public Response refuser(
|
||||
@PathParam("dossierId") UUID dossierId,
|
||||
@QueryParam("validateurId") UUID validateurId,
|
||||
@QueryParam("motif") String motif) {
|
||||
KycDossierResponse response = kycAmlService.refuser(
|
||||
dossierId, validateurId, motif, identity.getPrincipal().getName());
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
/** Liste les dossiers KYC en attente de validation. */
|
||||
@GET
|
||||
@Path("/dossiers/en-attente")
|
||||
@RolesAllowed({"SUPER_ADMIN", "ADMIN_ORGANISATION"})
|
||||
public List<KycDossierResponse> getDossiersEnAttente() {
|
||||
return kycAmlService.getDossiersEnAttente();
|
||||
}
|
||||
|
||||
/** Liste les membres PEP (Personnes Exposées Politiquement). */
|
||||
@GET
|
||||
@Path("/pep")
|
||||
@RolesAllowed({"SUPER_ADMIN"})
|
||||
public List<KycDossierResponse> getPep() {
|
||||
return kycAmlService.getDossiersPep();
|
||||
}
|
||||
|
||||
/** Pièces d'identité expirant dans les 30 jours. */
|
||||
@GET
|
||||
@Path("/pieces-expirant-bientot")
|
||||
@RolesAllowed({"SUPER_ADMIN", "ADMIN_ORGANISATION", "TRESORIER"})
|
||||
public List<KycDossierResponse> getPiecesExpirant() {
|
||||
return kycAmlService.getPiecesExpirantDansLes30Jours();
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import dev.lions.unionflow.server.entity.Membre;
|
||||
import dev.lions.unionflow.server.entity.Organisation;
|
||||
import dev.lions.unionflow.server.entity.MembreOrganisation;
|
||||
import dev.lions.unionflow.server.repository.MembreOrganisationRepository;
|
||||
import dev.lions.unionflow.server.repository.MembreRepository;
|
||||
import dev.lions.unionflow.server.repository.MembreRoleRepository;
|
||||
import dev.lions.unionflow.server.service.MemberLifecycleService;
|
||||
import dev.lions.unionflow.server.service.MembreKeycloakSyncService;
|
||||
@@ -78,6 +79,9 @@ public class MembreResource {
|
||||
@Inject
|
||||
MembreOrganisationRepository membreOrgRepository;
|
||||
|
||||
@Inject
|
||||
MembreRepository membreRepository;
|
||||
|
||||
@Inject
|
||||
MembreRoleRepository membreRoleRepository;
|
||||
|
||||
@@ -447,6 +451,40 @@ public class MembreResource {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liste TOUS les membres (y compris EN_ATTENTE_VALIDATION) — réservé SUPER_ADMIN.
|
||||
* Utile pour les imports de données historiques et la gestion admin.
|
||||
*/
|
||||
@GET
|
||||
@Path("/admin/tous")
|
||||
@RolesAllowed({ "SUPER_ADMIN" })
|
||||
@Operation(summary = "Tous les membres (admin)", description = "Liste tous les membres quelque soit leur statut, réservé SUPER_ADMIN")
|
||||
@APIResponse(responseCode = "200", description = "Liste complète des membres")
|
||||
public Response getTousMembres(
|
||||
@Parameter(description = "Numéro de page (0-based)") @QueryParam("page") @DefaultValue("0") int page,
|
||||
@Parameter(description = "Taille de la page") @QueryParam("size") @DefaultValue("100") int size) {
|
||||
try {
|
||||
LOG.infof("GET /api/membres/admin/tous - page=%d size=%d", page, size);
|
||||
List<Membre> membres = membreRepository.findAll(
|
||||
io.quarkus.panache.common.Sort.by("nom").ascending())
|
||||
.page(io.quarkus.panache.common.Page.of(page, size))
|
||||
.list();
|
||||
List<MembreResponse> membresDTO = membreService.convertToResponseList(membres);
|
||||
long total = membreRepository.count();
|
||||
return Response.ok(Map.of(
|
||||
"data", membresDTO,
|
||||
"totalElements", total,
|
||||
"page", page,
|
||||
"size", size,
|
||||
"totalPages", (int) Math.ceil((double) total / size)
|
||||
)).build();
|
||||
} catch (Exception e) {
|
||||
LOG.errorf(e, "Erreur récupération tous membres");
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||
.entity(Map.of("error", e.getMessage())).build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liste les membres d'une organisation spécifique (statut ACTIF dans l'organisation).
|
||||
* Utilisé pour la création de campagnes ciblées.
|
||||
@@ -588,7 +626,7 @@ public class MembreResource {
|
||||
@APIResponses({
|
||||
@APIResponse(responseCode = "200", description = "Recherche effectuée avec succès", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = MembreSearchResultDTO.class), examples = @ExampleObject(name = "Exemple de résultats", value = """
|
||||
{
|
||||
"membres": [...],
|
||||
"membres": [],
|
||||
"totalElements": 247,
|
||||
"totalPages": 13,
|
||||
"currentPage": 0,
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
package dev.lions.unionflow.server.resource;
|
||||
|
||||
import dev.lions.unionflow.server.api.payment.*;
|
||||
import dev.lions.unionflow.server.entity.SouscriptionOrganisation;
|
||||
import dev.lions.unionflow.server.payment.orchestration.PaymentOrchestrator;
|
||||
import dev.lions.unionflow.server.payment.orchestration.PaymentProviderRegistry;
|
||||
import dev.lions.unionflow.server.repository.SouscriptionOrganisationRepository;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Endpoints de paiement unifiés — abstraction multi-provider.
|
||||
* Remplace à terme les endpoints Wave-spécifiques.
|
||||
*/
|
||||
@Slf4j
|
||||
@Path("/api/paiements")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class PaiementUnifieResource {
|
||||
|
||||
@Inject
|
||||
PaymentOrchestrator orchestrator;
|
||||
|
||||
@Inject
|
||||
PaymentProviderRegistry registry;
|
||||
|
||||
@Inject
|
||||
SouscriptionOrganisationRepository souscriptionRepository;
|
||||
|
||||
/**
|
||||
* Initie un paiement via le provider demandé (ou le provider par défaut).
|
||||
*
|
||||
* <p>Exemple : {@code POST /api/paiements/initier?provider=WAVE}
|
||||
*/
|
||||
@POST
|
||||
@Path("/initier")
|
||||
@RolesAllowed({"MEMBRE_ACTIF", "ADMIN_ORGANISATION", "TRESORIER", "SUPER_ADMIN"})
|
||||
public Response initier(
|
||||
@QueryParam("provider") String provider,
|
||||
PaiementInitierRequest req) {
|
||||
try {
|
||||
// Si une souscription est fournie, utiliser le providerDefaut de sa formule
|
||||
String resolvedProvider = provider;
|
||||
if (req.souscriptionId() != null) {
|
||||
resolvedProvider = souscriptionRepository.findByIdOptional(req.souscriptionId())
|
||||
.map(SouscriptionOrganisation::getFormule)
|
||||
.map(f -> f.getProviderDefaut())
|
||||
.filter(p -> p != null && !p.isBlank())
|
||||
.orElse(provider);
|
||||
}
|
||||
|
||||
CheckoutRequest checkoutRequest = new CheckoutRequest(
|
||||
req.montant(),
|
||||
req.devise() != null ? req.devise() : "XOF",
|
||||
req.telephone(),
|
||||
req.email(),
|
||||
req.reference(),
|
||||
req.successUrl(),
|
||||
req.cancelUrl(),
|
||||
Map.of()
|
||||
);
|
||||
CheckoutSession session = orchestrator.initierPaiement(checkoutRequest, resolvedProvider);
|
||||
return Response.ok(session).build();
|
||||
} catch (PaymentException e) {
|
||||
return Response.status(e.getHttpStatus())
|
||||
.entity(Map.of("error", e.getMessage(), "provider", e.getProviderCode()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Webhook entrant d'un provider. Vérifie la signature et met à jour le statut.
|
||||
* Route : {@code POST /api/paiements/webhook/{provider}}
|
||||
*/
|
||||
@POST
|
||||
@Path("/webhook/{provider}")
|
||||
@PermitAll
|
||||
@Consumes(MediaType.WILDCARD)
|
||||
public Response webhook(
|
||||
@PathParam("provider") String providerCode,
|
||||
String rawBody,
|
||||
@Context HttpHeaders httpHeaders) {
|
||||
try {
|
||||
PaymentProvider provider = registry.get(providerCode.toUpperCase());
|
||||
Map<String, String> headers = httpHeaders.getRequestHeaders().entrySet().stream()
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
e -> e.getValue().isEmpty() ? "" : e.getValue().get(0)
|
||||
));
|
||||
|
||||
PaymentEvent event = provider.processWebhook(rawBody, headers);
|
||||
orchestrator.handleEvent(event);
|
||||
return Response.ok().build();
|
||||
|
||||
} catch (UnsupportedOperationException e) {
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.entity(Map.of("error", "Provider inconnu : " + providerCode))
|
||||
.build();
|
||||
} catch (PaymentException e) {
|
||||
log.error("Webhook {} rejeté : {}", providerCode, e.getMessage());
|
||||
return Response.status(e.getHttpStatus())
|
||||
.entity(Map.of("error", e.getMessage()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
/** Retourne les providers de paiement disponibles. */
|
||||
@GET
|
||||
@Path("/providers")
|
||||
@RolesAllowed({"ADMIN_ORGANISATION", "SUPER_ADMIN"})
|
||||
public List<String> getProviders() {
|
||||
return registry.getAvailableCodes();
|
||||
}
|
||||
|
||||
public record PaiementInitierRequest(
|
||||
BigDecimal montant,
|
||||
String devise,
|
||||
String telephone,
|
||||
String email,
|
||||
String reference,
|
||||
String successUrl,
|
||||
String cancelUrl,
|
||||
/** Optionnel — si fourni, le providerDefaut de la formule prend le dessus sur le query param. */
|
||||
UUID souscriptionId
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package dev.lions.unionflow.server.resource.mutuelle;
|
||||
|
||||
import dev.lions.unionflow.server.api.dto.mutuelle.financier.ParametresFinanciersMutuellRequest;
|
||||
import dev.lions.unionflow.server.api.dto.mutuelle.financier.ParametresFinanciersMutuellResponse;
|
||||
import dev.lions.unionflow.server.security.RequiresModule;
|
||||
import dev.lions.unionflow.server.service.mutuelle.InteretsEpargneService;
|
||||
import dev.lions.unionflow.server.service.mutuelle.ParametresFinanciersService;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Path("/api/v1/mutuelle/parametres-financiers")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@RequiresModule("EPARGNE")
|
||||
public class ParametresFinanciersResource {
|
||||
|
||||
@Inject ParametresFinanciersService parametresService;
|
||||
@Inject InteretsEpargneService interetsService;
|
||||
|
||||
@GET
|
||||
@Path("/{orgId}")
|
||||
@RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP"})
|
||||
public Response getByOrganisation(@PathParam("orgId") UUID orgId) {
|
||||
return Response.ok(parametresService.getByOrganisation(orgId)).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION"})
|
||||
public Response creerOuMettrAJour(@Valid ParametresFinanciersMutuellRequest request) {
|
||||
ParametresFinanciersMutuellResponse resp = parametresService.creerOuMettrAJour(request);
|
||||
return Response.ok(resp).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Déclenche manuellement le calcul des intérêts / dividendes pour une organisation.
|
||||
* Utile pour régularisation ou test.
|
||||
*/
|
||||
@POST
|
||||
@Path("/{orgId}/calculer-interets")
|
||||
@RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION"})
|
||||
public Response calculerInterets(@PathParam("orgId") UUID orgId) {
|
||||
Map<String, Object> result = interetsService.calculerManuellement(orgId);
|
||||
return Response.ok(result).build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package dev.lions.unionflow.server.resource.mutuelle;
|
||||
|
||||
import dev.lions.unionflow.server.security.RequiresModule;
|
||||
import dev.lions.unionflow.server.service.mutuelle.ReleveComptePdfService;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.Response.ResponseBuilder;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Relevés de compte en PDF.
|
||||
* - GET /api/v1/releves/epargne/{compteId} → relevé épargne
|
||||
* - GET /api/v1/releves/parts-sociales/{compteId} → relevé parts sociales
|
||||
*/
|
||||
@Path("/api/v1/releves")
|
||||
@RequiresModule("EPARGNE")
|
||||
public class ReleveCompteResource {
|
||||
|
||||
@Inject ReleveComptePdfService releveService;
|
||||
|
||||
@GET
|
||||
@Path("/epargne/{compteId}")
|
||||
@Produces("application/pdf")
|
||||
@RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP", "MEMBRE", "USER"})
|
||||
public Response releveEpargne(
|
||||
@PathParam("compteId") UUID compteId,
|
||||
@QueryParam("dateDebut") String dateDebutStr,
|
||||
@QueryParam("dateFin") String dateFinStr) {
|
||||
|
||||
LocalDate dateDebut = parseDate(dateDebutStr);
|
||||
LocalDate dateFin = parseDate(dateFinStr);
|
||||
byte[] pdf = releveService.genererReleveEpargne(compteId, dateDebut, dateFin);
|
||||
|
||||
ResponseBuilder rb = Response.ok(pdf);
|
||||
rb.header("Content-Disposition",
|
||||
"attachment; filename=\"releve-epargne-" + compteId + ".pdf\"");
|
||||
rb.header("Content-Type", MediaType.valueOf("application/pdf"));
|
||||
return rb.build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/parts-sociales/{compteId}")
|
||||
@Produces("application/pdf")
|
||||
@RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP", "MEMBRE", "USER"})
|
||||
public Response releveParts(
|
||||
@PathParam("compteId") UUID compteId,
|
||||
@QueryParam("dateDebut") String dateDebutStr,
|
||||
@QueryParam("dateFin") String dateFinStr) {
|
||||
|
||||
LocalDate dateDebut = parseDate(dateDebutStr);
|
||||
LocalDate dateFin = parseDate(dateFinStr);
|
||||
byte[] pdf = releveService.genererReleveParts(compteId, dateDebut, dateFin);
|
||||
|
||||
ResponseBuilder rb = Response.ok(pdf);
|
||||
rb.header("Content-Disposition",
|
||||
"attachment; filename=\"releve-parts-" + compteId + ".pdf\"");
|
||||
rb.header("Content-Type", MediaType.valueOf("application/pdf"));
|
||||
return rb.build();
|
||||
}
|
||||
|
||||
private LocalDate parseDate(String s) {
|
||||
if (s == null || s.isBlank()) return null;
|
||||
try {
|
||||
return LocalDate.parse(s);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Format de date invalide. Utilisez YYYY-MM-DD. Valeur reçue: " + s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import jakarta.validation.Valid;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import io.quarkus.security.identity.SecurityIdentity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -24,10 +25,16 @@ public class TransactionEpargneResource {
|
||||
@Inject
|
||||
TransactionEpargneService transactionEpargneService;
|
||||
|
||||
@Inject
|
||||
SecurityIdentity securityIdentity;
|
||||
|
||||
@POST
|
||||
@RolesAllowed({ "ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP", "MEMBRE", "USER" })
|
||||
public Response executerTransaction(@Valid TransactionEpargneRequest request) {
|
||||
TransactionEpargneResponse transaction = transactionEpargneService.executerTransaction(request);
|
||||
public Response executerTransaction(
|
||||
@Valid TransactionEpargneRequest request,
|
||||
@QueryParam("historique") @DefaultValue("false") boolean historique) {
|
||||
boolean bypassSolde = historique && securityIdentity.hasRole("SUPER_ADMIN");
|
||||
TransactionEpargneResponse transaction = transactionEpargneService.executerTransaction(request, bypassSolde);
|
||||
return Response.status(Response.Status.CREATED).entity(transaction).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package dev.lions.unionflow.server.resource.mutuelle.parts;
|
||||
|
||||
import dev.lions.unionflow.server.api.dto.mutuelle.parts.ComptePartsSocialesRequest;
|
||||
import dev.lions.unionflow.server.api.dto.mutuelle.parts.ComptePartsSocialesResponse;
|
||||
import dev.lions.unionflow.server.api.dto.mutuelle.parts.TransactionPartsSocialesRequest;
|
||||
import dev.lions.unionflow.server.api.dto.mutuelle.parts.TransactionPartsSocialesResponse;
|
||||
import dev.lions.unionflow.server.security.RequiresModule;
|
||||
import dev.lions.unionflow.server.service.mutuelle.parts.ComptePartsSocialesService;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Path("/api/v1/parts-sociales/comptes")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@RequiresModule("EPARGNE")
|
||||
public class ComptePartsSocialesResource {
|
||||
|
||||
@Inject
|
||||
ComptePartsSocialesService service;
|
||||
|
||||
@POST
|
||||
@RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP"})
|
||||
public Response ouvrirCompte(@Valid ComptePartsSocialesRequest request) {
|
||||
ComptePartsSocialesResponse resp = service.ouvrirCompte(request);
|
||||
return Response.status(Response.Status.CREATED).entity(resp).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/transactions")
|
||||
@RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP"})
|
||||
public Response enregistrerTransaction(@Valid TransactionPartsSocialesRequest request) {
|
||||
TransactionPartsSocialesResponse resp = service.enregistrerSouscription(request);
|
||||
return Response.status(Response.Status.CREATED).entity(resp).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{id}")
|
||||
@RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP", "MEMBRE", "USER"})
|
||||
public Response getById(@PathParam("id") UUID id) {
|
||||
return Response.ok(service.getById(id)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/membre/{membreId}")
|
||||
@RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP", "MEMBRE", "USER"})
|
||||
public Response getByMembre(@PathParam("membreId") UUID membreId) {
|
||||
List<ComptePartsSocialesResponse> list = service.getByMembre(membreId);
|
||||
return Response.ok(list).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/organisation/{orgId}")
|
||||
@RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP"})
|
||||
public Response getByOrganisation(@PathParam("orgId") UUID orgId) {
|
||||
List<ComptePartsSocialesResponse> list = service.getByOrganisation(orgId);
|
||||
return Response.ok(list).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{id}/transactions")
|
||||
@RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP", "MEMBRE", "USER"})
|
||||
public Response getTransactions(@PathParam("id") UUID id) {
|
||||
List<TransactionPartsSocialesResponse> list = service.getTransactions(id);
|
||||
return Response.ok(list).build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user