From 80a8bfb90568be208e430d9cabf9d77589d8beba Mon Sep 17 00:00:00 2001 From: Yuri Petrov <48598325+petrovyuri@users.noreply.github.com> Date: Wed, 25 Jun 2025 10:31:37 +0300 Subject: [PATCH] =?UTF-8?q?feat(profile):=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D1=83=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B2=D1=8B=D1=85=D0=BE=D0=B4=D0=B0=20=D0=B8=D0=B7=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D1=84=D0=B8=D0=BB=D1=8F=20=D0=B8=20rethrow=20(#17)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: PetrovY --- .../profile/domain/bloc/profile_bloc.dart | 19 +++++++++++++++++ .../profile/domain/bloc/profile_event.dart | 21 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/features/profile/domain/bloc/profile_bloc.dart b/lib/features/profile/domain/bloc/profile_bloc.dart index 1fe03fc..93d5810 100644 --- a/lib/features/profile/domain/bloc/profile_bloc.dart +++ b/lib/features/profile/domain/bloc/profile_bloc.dart @@ -16,9 +16,14 @@ class ProfileBloc extends Bloc { ProfileBloc(this._profileRepository) : super(ProfileInitialState()) { // Регистрируем обработчики событий в конструкторе on((event, emit) async { + // Обрабатываем событие загрузки профиля if (event is ProfileFetchProfileEvent) { await _fetchProfile(event, emit); } + // Обрабатываем событие выхода из профиля + else if (event is ProfileLogoutProfileEvent) { + await _logout(event, emit); + } }); } @@ -44,6 +49,7 @@ class ProfileBloc extends Bloc { final data = await _profileRepository.fetchUserProfile(event.id); emit(ProfileSuccessState(data: data)); } on Object catch (error, stackTrace) { + // Обработка ошибки при загрузке профиля emit( ProfileErrorState( message: 'Ошибка при загрузке профиля', @@ -51,6 +57,19 @@ class ProfileBloc extends Bloc { stackTrace: stackTrace, ), ); + // Пробрасываем исключение дальше, для логирования или обработки + rethrow; } } + + /// Метод для выхода из профиля пользователя. + Future _logout( + ProfileLogoutProfileEvent event, + Emitter emit, + ) async { + // Здесь можно добавить логику выхода из профиля + // Например, очистка токенов, данных пользователя и т.д. + // В данном примере просто эмитим начальное состояние + emit(ProfileInitialState()); + } } diff --git a/lib/features/profile/domain/bloc/profile_event.dart b/lib/features/profile/domain/bloc/profile_event.dart index 69c50c8..4410dfd 100644 --- a/lib/features/profile/domain/bloc/profile_event.dart +++ b/lib/features/profile/domain/bloc/profile_event.dart @@ -1,16 +1,37 @@ part of 'profile_bloc.dart'; +/// {@template profile_event} +/// События для управления состоянием профиля пользователя. +/// {@endtemplate} sealed class ProfileEvent extends Equatable { + /// {@macro profile_event} const ProfileEvent(); @override List get props => []; } +/// {@template profile_event} +/// Событие для загрузки профиля пользователя. +/// {@endtemplate} final class ProfileFetchProfileEvent extends ProfileEvent { + /// {@macro profile_event} const ProfileFetchProfileEvent({required this.id}); + + /// ID пользователя для загрузки профиля final String id; @override List get props => [id]; } + +/// {@template profile_logout_event} +/// Событие для выхода из профиля пользователя. +/// {@endtemplate} +final class ProfileLogoutProfileEvent extends ProfileEvent { + /// {@macro profile_logout_event} + const ProfileLogoutProfileEvent(); + + @override + List get props => []; +}