Initial commit: unionflow-mobile-apps
Application Flutter complète (sans build artifacts). Signed-off-by: lions dev Team
This commit is contained in:
373
lib/features/members/data/models/membre_complete_model.dart
Normal file
373
lib/features/members/data/models/membre_complete_model.dart
Normal file
@@ -0,0 +1,373 @@
|
||||
/// Modèle complet de données pour un membre
|
||||
/// Aligné avec le backend MembreDTO
|
||||
library membre_complete_model;
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'membre_complete_model.g.dart';
|
||||
|
||||
/// Énumération des genres
|
||||
enum Genre {
|
||||
@JsonValue('HOMME')
|
||||
homme,
|
||||
@JsonValue('FEMME')
|
||||
femme,
|
||||
@JsonValue('AUTRE')
|
||||
autre,
|
||||
}
|
||||
|
||||
/// Énumération des statuts de membre
|
||||
enum StatutMembre {
|
||||
@JsonValue('ACTIF')
|
||||
actif,
|
||||
@JsonValue('INACTIF')
|
||||
inactif,
|
||||
@JsonValue('SUSPENDU')
|
||||
suspendu,
|
||||
@JsonValue('EN_ATTENTE')
|
||||
enAttente,
|
||||
}
|
||||
|
||||
/// Niveau de vigilance KYC (LCB-FT)
|
||||
enum NiveauVigilanceKyc {
|
||||
@JsonValue('SIMPLIFIE')
|
||||
simplifie,
|
||||
@JsonValue('RENFORCE')
|
||||
renforce,
|
||||
}
|
||||
|
||||
/// Statut KYC (vérification identité)
|
||||
enum StatutKyc {
|
||||
@JsonValue('NON_VERIFIE')
|
||||
nonVerifie,
|
||||
@JsonValue('EN_COURS')
|
||||
enCours,
|
||||
@JsonValue('VERIFIE')
|
||||
verifie,
|
||||
@JsonValue('REFUSE')
|
||||
refuse,
|
||||
}
|
||||
|
||||
/// Modèle complet d'un membre
|
||||
@JsonSerializable()
|
||||
class MembreCompletModel extends Equatable {
|
||||
/// Identifiant unique
|
||||
final String? id;
|
||||
|
||||
/// Nom de famille
|
||||
final String nom;
|
||||
|
||||
/// Prénom
|
||||
final String prenom;
|
||||
|
||||
/// Email (unique)
|
||||
final String email;
|
||||
|
||||
/// Téléphone
|
||||
final String? telephone;
|
||||
|
||||
/// Date de naissance
|
||||
@JsonKey(name: 'dateNaissance')
|
||||
final DateTime? dateNaissance;
|
||||
|
||||
/// Genre
|
||||
final Genre? genre;
|
||||
|
||||
/// Adresse complète
|
||||
final String? adresse;
|
||||
|
||||
/// Ville
|
||||
final String? ville;
|
||||
|
||||
/// Code postal
|
||||
@JsonKey(name: 'codePostal')
|
||||
final String? codePostal;
|
||||
|
||||
/// Région
|
||||
final String? region;
|
||||
|
||||
/// Pays
|
||||
final String? pays;
|
||||
|
||||
/// Profession
|
||||
final String? profession;
|
||||
|
||||
/// Nationalité
|
||||
final String? nationalite;
|
||||
|
||||
/// URL de la photo
|
||||
final String? photo;
|
||||
|
||||
/// Statut du membre
|
||||
final StatutMembre statut;
|
||||
|
||||
/// Rôle dans l'organisation
|
||||
final String? role;
|
||||
|
||||
/// ID de l'organisation
|
||||
@JsonKey(name: 'organisationId')
|
||||
final String? organisationId;
|
||||
|
||||
/// Nom de l'organisation (pour affichage)
|
||||
@JsonKey(name: 'organisationNom')
|
||||
final String? organisationNom;
|
||||
|
||||
/// Date d'adhésion
|
||||
@JsonKey(name: 'dateAdhesion')
|
||||
final DateTime? dateAdhesion;
|
||||
|
||||
/// Date de fin d'adhésion
|
||||
@JsonKey(name: 'dateFinAdhesion')
|
||||
final DateTime? dateFinAdhesion;
|
||||
|
||||
/// Membre du bureau
|
||||
@JsonKey(name: 'membreBureau')
|
||||
final bool membreBureau;
|
||||
|
||||
/// Est responsable
|
||||
final bool responsable;
|
||||
|
||||
/// Fonction au bureau
|
||||
@JsonKey(name: 'fonctionBureau')
|
||||
final String? fonctionBureau;
|
||||
|
||||
/// Numéro de membre (unique)
|
||||
@JsonKey(name: 'numeroMembre')
|
||||
final String? numeroMembre;
|
||||
|
||||
/// Cotisation à jour
|
||||
@JsonKey(name: 'cotisationAJour')
|
||||
final bool cotisationAJour;
|
||||
|
||||
/// Nombre d'événements participés
|
||||
@JsonKey(name: 'nombreEvenementsParticipes')
|
||||
final int nombreEvenementsParticipes;
|
||||
|
||||
/// Dernière activité
|
||||
@JsonKey(name: 'derniereActivite')
|
||||
final DateTime? derniereActivite;
|
||||
|
||||
/// Notes internes
|
||||
final String? notes;
|
||||
|
||||
/// Date de création
|
||||
@JsonKey(name: 'dateCreation')
|
||||
final DateTime? dateCreation;
|
||||
|
||||
/// Date de modification
|
||||
@JsonKey(name: 'dateModification')
|
||||
final DateTime? dateModification;
|
||||
|
||||
/// Actif
|
||||
final bool actif;
|
||||
|
||||
/// Niveau de vigilance KYC (LCB-FT anti-blanchiment)
|
||||
@JsonKey(name: 'niveauVigilanceKyc')
|
||||
final NiveauVigilanceKyc? niveauVigilanceKyc;
|
||||
|
||||
/// Statut de vérification KYC (Know Your Customer)
|
||||
@JsonKey(name: 'statutKyc')
|
||||
final StatutKyc? statutKyc;
|
||||
|
||||
/// Date de vérification de l'identité (LCB-FT)
|
||||
@JsonKey(name: 'dateVerificationIdentite')
|
||||
final DateTime? dateVerificationIdentite;
|
||||
|
||||
const MembreCompletModel({
|
||||
this.id,
|
||||
required this.nom,
|
||||
required this.prenom,
|
||||
required this.email,
|
||||
this.telephone,
|
||||
this.dateNaissance,
|
||||
this.genre,
|
||||
this.adresse,
|
||||
this.ville,
|
||||
this.codePostal,
|
||||
this.region,
|
||||
this.pays,
|
||||
this.profession,
|
||||
this.nationalite,
|
||||
this.photo,
|
||||
this.statut = StatutMembre.actif,
|
||||
this.role,
|
||||
this.organisationId,
|
||||
this.organisationNom,
|
||||
this.dateAdhesion,
|
||||
this.dateFinAdhesion,
|
||||
this.membreBureau = false,
|
||||
this.responsable = false,
|
||||
this.fonctionBureau,
|
||||
this.numeroMembre,
|
||||
this.cotisationAJour = false,
|
||||
this.nombreEvenementsParticipes = 0,
|
||||
this.derniereActivite,
|
||||
this.notes,
|
||||
this.dateCreation,
|
||||
this.dateModification,
|
||||
this.actif = true,
|
||||
this.niveauVigilanceKyc,
|
||||
this.statutKyc,
|
||||
this.dateVerificationIdentite,
|
||||
});
|
||||
|
||||
/// Création depuis JSON
|
||||
factory MembreCompletModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$MembreCompletModelFromJson(json);
|
||||
|
||||
/// Conversion vers JSON
|
||||
Map<String, dynamic> toJson() => _$MembreCompletModelToJson(this);
|
||||
|
||||
/// Copie avec modifications
|
||||
MembreCompletModel copyWith({
|
||||
String? id,
|
||||
String? nom,
|
||||
String? prenom,
|
||||
String? email,
|
||||
String? telephone,
|
||||
DateTime? dateNaissance,
|
||||
Genre? genre,
|
||||
String? adresse,
|
||||
String? ville,
|
||||
String? codePostal,
|
||||
String? region,
|
||||
String? pays,
|
||||
String? profession,
|
||||
String? nationalite,
|
||||
String? photo,
|
||||
StatutMembre? statut,
|
||||
String? role,
|
||||
String? organisationId,
|
||||
String? organisationNom,
|
||||
DateTime? dateAdhesion,
|
||||
DateTime? dateFinAdhesion,
|
||||
bool? membreBureau,
|
||||
bool? responsable,
|
||||
String? fonctionBureau,
|
||||
String? numeroMembre,
|
||||
bool? cotisationAJour,
|
||||
int? nombreEvenementsParticipes,
|
||||
DateTime? derniereActivite,
|
||||
String? notes,
|
||||
DateTime? dateCreation,
|
||||
DateTime? dateModification,
|
||||
bool? actif,
|
||||
NiveauVigilanceKyc? niveauVigilanceKyc,
|
||||
StatutKyc? statutKyc,
|
||||
DateTime? dateVerificationIdentite,
|
||||
}) {
|
||||
return MembreCompletModel(
|
||||
id: id ?? this.id,
|
||||
nom: nom ?? this.nom,
|
||||
prenom: prenom ?? this.prenom,
|
||||
email: email ?? this.email,
|
||||
telephone: telephone ?? this.telephone,
|
||||
dateNaissance: dateNaissance ?? this.dateNaissance,
|
||||
genre: genre ?? this.genre,
|
||||
adresse: adresse ?? this.adresse,
|
||||
ville: ville ?? this.ville,
|
||||
codePostal: codePostal ?? this.codePostal,
|
||||
region: region ?? this.region,
|
||||
pays: pays ?? this.pays,
|
||||
profession: profession ?? this.profession,
|
||||
nationalite: nationalite ?? this.nationalite,
|
||||
photo: photo ?? this.photo,
|
||||
statut: statut ?? this.statut,
|
||||
role: role ?? this.role,
|
||||
organisationId: organisationId ?? this.organisationId,
|
||||
organisationNom: organisationNom ?? this.organisationNom,
|
||||
dateAdhesion: dateAdhesion ?? this.dateAdhesion,
|
||||
dateFinAdhesion: dateFinAdhesion ?? this.dateFinAdhesion,
|
||||
membreBureau: membreBureau ?? this.membreBureau,
|
||||
responsable: responsable ?? this.responsable,
|
||||
fonctionBureau: fonctionBureau ?? this.fonctionBureau,
|
||||
numeroMembre: numeroMembre ?? this.numeroMembre,
|
||||
cotisationAJour: cotisationAJour ?? this.cotisationAJour,
|
||||
nombreEvenementsParticipes: nombreEvenementsParticipes ?? this.nombreEvenementsParticipes,
|
||||
derniereActivite: derniereActivite ?? this.derniereActivite,
|
||||
notes: notes ?? this.notes,
|
||||
dateCreation: dateCreation ?? this.dateCreation,
|
||||
dateModification: dateModification ?? this.dateModification,
|
||||
actif: actif ?? this.actif,
|
||||
niveauVigilanceKyc: niveauVigilanceKyc ?? this.niveauVigilanceKyc,
|
||||
statutKyc: statutKyc ?? this.statutKyc,
|
||||
dateVerificationIdentite: dateVerificationIdentite ?? this.dateVerificationIdentite,
|
||||
);
|
||||
}
|
||||
|
||||
/// Nom complet
|
||||
String get nomComplet => '$prenom $nom';
|
||||
|
||||
/// Initiales
|
||||
String get initiales {
|
||||
final p = prenom.isNotEmpty ? prenom[0].toUpperCase() : '';
|
||||
final n = nom.isNotEmpty ? nom[0].toUpperCase() : '';
|
||||
return '$p$n';
|
||||
}
|
||||
|
||||
/// Âge calculé
|
||||
int? get age {
|
||||
if (dateNaissance == null) return null;
|
||||
final now = DateTime.now();
|
||||
int age = now.year - dateNaissance!.year;
|
||||
if (now.month < dateNaissance!.month ||
|
||||
(now.month == dateNaissance!.month && now.day < dateNaissance!.day)) {
|
||||
age--;
|
||||
}
|
||||
return age;
|
||||
}
|
||||
|
||||
/// Ancienneté en jours
|
||||
int? get ancienneteJours {
|
||||
if (dateAdhesion == null) return null;
|
||||
return DateTime.now().difference(dateAdhesion!).inDays;
|
||||
}
|
||||
|
||||
/// Est actif et cotisation à jour
|
||||
bool get estActifEtAJour => actif && statut == StatutMembre.actif && cotisationAJour;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
nom,
|
||||
prenom,
|
||||
email,
|
||||
telephone,
|
||||
dateNaissance,
|
||||
genre,
|
||||
adresse,
|
||||
ville,
|
||||
codePostal,
|
||||
region,
|
||||
pays,
|
||||
profession,
|
||||
nationalite,
|
||||
photo,
|
||||
statut,
|
||||
role,
|
||||
organisationId,
|
||||
organisationNom,
|
||||
dateAdhesion,
|
||||
dateFinAdhesion,
|
||||
membreBureau,
|
||||
responsable,
|
||||
fonctionBureau,
|
||||
numeroMembre,
|
||||
cotisationAJour,
|
||||
nombreEvenementsParticipes,
|
||||
derniereActivite,
|
||||
notes,
|
||||
dateCreation,
|
||||
dateModification,
|
||||
actif,
|
||||
niveauVigilanceKyc,
|
||||
statutKyc,
|
||||
dateVerificationIdentite,
|
||||
];
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
'MembreCompletModel(id: $id, nom: $nomComplet, email: $email, statut: $statut)';
|
||||
}
|
||||
|
||||
129
lib/features/members/data/models/membre_complete_model.g.dart
Normal file
129
lib/features/members/data/models/membre_complete_model.g.dart
Normal file
@@ -0,0 +1,129 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'membre_complete_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
MembreCompletModel _$MembreCompletModelFromJson(Map<String, dynamic> json) =>
|
||||
MembreCompletModel(
|
||||
id: json['id'] as String?,
|
||||
nom: json['nom'] as String,
|
||||
prenom: json['prenom'] as String,
|
||||
email: json['email'] as String,
|
||||
telephone: json['telephone'] as String?,
|
||||
dateNaissance: json['dateNaissance'] == null
|
||||
? null
|
||||
: DateTime.parse(json['dateNaissance'] as String),
|
||||
genre: $enumDecodeNullable(_$GenreEnumMap, json['genre']),
|
||||
adresse: json['adresse'] as String?,
|
||||
ville: json['ville'] as String?,
|
||||
codePostal: json['codePostal'] as String?,
|
||||
region: json['region'] as String?,
|
||||
pays: json['pays'] as String?,
|
||||
profession: json['profession'] as String?,
|
||||
nationalite: json['nationalite'] as String?,
|
||||
photo: json['photo'] as String?,
|
||||
statut: $enumDecodeNullable(_$StatutMembreEnumMap, json['statut']) ??
|
||||
StatutMembre.actif,
|
||||
role: json['role'] as String?,
|
||||
organisationId: json['organisationId'] as String?,
|
||||
organisationNom: json['organisationNom'] as String?,
|
||||
dateAdhesion: json['dateAdhesion'] == null
|
||||
? null
|
||||
: DateTime.parse(json['dateAdhesion'] as String),
|
||||
dateFinAdhesion: json['dateFinAdhesion'] == null
|
||||
? null
|
||||
: DateTime.parse(json['dateFinAdhesion'] as String),
|
||||
membreBureau: json['membreBureau'] as bool? ?? false,
|
||||
responsable: json['responsable'] as bool? ?? false,
|
||||
fonctionBureau: json['fonctionBureau'] as String?,
|
||||
numeroMembre: json['numeroMembre'] as String?,
|
||||
cotisationAJour: json['cotisationAJour'] as bool? ?? false,
|
||||
nombreEvenementsParticipes:
|
||||
(json['nombreEvenementsParticipes'] as num?)?.toInt() ?? 0,
|
||||
derniereActivite: json['derniereActivite'] == null
|
||||
? null
|
||||
: DateTime.parse(json['derniereActivite'] as String),
|
||||
notes: json['notes'] as String?,
|
||||
dateCreation: json['dateCreation'] == null
|
||||
? null
|
||||
: DateTime.parse(json['dateCreation'] as String),
|
||||
dateModification: json['dateModification'] == null
|
||||
? null
|
||||
: DateTime.parse(json['dateModification'] as String),
|
||||
actif: json['actif'] as bool? ?? true,
|
||||
niveauVigilanceKyc: $enumDecodeNullable(
|
||||
_$NiveauVigilanceKycEnumMap, json['niveauVigilanceKyc']),
|
||||
statutKyc: $enumDecodeNullable(_$StatutKycEnumMap, json['statutKyc']),
|
||||
dateVerificationIdentite: json['dateVerificationIdentite'] == null
|
||||
? null
|
||||
: DateTime.parse(json['dateVerificationIdentite'] as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$MembreCompletModelToJson(MembreCompletModel instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'nom': instance.nom,
|
||||
'prenom': instance.prenom,
|
||||
'email': instance.email,
|
||||
'telephone': instance.telephone,
|
||||
'dateNaissance': instance.dateNaissance?.toIso8601String(),
|
||||
'genre': _$GenreEnumMap[instance.genre],
|
||||
'adresse': instance.adresse,
|
||||
'ville': instance.ville,
|
||||
'codePostal': instance.codePostal,
|
||||
'region': instance.region,
|
||||
'pays': instance.pays,
|
||||
'profession': instance.profession,
|
||||
'nationalite': instance.nationalite,
|
||||
'photo': instance.photo,
|
||||
'statut': _$StatutMembreEnumMap[instance.statut]!,
|
||||
'role': instance.role,
|
||||
'organisationId': instance.organisationId,
|
||||
'organisationNom': instance.organisationNom,
|
||||
'dateAdhesion': instance.dateAdhesion?.toIso8601String(),
|
||||
'dateFinAdhesion': instance.dateFinAdhesion?.toIso8601String(),
|
||||
'membreBureau': instance.membreBureau,
|
||||
'responsable': instance.responsable,
|
||||
'fonctionBureau': instance.fonctionBureau,
|
||||
'numeroMembre': instance.numeroMembre,
|
||||
'cotisationAJour': instance.cotisationAJour,
|
||||
'nombreEvenementsParticipes': instance.nombreEvenementsParticipes,
|
||||
'derniereActivite': instance.derniereActivite?.toIso8601String(),
|
||||
'notes': instance.notes,
|
||||
'dateCreation': instance.dateCreation?.toIso8601String(),
|
||||
'dateModification': instance.dateModification?.toIso8601String(),
|
||||
'actif': instance.actif,
|
||||
'niveauVigilanceKyc':
|
||||
_$NiveauVigilanceKycEnumMap[instance.niveauVigilanceKyc],
|
||||
'statutKyc': _$StatutKycEnumMap[instance.statutKyc],
|
||||
'dateVerificationIdentite':
|
||||
instance.dateVerificationIdentite?.toIso8601String(),
|
||||
};
|
||||
|
||||
const _$GenreEnumMap = {
|
||||
Genre.homme: 'HOMME',
|
||||
Genre.femme: 'FEMME',
|
||||
Genre.autre: 'AUTRE',
|
||||
};
|
||||
|
||||
const _$StatutMembreEnumMap = {
|
||||
StatutMembre.actif: 'ACTIF',
|
||||
StatutMembre.inactif: 'INACTIF',
|
||||
StatutMembre.suspendu: 'SUSPENDU',
|
||||
StatutMembre.enAttente: 'EN_ATTENTE',
|
||||
};
|
||||
|
||||
const _$NiveauVigilanceKycEnumMap = {
|
||||
NiveauVigilanceKyc.simplifie: 'SIMPLIFIE',
|
||||
NiveauVigilanceKyc.renforce: 'RENFORCE',
|
||||
};
|
||||
|
||||
const _$StatutKycEnumMap = {
|
||||
StatutKyc.nonVerifie: 'NON_VERIFIE',
|
||||
StatutKyc.enCours: 'EN_COURS',
|
||||
StatutKyc.verifie: 'VERIFIE',
|
||||
StatutKyc.refuse: 'REFUSE',
|
||||
};
|
||||
69
lib/features/members/data/models/membre_model.dart
Normal file
69
lib/features/members/data/models/membre_model.dart
Normal file
@@ -0,0 +1,69 @@
|
||||
/// Modèle de données pour un membre
|
||||
class MembreModel {
|
||||
final String id;
|
||||
final String nom;
|
||||
final String prenom;
|
||||
final String email;
|
||||
final String? telephone;
|
||||
final String? statut;
|
||||
final String? role;
|
||||
final OrganisationModel? organisation;
|
||||
|
||||
const MembreModel({
|
||||
required this.id,
|
||||
required this.nom,
|
||||
required this.prenom,
|
||||
required this.email,
|
||||
this.telephone,
|
||||
this.statut,
|
||||
this.role,
|
||||
this.organisation,
|
||||
});
|
||||
|
||||
factory MembreModel.fromJson(Map<String, dynamic> json) {
|
||||
return MembreModel(
|
||||
id: json['id'] as String,
|
||||
nom: json['nom'] as String,
|
||||
prenom: json['prenom'] as String,
|
||||
email: json['email'] as String,
|
||||
telephone: json['telephone'] as String?,
|
||||
statut: json['statut'] as String?,
|
||||
role: json['role'] as String?,
|
||||
organisation: json['organisation'] != null
|
||||
? OrganisationModel.fromJson(json['organisation'] as Map<String, dynamic>)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'nom': nom,
|
||||
'prenom': prenom,
|
||||
'email': email,
|
||||
'telephone': telephone,
|
||||
'statut': statut,
|
||||
'role': role,
|
||||
'organisation': organisation?.toJson(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Modèle pour une organisation
|
||||
class OrganisationModel {
|
||||
final String? nom;
|
||||
|
||||
const OrganisationModel({this.nom});
|
||||
|
||||
factory OrganisationModel.fromJson(Map<String, dynamic> json) {
|
||||
return OrganisationModel(
|
||||
nom: json['nom'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'nom': nom,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
/// Implémentation du repository pour la gestion des membres
|
||||
/// Interface avec l'API backend MembreResource
|
||||
library membre_repository_impl;
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:unionflow_mobile_apps/core/network/api_client.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../domain/repositories/membre_repository.dart';
|
||||
import '../models/membre_complete_model.dart';
|
||||
import '../../../../shared/models/membre_search_result.dart';
|
||||
import '../../../../shared/models/membre_search_criteria.dart';
|
||||
|
||||
/// Implémentation du repository des membres
|
||||
@LazySingleton(as: IMembreRepository)
|
||||
class MembreRepositoryImpl implements IMembreRepository {
|
||||
final ApiClient _apiClient;
|
||||
static const String _baseUrl = '/api/membres';
|
||||
|
||||
MembreRepositoryImpl(this._apiClient);
|
||||
|
||||
@override
|
||||
Future<MembreSearchResult> getMembres({
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
String? recherche,
|
||||
}) async {
|
||||
try {
|
||||
// Si une recherche est fournie, utiliser l'endpoint de recherche
|
||||
if (recherche?.isNotEmpty == true) {
|
||||
final response = await _apiClient.get(
|
||||
'$_baseUrl/recherche',
|
||||
queryParameters: {
|
||||
'q': recherche,
|
||||
'page': page,
|
||||
'size': size,
|
||||
},
|
||||
);
|
||||
|
||||
return _parseMembreSearchResult(response, page, size, MembreSearchCriteria(query: recherche));
|
||||
}
|
||||
|
||||
// Sinon, récupérer tous les membres
|
||||
final response = await _apiClient.get(
|
||||
_baseUrl,
|
||||
queryParameters: {
|
||||
'page': page,
|
||||
'size': size,
|
||||
},
|
||||
);
|
||||
|
||||
return _parseMembreSearchResult(response, page, size, const MembreSearchCriteria());
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la récupération des membres: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la récupération des membres: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Normalise les clés backend pour alignement API ↔ modèle (cohérence des données).
|
||||
MembreCompletModel _normalizeAndParseMembre(Map<String, dynamic> map) {
|
||||
if (map.containsKey('associationNom') && !map.containsKey('organisationNom')) {
|
||||
map['organisationNom'] = map['associationNom'];
|
||||
}
|
||||
if (map.containsKey('organisationId') && map['organisationId'] != null && map['organisationId'] is! String) {
|
||||
map['organisationId'] = map['organisationId'].toString();
|
||||
}
|
||||
if (map.containsKey('statutCompte') && !map.containsKey('statut')) {
|
||||
map['statut'] = map['statutCompte'];
|
||||
}
|
||||
if (map.containsKey('photoUrl') && !map.containsKey('photo')) {
|
||||
map['photo'] = map['photoUrl'];
|
||||
}
|
||||
if (map['id'] != null && map['id'] is! String) {
|
||||
map['id'] = map['id'].toString();
|
||||
}
|
||||
return MembreCompletModel.fromJson(map);
|
||||
}
|
||||
|
||||
/// Parse la réponse API et retourne un MembreSearchResult
|
||||
/// Gère les deux formats possibles : List (simple) ou Map (paginé)
|
||||
MembreSearchResult _parseMembreSearchResult(
|
||||
Response response,
|
||||
int page,
|
||||
int size,
|
||||
MembreSearchCriteria criteria,
|
||||
) {
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Erreur HTTP: ${response.statusCode}');
|
||||
}
|
||||
|
||||
// Format simple : liste directe de membres
|
||||
if (response.data is List) {
|
||||
final List<dynamic> listData = response.data as List<dynamic>;
|
||||
final membres = listData
|
||||
.map((e) => _normalizeAndParseMembre(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
|
||||
return MembreSearchResult(
|
||||
membres: membres,
|
||||
totalElements: membres.length,
|
||||
totalPages: 1,
|
||||
currentPage: page,
|
||||
pageSize: membres.length,
|
||||
numberOfElements: membres.length,
|
||||
hasNext: false,
|
||||
hasPrevious: false,
|
||||
isFirst: true,
|
||||
isLast: true,
|
||||
criteria: criteria,
|
||||
executionTimeMs: 0,
|
||||
);
|
||||
}
|
||||
|
||||
// Format paginé : PagedResponse backend (data, total, page, size, totalPages)
|
||||
final Map<String, dynamic> data = response.data as Map<String, dynamic>;
|
||||
final List<dynamic>? listData = data['data'] as List<dynamic>?;
|
||||
if (listData != null) {
|
||||
final membres = listData
|
||||
.map((e) => _normalizeAndParseMembre(Map<String, dynamic>.from(e as Map<String, dynamic>)))
|
||||
.toList();
|
||||
final total = (data['total'] as num?)?.toInt() ?? membres.length;
|
||||
final currentPage = (data['page'] as num?)?.toInt() ?? page;
|
||||
final pageSize = (data['size'] as num?)?.toInt() ?? size;
|
||||
final totalPages = (data['totalPages'] as num?)?.toInt() ?? (total > 0 ? 1 : 0);
|
||||
return MembreSearchResult(
|
||||
membres: membres,
|
||||
totalElements: total,
|
||||
totalPages: totalPages,
|
||||
currentPage: currentPage,
|
||||
pageSize: pageSize,
|
||||
numberOfElements: membres.length,
|
||||
hasNext: currentPage + 1 < totalPages,
|
||||
hasPrevious: currentPage > 0,
|
||||
isFirst: currentPage == 0,
|
||||
isLast: currentPage >= totalPages - 1,
|
||||
criteria: criteria,
|
||||
executionTimeMs: 0,
|
||||
);
|
||||
}
|
||||
return MembreSearchResult.fromJson(data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@override
|
||||
Future<MembreCompletModel?> getMembreById(String id) async {
|
||||
try {
|
||||
final response = await _apiClient.get('$_baseUrl/$id');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return MembreCompletModel.fromJson(response.data as Map<String, dynamic>);
|
||||
} else if (response.statusCode == 404) {
|
||||
return null;
|
||||
} else {
|
||||
throw Exception('Erreur lors de la récupération du membre: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 404) {
|
||||
return null;
|
||||
}
|
||||
throw Exception('Erreur réseau lors de la récupération du membre: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la récupération du membre: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<MembreCompletModel> createMembre(MembreCompletModel membre) async {
|
||||
try {
|
||||
final response = await _apiClient.post(
|
||||
_baseUrl,
|
||||
data: membre.toJson(),
|
||||
);
|
||||
|
||||
if (response.statusCode == 201 || response.statusCode == 200) {
|
||||
return MembreCompletModel.fromJson(response.data as Map<String, dynamic>);
|
||||
} else {
|
||||
throw Exception('Erreur lors de la création du membre: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la création du membre: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la création du membre: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<MembreCompletModel> updateMembre(String id, MembreCompletModel membre) async {
|
||||
try {
|
||||
final response = await _apiClient.put(
|
||||
'$_baseUrl/$id',
|
||||
data: membre.toJson(),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return MembreCompletModel.fromJson(response.data as Map<String, dynamic>);
|
||||
} else {
|
||||
throw Exception('Erreur lors de la mise à jour du membre: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la mise à jour du membre: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la mise à jour du membre: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteMembre(String id) async {
|
||||
try {
|
||||
final response = await _apiClient.delete('$_baseUrl/$id');
|
||||
|
||||
if (response.statusCode != 204 && response.statusCode != 200) {
|
||||
throw Exception('Erreur lors de la suppression du membre: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la suppression du membre: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la suppression du membre: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<MembreCompletModel> activateMembre(String id) async {
|
||||
try {
|
||||
final response = await _apiClient.post('$_baseUrl/$id/activer');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return MembreCompletModel.fromJson(response.data as Map<String, dynamic>);
|
||||
} else {
|
||||
throw Exception('Erreur lors de l\'activation du membre: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de l\'activation du membre: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de l\'activation du membre: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<MembreCompletModel> deactivateMembre(String id) async {
|
||||
try {
|
||||
final response = await _apiClient.post('$_baseUrl/$id/desactiver');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return MembreCompletModel.fromJson(response.data as Map<String, dynamic>);
|
||||
} else {
|
||||
throw Exception('Erreur lors de la désactivation du membre: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la désactivation du membre: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la désactivation du membre: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<MembreSearchResult> searchMembres({
|
||||
required MembreSearchCriteria criteria,
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
}) async {
|
||||
try {
|
||||
// Les paramètres de pagination vont dans queryParameters
|
||||
// Les critères de recherche vont directement dans le body
|
||||
final response = await _apiClient.post(
|
||||
'$_baseUrl/search/advanced',
|
||||
queryParameters: {
|
||||
'page': page,
|
||||
'size': size,
|
||||
},
|
||||
data: criteria.toJson(),
|
||||
);
|
||||
|
||||
return _parseMembreSearchResult(response, page, size, criteria);
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la recherche de membres: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la recherche de membres: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<MembreSearchResult> getActiveMembers({int page = 0, int size = 20}) async {
|
||||
// Utiliser la recherche avancée avec le critère statut=ACTIF
|
||||
return searchMembres(
|
||||
criteria: const MembreSearchCriteria(
|
||||
statut: 'ACTIF',
|
||||
includeInactifs: false,
|
||||
),
|
||||
page: page,
|
||||
size: size,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<MembreSearchResult> getBureauMembers({int page = 0, int size = 20}) async {
|
||||
// Utiliser la recherche avancée avec le critère membreBureau=true
|
||||
return searchMembres(
|
||||
criteria: const MembreSearchCriteria(
|
||||
membreBureau: true,
|
||||
statut: 'ACTIF',
|
||||
),
|
||||
page: page,
|
||||
size: size,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getMembresStats() async {
|
||||
try {
|
||||
final response = await _apiClient.get('$_baseUrl/statistiques');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return response.data as Map<String, dynamic>;
|
||||
} else {
|
||||
throw Exception('Erreur lors de la récupération des statistiques: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Erreur réseau lors de la récupération des statistiques: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur inattendue lors de la récupération des statistiques: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
282
lib/features/members/data/services/membre_search_service.dart
Normal file
282
lib/features/members/data/services/membre_search_service.dart
Normal file
@@ -0,0 +1,282 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:unionflow_mobile_apps/core/network/api_client.dart';
|
||||
import 'package:unionflow_mobile_apps/core/utils/logger.dart';
|
||||
|
||||
import '../../../../shared/models/membre_search_criteria.dart';
|
||||
import '../../../../shared/models/membre_search_result.dart';
|
||||
|
||||
/// Service pour la recherche avancée de membres
|
||||
/// Gère les appels API vers l'endpoint de recherche sophistiquée
|
||||
@lazySingleton
|
||||
class MembreSearchService {
|
||||
final ApiClient _apiClient;
|
||||
|
||||
MembreSearchService(this._apiClient);
|
||||
|
||||
/// Effectue une recherche avancée de membres
|
||||
///
|
||||
/// [criteria] Critères de recherche
|
||||
/// [page] Numéro de page (0-based)
|
||||
/// [size] Taille de la page
|
||||
/// [sortField] Champ de tri
|
||||
/// [sortDirection] Direction du tri (asc/desc)
|
||||
///
|
||||
/// Returns [MembreSearchResult] avec les résultats paginés
|
||||
Future<MembreSearchResult> searchMembresAdvanced({
|
||||
required MembreSearchCriteria criteria,
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
String sortField = 'nom',
|
||||
String sortDirection = 'asc',
|
||||
}) async {
|
||||
AppLogger.info('Recherche avancée de membres: ${criteria.description}');
|
||||
|
||||
try {
|
||||
// Validation des critères
|
||||
if (!criteria.hasAnyCriteria) {
|
||||
throw Exception('Au moins un critère de recherche doit être spécifié');
|
||||
}
|
||||
|
||||
if (!criteria.isValid) {
|
||||
throw Exception('Critères de recherche invalides');
|
||||
}
|
||||
|
||||
// Préparation des paramètres de requête
|
||||
final queryParams = {
|
||||
'page': page.toString(),
|
||||
'size': size.toString(),
|
||||
'sort': sortField,
|
||||
'direction': sortDirection,
|
||||
};
|
||||
|
||||
// Appel API
|
||||
final response = await _apiClient.post(
|
||||
'/api/membres/search/advanced',
|
||||
data: criteria.toJson(),
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
|
||||
// Parsing de la réponse
|
||||
final result = MembreSearchResult.fromJson(response.data);
|
||||
|
||||
AppLogger.info('Recherche terminée: ${result.totalElements} résultats en ${result.executionTimeMs}ms');
|
||||
|
||||
return result;
|
||||
} on DioException catch (e, st) {
|
||||
AppLogger.error('MembreSearchService: recherche avancée échouée', error: e, stackTrace: st);
|
||||
rethrow;
|
||||
} catch (e, st) {
|
||||
AppLogger.error('MembreSearchService: erreur inattendue recherche', error: e, stackTrace: st);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
/// Recherche rapide par terme général
|
||||
///
|
||||
/// [query] Terme de recherche
|
||||
/// [page] Numéro de page
|
||||
/// [size] Taille de la page
|
||||
///
|
||||
/// Returns [MembreSearchResult] avec les résultats
|
||||
Future<MembreSearchResult> quickSearch({
|
||||
required String query,
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
}) async {
|
||||
final criteria = MembreSearchCriteria.quickSearch(query);
|
||||
return searchMembresAdvanced(
|
||||
criteria: criteria,
|
||||
page: page,
|
||||
size: size,
|
||||
);
|
||||
}
|
||||
|
||||
/// Recherche des membres actifs uniquement
|
||||
///
|
||||
/// [page] Numéro de page
|
||||
/// [size] Taille de la page
|
||||
///
|
||||
/// Returns [MembreSearchResult] avec les membres actifs
|
||||
Future<MembreSearchResult> searchActiveMembers({
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
}) async {
|
||||
return searchMembresAdvanced(
|
||||
criteria: MembreSearchCriteria.activeMembers,
|
||||
page: page,
|
||||
size: size,
|
||||
);
|
||||
}
|
||||
|
||||
/// Recherche des membres du bureau
|
||||
///
|
||||
/// [page] Numéro de page
|
||||
/// [size] Taille de la page
|
||||
///
|
||||
/// Returns [MembreSearchResult] avec les membres du bureau
|
||||
Future<MembreSearchResult> searchBureauMembers({
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
}) async {
|
||||
return searchMembresAdvanced(
|
||||
criteria: MembreSearchCriteria.bureauMembers,
|
||||
page: page,
|
||||
size: size,
|
||||
);
|
||||
}
|
||||
|
||||
/// Recherche par organisation
|
||||
///
|
||||
/// [organisationIds] Liste des IDs d'organisations
|
||||
/// [page] Numéro de page
|
||||
/// [size] Taille de la page
|
||||
///
|
||||
/// Returns [MembreSearchResult] avec les membres des organisations
|
||||
Future<MembreSearchResult> searchByOrganisations({
|
||||
required List<String> organisationIds,
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
}) async {
|
||||
final criteria = MembreSearchCriteria(
|
||||
organisationIds: organisationIds,
|
||||
statut: 'ACTIF',
|
||||
);
|
||||
return searchMembresAdvanced(
|
||||
criteria: criteria,
|
||||
page: page,
|
||||
size: size,
|
||||
);
|
||||
}
|
||||
|
||||
/// Recherche par tranche d'âge
|
||||
///
|
||||
/// [ageMin] Âge minimum
|
||||
/// [ageMax] Âge maximum
|
||||
/// [page] Numéro de page
|
||||
/// [size] Taille de la page
|
||||
///
|
||||
/// Returns [MembreSearchResult] avec les membres dans la tranche d'âge
|
||||
Future<MembreSearchResult> searchByAgeRange({
|
||||
int? ageMin,
|
||||
int? ageMax,
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
}) async {
|
||||
final criteria = MembreSearchCriteria(
|
||||
ageMin: ageMin,
|
||||
ageMax: ageMax,
|
||||
statut: 'ACTIF',
|
||||
);
|
||||
return searchMembresAdvanced(
|
||||
criteria: criteria,
|
||||
page: page,
|
||||
size: size,
|
||||
);
|
||||
}
|
||||
|
||||
/// Recherche par région
|
||||
///
|
||||
/// [region] Nom de la région
|
||||
/// [page] Numéro de page
|
||||
/// [size] Taille de la page
|
||||
///
|
||||
/// Returns [MembreSearchResult] avec les membres de la région
|
||||
Future<MembreSearchResult> searchByRegion({
|
||||
required String region,
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
}) async {
|
||||
final criteria = MembreSearchCriteria(
|
||||
region: region,
|
||||
statut: 'ACTIF',
|
||||
);
|
||||
return searchMembresAdvanced(
|
||||
criteria: criteria,
|
||||
page: page,
|
||||
size: size,
|
||||
);
|
||||
}
|
||||
|
||||
/// Recherche par rôles
|
||||
///
|
||||
/// [roles] Liste des rôles
|
||||
/// [page] Numéro de page
|
||||
/// [size] Taille de la page
|
||||
///
|
||||
/// Returns [MembreSearchResult] avec les membres ayant ces rôles
|
||||
Future<MembreSearchResult> searchByRoles({
|
||||
required List<String> roles,
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
}) async {
|
||||
final criteria = MembreSearchCriteria(
|
||||
roles: roles,
|
||||
statut: 'ACTIF',
|
||||
);
|
||||
return searchMembresAdvanced(
|
||||
criteria: criteria,
|
||||
page: page,
|
||||
size: size,
|
||||
);
|
||||
}
|
||||
|
||||
/// Recherche par période d'adhésion
|
||||
///
|
||||
/// [dateMin] Date minimum (ISO 8601)
|
||||
/// [dateMax] Date maximum (ISO 8601)
|
||||
/// [page] Numéro de page
|
||||
/// [size] Taille de la page
|
||||
///
|
||||
/// Returns [MembreSearchResult] avec les membres adhérés dans la période
|
||||
Future<MembreSearchResult> searchByAdhesionPeriod({
|
||||
String? dateMin,
|
||||
String? dateMax,
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
}) async {
|
||||
final criteria = MembreSearchCriteria(
|
||||
dateAdhesionMin: dateMin,
|
||||
dateAdhesionMax: dateMax,
|
||||
statut: 'ACTIF',
|
||||
);
|
||||
return searchMembresAdvanced(
|
||||
criteria: criteria,
|
||||
page: page,
|
||||
size: size,
|
||||
);
|
||||
}
|
||||
|
||||
/// Valide les critères de recherche avant envoi
|
||||
bool validateCriteria(MembreSearchCriteria criteria) {
|
||||
if (!criteria.hasAnyCriteria) {
|
||||
AppLogger.warning('MembreSearchService: aucun critère de recherche spécifié');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!criteria.isValid) {
|
||||
AppLogger.warning('MembreSearchService: critères invalides', tag: criteria.description);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Estime le temps de recherche basé sur les critères
|
||||
Duration estimateSearchTime(MembreSearchCriteria criteria) {
|
||||
// Estimation basique - peut être améliorée avec des métriques réelles
|
||||
int complexityScore = 0;
|
||||
|
||||
if (criteria.query?.isNotEmpty == true) complexityScore += 2;
|
||||
if (criteria.organisationIds?.isNotEmpty == true) complexityScore += 1;
|
||||
if (criteria.roles?.isNotEmpty == true) complexityScore += 1;
|
||||
if (criteria.ageMin != null || criteria.ageMax != null) complexityScore += 1;
|
||||
if (criteria.dateAdhesionMin != null || criteria.dateAdhesionMax != null) complexityScore += 1;
|
||||
|
||||
// Temps de base + complexité
|
||||
const baseTime = 100; // 100ms de base
|
||||
final additionalTime = complexityScore * 50; // 50ms par critère
|
||||
|
||||
return Duration(milliseconds: baseTime + additionalTime);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user