refactoring

This commit is contained in:
dahoud
2026-03-31 09:14:47 +00:00
parent 9bfffeeebe
commit 5383df6dcb
200 changed files with 11192 additions and 7063 deletions

View File

@@ -28,6 +28,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
on<LoadMe>(_onLoadMe);
on<LoadMyProfile>(_onLoadMyProfile);
on<UpdateMyProfile>(_onUpdateMyProfile);
on<ChangePassword>(_onChangePassword);
on<DeleteAccount>(_onDeleteAccount);
}
/// Charge le profil du membre connecté
@@ -44,8 +46,10 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
emit(const ProfileNotFound());
}
} on DioException catch (e) {
if (e.type == DioExceptionType.cancel) return;
emit(ProfileError(_networkErrorMessage(e)));
} catch (e) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
emit(ProfileError('Erreur lors du chargement du profil : $e'));
}
}
@@ -65,8 +69,10 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
emit(const ProfileNotFound());
}
} on DioException catch (e) {
if (e.type == DioExceptionType.cancel) return;
emit(ProfileError(_networkErrorMessage(e)));
} catch (e) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
emit(ProfileError('Erreur lors du chargement du profil : $e'));
}
}
@@ -84,15 +90,57 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
final updated = await _updateProfile(event.membreId, event.membre);
emit(ProfileUpdated(updated));
} on DioException catch (e) {
if (e.type == DioExceptionType.cancel) return;
if (currentState is ProfileLoaded) {
emit(ProfileLoaded(currentState.membre));
}
emit(ProfileError(_networkErrorMessage(e)));
} catch (e) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
emit(ProfileError('Erreur lors de la mise à jour du profil : $e'));
}
}
/// Change le mot de passe via Keycloak
Future<void> _onChangePassword(
ChangePassword event,
Emitter<ProfileState> emit,
) async {
final previousState = state;
try {
emit(const PasswordChanging());
await _repository.changePassword(event.membreId, event.oldPassword, event.newPassword);
emit(const PasswordChanged());
if (previousState is ProfileLoaded) emit(previousState);
} on DioException catch (e) {
if (e.type == DioExceptionType.cancel) return;
emit(ProfileError(_networkErrorMessage(e)));
if (previousState is ProfileLoaded) emit(previousState);
} catch (e) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
emit(ProfileError(e.toString().replaceFirst('Exception: ', '')));
if (previousState is ProfileLoaded) emit(previousState);
}
}
/// Supprime le compte (soft delete)
Future<void> _onDeleteAccount(
DeleteAccount event,
Emitter<ProfileState> emit,
) async {
try {
emit(const AccountDeleting());
await _repository.deleteAccount(event.membreId);
emit(const AccountDeleted());
} on DioException catch (e) {
if (e.type == DioExceptionType.cancel) return;
emit(ProfileError(_networkErrorMessage(e)));
} catch (e) {
if (e is DioException && e.type == DioExceptionType.cancel) return;
emit(ProfileError(e.toString().replaceFirst('Exception: ', '')));
}
}
String _networkErrorMessage(DioException e) {
switch (e.type) {
case DioExceptionType.connectionTimeout: