current outlet

This commit is contained in:
efrilm
2025-10-24 13:55:00 +07:00
parent 97c03bcf96
commit 4dbdcadeaf
27 changed files with 2201 additions and 11 deletions
+18 -1
View File
@@ -4,6 +4,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../domain/auth/auth.dart';
import '../../domain/outlet/outlet.dart';
part 'auth_event.dart';
part 'auth_state.dart';
@@ -12,7 +13,9 @@ part 'auth_bloc.freezed.dart';
@injectable
class AuthBloc extends Bloc<AuthEvent, AuthState> {
final IAuthRepository _repository;
AuthBloc(this._repository) : super(AuthState.initial()) {
final IOutletRepository _outletRepository;
AuthBloc(this._repository, this._outletRepository)
: super(AuthState.initial()) {
on<AuthEvent>(_onAuthEvent);
}
@@ -43,6 +46,20 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
),
),
);
add(AuthEvent.fetchCurrentOutlet(state.user.outletId));
},
fetchCurrentOutlet: (e) async {
emit(state.copyWith(failureOutletOption: none()));
final failureOrOutlet = await _outletRepository.getOutletById(
e.outletId,
);
failureOrOutlet.fold(
(f) => emit(state.copyWith(failureOutletOption: optionOf(f))),
(outlet) => emit(state.copyWith(outlet: outlet)),
);
},
);
}
+248 -4
View File
@@ -20,27 +20,33 @@ mixin _$AuthEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() fetchCurrentUser,
required TResult Function(String outletId) fetchCurrentOutlet,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? fetchCurrentUser,
TResult? Function(String outletId)? fetchCurrentOutlet,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? fetchCurrentUser,
TResult Function(String outletId)? fetchCurrentOutlet,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_FetchCurrentUser value) fetchCurrentUser,
required TResult Function(_FetchCurrentOutlet value) fetchCurrentOutlet,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_FetchCurrentUser value)? fetchCurrentUser,
TResult? Function(_FetchCurrentOutlet value)? fetchCurrentOutlet,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_FetchCurrentUser value)? fetchCurrentUser,
TResult Function(_FetchCurrentOutlet value)? fetchCurrentOutlet,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
}
@@ -109,6 +115,7 @@ class _$FetchCurrentUserImpl implements _FetchCurrentUser {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() fetchCurrentUser,
required TResult Function(String outletId) fetchCurrentOutlet,
}) {
return fetchCurrentUser();
}
@@ -117,6 +124,7 @@ class _$FetchCurrentUserImpl implements _FetchCurrentUser {
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? fetchCurrentUser,
TResult? Function(String outletId)? fetchCurrentOutlet,
}) {
return fetchCurrentUser?.call();
}
@@ -125,6 +133,7 @@ class _$FetchCurrentUserImpl implements _FetchCurrentUser {
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? fetchCurrentUser,
TResult Function(String outletId)? fetchCurrentOutlet,
required TResult orElse(),
}) {
if (fetchCurrentUser != null) {
@@ -137,6 +146,7 @@ class _$FetchCurrentUserImpl implements _FetchCurrentUser {
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_FetchCurrentUser value) fetchCurrentUser,
required TResult Function(_FetchCurrentOutlet value) fetchCurrentOutlet,
}) {
return fetchCurrentUser(this);
}
@@ -145,6 +155,7 @@ class _$FetchCurrentUserImpl implements _FetchCurrentUser {
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_FetchCurrentUser value)? fetchCurrentUser,
TResult? Function(_FetchCurrentOutlet value)? fetchCurrentOutlet,
}) {
return fetchCurrentUser?.call(this);
}
@@ -153,6 +164,7 @@ class _$FetchCurrentUserImpl implements _FetchCurrentUser {
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_FetchCurrentUser value)? fetchCurrentUser,
TResult Function(_FetchCurrentOutlet value)? fetchCurrentOutlet,
required TResult orElse(),
}) {
if (fetchCurrentUser != null) {
@@ -166,12 +178,163 @@ abstract class _FetchCurrentUser implements AuthEvent {
const factory _FetchCurrentUser() = _$FetchCurrentUserImpl;
}
/// @nodoc
abstract class _$$FetchCurrentOutletImplCopyWith<$Res> {
factory _$$FetchCurrentOutletImplCopyWith(
_$FetchCurrentOutletImpl value,
$Res Function(_$FetchCurrentOutletImpl) then,
) = __$$FetchCurrentOutletImplCopyWithImpl<$Res>;
@useResult
$Res call({String outletId});
}
/// @nodoc
class __$$FetchCurrentOutletImplCopyWithImpl<$Res>
extends _$AuthEventCopyWithImpl<$Res, _$FetchCurrentOutletImpl>
implements _$$FetchCurrentOutletImplCopyWith<$Res> {
__$$FetchCurrentOutletImplCopyWithImpl(
_$FetchCurrentOutletImpl _value,
$Res Function(_$FetchCurrentOutletImpl) _then,
) : super(_value, _then);
/// Create a copy of AuthEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? outletId = null}) {
return _then(
_$FetchCurrentOutletImpl(
null == outletId
? _value.outletId
: outletId // ignore: cast_nullable_to_non_nullable
as String,
),
);
}
}
/// @nodoc
class _$FetchCurrentOutletImpl implements _FetchCurrentOutlet {
const _$FetchCurrentOutletImpl(this.outletId);
@override
final String outletId;
@override
String toString() {
return 'AuthEvent.fetchCurrentOutlet(outletId: $outletId)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FetchCurrentOutletImpl &&
(identical(other.outletId, outletId) ||
other.outletId == outletId));
}
@override
int get hashCode => Object.hash(runtimeType, outletId);
/// Create a copy of AuthEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$FetchCurrentOutletImplCopyWith<_$FetchCurrentOutletImpl> get copyWith =>
__$$FetchCurrentOutletImplCopyWithImpl<_$FetchCurrentOutletImpl>(
this,
_$identity,
);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() fetchCurrentUser,
required TResult Function(String outletId) fetchCurrentOutlet,
}) {
return fetchCurrentOutlet(outletId);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? fetchCurrentUser,
TResult? Function(String outletId)? fetchCurrentOutlet,
}) {
return fetchCurrentOutlet?.call(outletId);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? fetchCurrentUser,
TResult Function(String outletId)? fetchCurrentOutlet,
required TResult orElse(),
}) {
if (fetchCurrentOutlet != null) {
return fetchCurrentOutlet(outletId);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_FetchCurrentUser value) fetchCurrentUser,
required TResult Function(_FetchCurrentOutlet value) fetchCurrentOutlet,
}) {
return fetchCurrentOutlet(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_FetchCurrentUser value)? fetchCurrentUser,
TResult? Function(_FetchCurrentOutlet value)? fetchCurrentOutlet,
}) {
return fetchCurrentOutlet?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_FetchCurrentUser value)? fetchCurrentUser,
TResult Function(_FetchCurrentOutlet value)? fetchCurrentOutlet,
required TResult orElse(),
}) {
if (fetchCurrentOutlet != null) {
return fetchCurrentOutlet(this);
}
return orElse();
}
}
abstract class _FetchCurrentOutlet implements AuthEvent {
const factory _FetchCurrentOutlet(final String outletId) =
_$FetchCurrentOutletImpl;
String get outletId;
/// Create a copy of AuthEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$FetchCurrentOutletImplCopyWith<_$FetchCurrentOutletImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$AuthState {
User get user => throw _privateConstructorUsedError;
Outlet get outlet => throw _privateConstructorUsedError;
AuthStatus get status => throw _privateConstructorUsedError;
Option<AuthFailure> get failureOption => throw _privateConstructorUsedError;
Option<OutletFailure> get failureOutletOption =>
throw _privateConstructorUsedError;
bool get isFetching => throw _privateConstructorUsedError;
bool get isFetchingOutlet => throw _privateConstructorUsedError;
/// Create a copy of AuthState
/// with the given fields replaced by the non-null parameter values.
@@ -187,12 +350,16 @@ abstract class $AuthStateCopyWith<$Res> {
@useResult
$Res call({
User user,
Outlet outlet,
AuthStatus status,
Option<AuthFailure> failureOption,
Option<OutletFailure> failureOutletOption,
bool isFetching,
bool isFetchingOutlet,
});
$UserCopyWith<$Res> get user;
$OutletCopyWith<$Res> get outlet;
$AuthStatusCopyWith<$Res> get status;
}
@@ -212,9 +379,12 @@ class _$AuthStateCopyWithImpl<$Res, $Val extends AuthState>
@override
$Res call({
Object? user = null,
Object? outlet = null,
Object? status = null,
Object? failureOption = null,
Object? failureOutletOption = null,
Object? isFetching = null,
Object? isFetchingOutlet = null,
}) {
return _then(
_value.copyWith(
@@ -222,6 +392,10 @@ class _$AuthStateCopyWithImpl<$Res, $Val extends AuthState>
? _value.user
: user // ignore: cast_nullable_to_non_nullable
as User,
outlet: null == outlet
? _value.outlet
: outlet // ignore: cast_nullable_to_non_nullable
as Outlet,
status: null == status
? _value.status
: status // ignore: cast_nullable_to_non_nullable
@@ -230,10 +404,18 @@ class _$AuthStateCopyWithImpl<$Res, $Val extends AuthState>
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AuthFailure>,
failureOutletOption: null == failureOutletOption
? _value.failureOutletOption
: failureOutletOption // ignore: cast_nullable_to_non_nullable
as Option<OutletFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
isFetchingOutlet: null == isFetchingOutlet
? _value.isFetchingOutlet
: isFetchingOutlet // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
@@ -249,6 +431,16 @@ class _$AuthStateCopyWithImpl<$Res, $Val extends AuthState>
});
}
/// Create a copy of AuthState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$OutletCopyWith<$Res> get outlet {
return $OutletCopyWith<$Res>(_value.outlet, (value) {
return _then(_value.copyWith(outlet: value) as $Val);
});
}
/// Create a copy of AuthState
/// with the given fields replaced by the non-null parameter values.
@override
@@ -271,14 +463,19 @@ abstract class _$$AuthStateImplCopyWith<$Res>
@useResult
$Res call({
User user,
Outlet outlet,
AuthStatus status,
Option<AuthFailure> failureOption,
Option<OutletFailure> failureOutletOption,
bool isFetching,
bool isFetchingOutlet,
});
@override
$UserCopyWith<$Res> get user;
@override
$OutletCopyWith<$Res> get outlet;
@override
$AuthStatusCopyWith<$Res> get status;
}
@@ -297,9 +494,12 @@ class __$$AuthStateImplCopyWithImpl<$Res>
@override
$Res call({
Object? user = null,
Object? outlet = null,
Object? status = null,
Object? failureOption = null,
Object? failureOutletOption = null,
Object? isFetching = null,
Object? isFetchingOutlet = null,
}) {
return _then(
_$AuthStateImpl(
@@ -307,6 +507,10 @@ class __$$AuthStateImplCopyWithImpl<$Res>
? _value.user
: user // ignore: cast_nullable_to_non_nullable
as User,
outlet: null == outlet
? _value.outlet
: outlet // ignore: cast_nullable_to_non_nullable
as Outlet,
status: null == status
? _value.status
: status // ignore: cast_nullable_to_non_nullable
@@ -315,10 +519,18 @@ class __$$AuthStateImplCopyWithImpl<$Res>
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AuthFailure>,
failureOutletOption: null == failureOutletOption
? _value.failureOutletOption
: failureOutletOption // ignore: cast_nullable_to_non_nullable
as Option<OutletFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
isFetchingOutlet: null == isFetchingOutlet
? _value.isFetchingOutlet
: isFetchingOutlet // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
@@ -329,25 +541,35 @@ class __$$AuthStateImplCopyWithImpl<$Res>
class _$AuthStateImpl extends _AuthState {
const _$AuthStateImpl({
required this.user,
required this.outlet,
this.status = const AuthStatus.initial(),
required this.failureOption,
required this.failureOutletOption,
this.isFetching = false,
this.isFetchingOutlet = false,
}) : super._();
@override
final User user;
@override
final Outlet outlet;
@override
@JsonKey()
final AuthStatus status;
@override
final Option<AuthFailure> failureOption;
@override
final Option<OutletFailure> failureOutletOption;
@override
@JsonKey()
final bool isFetching;
@override
@JsonKey()
final bool isFetchingOutlet;
@override
String toString() {
return 'AuthState(user: $user, status: $status, failureOption: $failureOption, isFetching: $isFetching)';
return 'AuthState(user: $user, outlet: $outlet, status: $status, failureOption: $failureOption, failureOutletOption: $failureOutletOption, isFetching: $isFetching, isFetchingOutlet: $isFetchingOutlet)';
}
@override
@@ -356,16 +578,29 @@ class _$AuthStateImpl extends _AuthState {
(other.runtimeType == runtimeType &&
other is _$AuthStateImpl &&
(identical(other.user, user) || other.user == user) &&
(identical(other.outlet, outlet) || other.outlet == outlet) &&
(identical(other.status, status) || other.status == status) &&
(identical(other.failureOption, failureOption) ||
other.failureOption == failureOption) &&
(identical(other.failureOutletOption, failureOutletOption) ||
other.failureOutletOption == failureOutletOption) &&
(identical(other.isFetching, isFetching) ||
other.isFetching == isFetching));
other.isFetching == isFetching) &&
(identical(other.isFetchingOutlet, isFetchingOutlet) ||
other.isFetchingOutlet == isFetchingOutlet));
}
@override
int get hashCode =>
Object.hash(runtimeType, user, status, failureOption, isFetching);
int get hashCode => Object.hash(
runtimeType,
user,
outlet,
status,
failureOption,
failureOutletOption,
isFetching,
isFetchingOutlet,
);
/// Create a copy of AuthState
/// with the given fields replaced by the non-null parameter values.
@@ -379,20 +614,29 @@ class _$AuthStateImpl extends _AuthState {
abstract class _AuthState extends AuthState {
const factory _AuthState({
required final User user,
required final Outlet outlet,
final AuthStatus status,
required final Option<AuthFailure> failureOption,
required final Option<OutletFailure> failureOutletOption,
final bool isFetching,
final bool isFetchingOutlet,
}) = _$AuthStateImpl;
const _AuthState._() : super._();
@override
User get user;
@override
Outlet get outlet;
@override
AuthStatus get status;
@override
Option<AuthFailure> get failureOption;
@override
Option<OutletFailure> get failureOutletOption;
@override
bool get isFetching;
@override
bool get isFetchingOutlet;
/// Create a copy of AuthState
/// with the given fields replaced by the non-null parameter values.
+2
View File
@@ -3,4 +3,6 @@ part of 'auth_bloc.dart';
@freezed
class AuthEvent with _$AuthEvent {
const factory AuthEvent.fetchCurrentUser() = _FetchCurrentUser;
const factory AuthEvent.fetchCurrentOutlet(String outletId) =
_FetchCurrentOutlet;
}
+9 -2
View File
@@ -6,13 +6,20 @@ class AuthState with _$AuthState {
const factory AuthState({
required User user,
required Outlet outlet,
@Default(AuthStatus.initial()) AuthStatus status,
required Option<AuthFailure> failureOption,
required Option<OutletFailure> failureOutletOption,
@Default(false) bool isFetching,
@Default(false) bool isFetchingOutlet,
}) = _AuthState;
factory AuthState.initial() =>
AuthState(user: User.empty(), failureOption: none());
factory AuthState.initial() => AuthState(
user: User.empty(),
failureOption: none(),
outlet: Outlet.empty(),
failureOutletOption: none(),
);
bool get isAuthenticated => status == const AuthStatus.authenticated();
bool get isInitial => status == const AuthStatus.initial();