refactoring
This commit is contained in:
@@ -29,20 +29,74 @@ class ProfileRepositoryImpl implements IProfileRepository {
|
||||
}
|
||||
return null;
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.cancel) rethrow;
|
||||
if (e.response?.statusCode == 404) return null;
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
/// Adapte les clés backend (MembreResponse) vers le modèle mobile si besoin
|
||||
/// Adapte les clés backend (MembreResponse) vers le modèle mobile
|
||||
void _normalizeMembreResponse(Map<String, dynamic> data) {
|
||||
// photoUrl → photo
|
||||
if (data.containsKey('photoUrl') && !data.containsKey('photo')) {
|
||||
data['photo'] = data['photoUrl'];
|
||||
}
|
||||
|
||||
// associationNom → organisationNom
|
||||
if (data.containsKey('associationNom') && !data.containsKey('organisationNom')) {
|
||||
data['organisationNom'] = data['associationNom'];
|
||||
}
|
||||
if (data['id'] is String == false && data['id'] != null) {
|
||||
|
||||
// statutCompte → statut (avec mapping des valeurs)
|
||||
if (data.containsKey('statutCompte') && !data.containsKey('statut')) {
|
||||
final sc = (data['statutCompte'] as String? ?? '').toUpperCase();
|
||||
if (sc == 'ACTIF') {
|
||||
data['statut'] = 'ACTIF';
|
||||
} else if (sc == 'INACTIF') {
|
||||
data['statut'] = 'INACTIF';
|
||||
} else if (sc == 'SUSPENDU') {
|
||||
data['statut'] = 'SUSPENDU';
|
||||
} else {
|
||||
// EN_ATTENTE_VALIDATION, EN_ATTENTE, etc.
|
||||
data['statut'] = 'EN_ATTENTE';
|
||||
}
|
||||
}
|
||||
|
||||
// roles (List<String>) → role (premier rôle)
|
||||
if (data.containsKey('roles') && !data.containsKey('role')) {
|
||||
final roles = data['roles'];
|
||||
if (roles is List && roles.isNotEmpty) {
|
||||
data['role'] = roles.first?.toString();
|
||||
}
|
||||
}
|
||||
|
||||
// Dates LocalDate [year, month, day] → ISO string "YYYY-MM-DD"
|
||||
for (final field in ['dateNaissance', 'dateAdhesion', 'dateFinAdhesion', 'dateVerificationIdentite']) {
|
||||
final val = data[field];
|
||||
if (val is List && val.length >= 3) {
|
||||
final y = val[0].toString().padLeft(4, '0');
|
||||
final m = val[1].toString().padLeft(2, '0');
|
||||
final d = val[2].toString().padLeft(2, '0');
|
||||
data[field] = '$y-$m-$d';
|
||||
}
|
||||
}
|
||||
|
||||
// Dates LocalDateTime [year, month, day, h, min, s, ns] → ISO string
|
||||
for (final field in ['dateCreation', 'dateModification', 'derniereActivite']) {
|
||||
final val = data[field];
|
||||
if (val is List && val.length >= 3) {
|
||||
final y = val[0].toString().padLeft(4, '0');
|
||||
final m = val[1].toString().padLeft(2, '0');
|
||||
final d = val[2].toString().padLeft(2, '0');
|
||||
final h = val.length > 3 ? val[3].toString().padLeft(2, '0') : '00';
|
||||
final min = val.length > 4 ? val[4].toString().padLeft(2, '0') : '00';
|
||||
final s = val.length > 5 ? val[5].toString().padLeft(2, '0') : '00';
|
||||
data[field] = '$y-$m-${d}T$h:$min:$s';
|
||||
}
|
||||
}
|
||||
|
||||
// id UUID → String
|
||||
if (data['id'] != null && data['id'] is! String) {
|
||||
data['id'] = data['id'].toString();
|
||||
}
|
||||
}
|
||||
@@ -77,6 +131,7 @@ class ProfileRepositoryImpl implements IProfileRepository {
|
||||
}
|
||||
return null;
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.cancel) rethrow;
|
||||
if (e.response?.statusCode == 404) return null;
|
||||
rethrow;
|
||||
}
|
||||
@@ -110,6 +165,7 @@ class ProfileRepositoryImpl implements IProfileRepository {
|
||||
final updated = membre.copyWith(photo: photoUrl);
|
||||
return updateProfile(id, updated);
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.cancel) rethrow;
|
||||
throw Exception('Erreur réseau lors de la mise à jour de la photo: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Erreur lors de la mise à jour de la photo: $e');
|
||||
@@ -135,6 +191,7 @@ class ProfileRepositoryImpl implements IProfileRepository {
|
||||
throw Exception(errorMsg);
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.cancel) rethrow;
|
||||
if (e.response?.statusCode == 400) {
|
||||
throw Exception('Ancien mot de passe incorrect');
|
||||
} else if (e.response?.statusCode == 401) {
|
||||
@@ -161,6 +218,7 @@ class ProfileRepositoryImpl implements IProfileRepository {
|
||||
throw Exception('Erreur lors de la mise à jour des préférences: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.cancel) rethrow;
|
||||
// Si l'endpoint n'existe pas (404), on sauvegarde localement via SharedPreferences
|
||||
if (e.response?.statusCode == 404) {
|
||||
// Fallback: stockage local uniquement
|
||||
@@ -182,6 +240,7 @@ class ProfileRepositoryImpl implements IProfileRepository {
|
||||
throw Exception('Erreur lors de la suppression du compte: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.cancel) rethrow;
|
||||
if (e.response?.statusCode == 403) {
|
||||
throw Exception('Vous n\'avez pas les permissions pour supprimer ce compte');
|
||||
} else if (e.response?.statusCode == 404) {
|
||||
|
||||
Reference in New Issue
Block a user