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:

View File

@@ -30,3 +30,27 @@ class UpdateMyProfile extends ProfileEvent {
@override
List<Object?> get props => [membreId, membre];
}
/// Change le mot de passe via Keycloak
class ChangePassword extends ProfileEvent {
final String membreId;
final String oldPassword;
final String newPassword;
const ChangePassword({
required this.membreId,
required this.oldPassword,
required this.newPassword,
});
@override
List<Object?> get props => [membreId, oldPassword, newPassword];
}
/// Supprime le compte (soft delete backend)
class DeleteAccount extends ProfileEvent {
final String membreId;
const DeleteAccount(this.membreId);
@override
List<Object?> get props => [membreId];
}

View File

@@ -50,3 +50,19 @@ class ProfileError extends ProfileState {
class ProfileNotFound extends ProfileState {
const ProfileNotFound();
}
class PasswordChanging extends ProfileState {
const PasswordChanging();
}
class PasswordChanged extends ProfileState {
const PasswordChanged();
}
class AccountDeleting extends ProfileState {
const AccountDeleting();
}
class AccountDeleted extends ProfileState {
const AccountDeleted();
}