diff --git a/lib/application/auth/auth_bloc.dart b/lib/application/auth/auth_bloc.dart index 0ca87c5..f3e7ae8 100644 --- a/lib/application/auth/auth_bloc.dart +++ b/lib/application/auth/auth_bloc.dart @@ -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 { final IAuthRepository _repository; - AuthBloc(this._repository) : super(AuthState.initial()) { + final IOutletRepository _outletRepository; + AuthBloc(this._repository, this._outletRepository) + : super(AuthState.initial()) { on(_onAuthEvent); } @@ -43,6 +46,20 @@ class AuthBloc extends Bloc { ), ), ); + + 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)), + ); }, ); } diff --git a/lib/application/auth/auth_bloc.freezed.dart b/lib/application/auth/auth_bloc.freezed.dart index 7fd3e02..6c14a07 100644 --- a/lib/application/auth/auth_bloc.freezed.dart +++ b/lib/application/auth/auth_bloc.freezed.dart @@ -20,27 +20,33 @@ mixin _$AuthEvent { @optionalTypeArgs TResult when({ required TResult Function() fetchCurrentUser, + required TResult Function(String outletId) fetchCurrentOutlet, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult? whenOrNull({ TResult? Function()? fetchCurrentUser, + TResult? Function(String outletId)? fetchCurrentOutlet, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeWhen({ TResult Function()? fetchCurrentUser, + TResult Function(String outletId)? fetchCurrentOutlet, required TResult orElse(), }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult map({ required TResult Function(_FetchCurrentUser value) fetchCurrentUser, + required TResult Function(_FetchCurrentOutlet value) fetchCurrentOutlet, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult? mapOrNull({ TResult? Function(_FetchCurrentUser value)? fetchCurrentUser, + TResult? Function(_FetchCurrentOutlet value)? fetchCurrentOutlet, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeMap({ 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({ required TResult Function() fetchCurrentUser, + required TResult Function(String outletId) fetchCurrentOutlet, }) { return fetchCurrentUser(); } @@ -117,6 +124,7 @@ class _$FetchCurrentUserImpl implements _FetchCurrentUser { @optionalTypeArgs TResult? whenOrNull({ TResult? Function()? fetchCurrentUser, + TResult? Function(String outletId)? fetchCurrentOutlet, }) { return fetchCurrentUser?.call(); } @@ -125,6 +133,7 @@ class _$FetchCurrentUserImpl implements _FetchCurrentUser { @optionalTypeArgs TResult maybeWhen({ 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({ 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? 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 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({ + required TResult Function() fetchCurrentUser, + required TResult Function(String outletId) fetchCurrentOutlet, + }) { + return fetchCurrentOutlet(outletId); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? fetchCurrentUser, + TResult? Function(String outletId)? fetchCurrentOutlet, + }) { + return fetchCurrentOutlet?.call(outletId); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? fetchCurrentUser, + TResult Function(String outletId)? fetchCurrentOutlet, + required TResult orElse(), + }) { + if (fetchCurrentOutlet != null) { + return fetchCurrentOutlet(outletId); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_FetchCurrentUser value) fetchCurrentUser, + required TResult Function(_FetchCurrentOutlet value) fetchCurrentOutlet, + }) { + return fetchCurrentOutlet(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_FetchCurrentUser value)? fetchCurrentUser, + TResult? Function(_FetchCurrentOutlet value)? fetchCurrentOutlet, + }) { + return fetchCurrentOutlet?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + 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 get failureOption => throw _privateConstructorUsedError; + Option 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 failureOption, + Option 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, + failureOutletOption: null == failureOutletOption + ? _value.failureOutletOption + : failureOutletOption // ignore: cast_nullable_to_non_nullable + as Option, 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 failureOption, + Option 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, + failureOutletOption: null == failureOutletOption + ? _value.failureOutletOption + : failureOutletOption // ignore: cast_nullable_to_non_nullable + as Option, 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 failureOption; @override + final Option 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 failureOption, + required final Option 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 get failureOption; @override + Option 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. diff --git a/lib/application/auth/auth_event.dart b/lib/application/auth/auth_event.dart index 6c3c293..dcc174d 100644 --- a/lib/application/auth/auth_event.dart +++ b/lib/application/auth/auth_event.dart @@ -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; } diff --git a/lib/application/auth/auth_state.dart b/lib/application/auth/auth_state.dart index 483740d..130d961 100644 --- a/lib/application/auth/auth_state.dart +++ b/lib/application/auth/auth_state.dart @@ -6,13 +6,20 @@ class AuthState with _$AuthState { const factory AuthState({ required User user, + required Outlet outlet, @Default(AuthStatus.initial()) AuthStatus status, required Option failureOption, + required Option 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(); diff --git a/lib/common/constant/local_storage_key.dart b/lib/common/constant/local_storage_key.dart index aebb90f..5be2a70 100644 --- a/lib/common/constant/local_storage_key.dart +++ b/lib/common/constant/local_storage_key.dart @@ -1,4 +1,5 @@ class LocalStorageKey { static const String token = 'token'; static const String user = 'user'; + static const String outlet = 'outlet'; } diff --git a/lib/common/extension/build_context_extension.dart b/lib/common/extension/build_context_extension.dart new file mode 100644 index 0000000..39240eb --- /dev/null +++ b/lib/common/extension/build_context_extension.dart @@ -0,0 +1,7 @@ +part of 'extension.dart'; + +extension BuildContextExt on BuildContext { + double get deviceHeight => MediaQuery.of(this).size.height; + + double get deviceWidth => MediaQuery.of(this).size.width; +} diff --git a/lib/common/extension/extension.dart b/lib/common/extension/extension.dart index 7199fdd..43176ba 100644 --- a/lib/common/extension/extension.dart +++ b/lib/common/extension/extension.dart @@ -1 +1,3 @@ - // TODO: define your code +import 'package:flutter/material.dart'; + +part 'build_context_extension.dart'; diff --git a/lib/common/function/app_function.dart b/lib/common/function/app_function.dart index ddffdda..617d7bf 100644 --- a/lib/common/function/app_function.dart +++ b/lib/common/function/app_function.dart @@ -1,4 +1,8 @@ import 'package:flutter/material.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +import '../../injection.dart'; +import '../constant/local_storage_key.dart'; void dismissKeyboard(BuildContext context) { final currentFocus = FocusScope.of(context); @@ -6,3 +10,10 @@ void dismissKeyboard(BuildContext context) { FocusManager.instance.primaryFocus?.unfocus(); } } + +Map getAuthorizationHeader() { + return { + 'Authorization': + 'Bearer ${getIt().getString(LocalStorageKey.token)}', + }; +} diff --git a/lib/common/url/api_path.dart b/lib/common/url/api_path.dart index 78543f2..7bb6fc8 100644 --- a/lib/common/url/api_path.dart +++ b/lib/common/url/api_path.dart @@ -1,3 +1,4 @@ class ApiPath { static const String login = '/api/v1/auth/login'; + static const String outlets = '/api/v1/outlets'; } diff --git a/lib/domain/outlet/entities/outlet_entity.dart b/lib/domain/outlet/entities/outlet_entity.dart new file mode 100644 index 0000000..b6cebfa --- /dev/null +++ b/lib/domain/outlet/entities/outlet_entity.dart @@ -0,0 +1,32 @@ +part of '../outlet.dart'; + +@freezed +class Outlet with _$Outlet { + const factory Outlet({ + required String id, + required String organizationId, + required String name, + required String address, + required String phoneNumber, + required String businessType, + required String currency, + required double taxRate, + required bool isActive, + required String createdAt, + required String updatedAt, + }) = _Outlet; + + factory Outlet.empty() => const Outlet( + id: '', + organizationId: '', + name: '', + address: '', + phoneNumber: '', + businessType: '', + currency: '', + taxRate: 0.0, + isActive: false, + createdAt: '', + updatedAt: '', + ); +} diff --git a/lib/domain/outlet/failures/outlet_failure.dart b/lib/domain/outlet/failures/outlet_failure.dart new file mode 100644 index 0000000..1f53408 --- /dev/null +++ b/lib/domain/outlet/failures/outlet_failure.dart @@ -0,0 +1,10 @@ +part of '../outlet.dart'; + +@freezed +sealed class OutletFailure with _$OutletFailure { + const factory OutletFailure.serverError(ApiFailure failure) = _ServerError; + const factory OutletFailure.unexpectedError() = _UnexpectedError; + const factory OutletFailure.empty() = _Empty; + const factory OutletFailure.dynamicErrorMessage(String erroMessage) = + _DynamicErrorMessage; +} diff --git a/lib/domain/outlet/outlet.dart b/lib/domain/outlet/outlet.dart new file mode 100644 index 0000000..5423c33 --- /dev/null +++ b/lib/domain/outlet/outlet.dart @@ -0,0 +1,10 @@ +import 'package:dartz/dartz.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +import '../../common/api/api_failure.dart'; + +part 'outlet.freezed.dart'; + +part 'failures/outlet_failure.dart'; +part 'entities/outlet_entity.dart'; +part 'repositories/i_outlet_repository.dart'; diff --git a/lib/domain/outlet/outlet.freezed.dart b/lib/domain/outlet/outlet.freezed.dart new file mode 100644 index 0000000..07ad1c5 --- /dev/null +++ b/lib/domain/outlet/outlet.freezed.dart @@ -0,0 +1,1009 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'outlet.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models', +); + +/// @nodoc +mixin _$OutletFailure { + @optionalTypeArgs + TResult when({ + required TResult Function(ApiFailure failure) serverError, + required TResult Function() unexpectedError, + required TResult Function() empty, + required TResult Function(String erroMessage) dynamicErrorMessage, + }) => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(ApiFailure failure)? serverError, + TResult? Function()? unexpectedError, + TResult? Function()? empty, + TResult? Function(String erroMessage)? dynamicErrorMessage, + }) => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(ApiFailure failure)? serverError, + TResult Function()? unexpectedError, + TResult Function()? empty, + TResult Function(String erroMessage)? dynamicErrorMessage, + required TResult orElse(), + }) => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_ServerError value) serverError, + required TResult Function(_UnexpectedError value) unexpectedError, + required TResult Function(_Empty value) empty, + required TResult Function(_DynamicErrorMessage value) dynamicErrorMessage, + }) => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_ServerError value)? serverError, + TResult? Function(_UnexpectedError value)? unexpectedError, + TResult? Function(_Empty value)? empty, + TResult? Function(_DynamicErrorMessage value)? dynamicErrorMessage, + }) => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_ServerError value)? serverError, + TResult Function(_UnexpectedError value)? unexpectedError, + TResult Function(_Empty value)? empty, + TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage, + required TResult orElse(), + }) => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $OutletFailureCopyWith<$Res> { + factory $OutletFailureCopyWith( + OutletFailure value, + $Res Function(OutletFailure) then, + ) = _$OutletFailureCopyWithImpl<$Res, OutletFailure>; +} + +/// @nodoc +class _$OutletFailureCopyWithImpl<$Res, $Val extends OutletFailure> + implements $OutletFailureCopyWith<$Res> { + _$OutletFailureCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of OutletFailure + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc +abstract class _$$ServerErrorImplCopyWith<$Res> { + factory _$$ServerErrorImplCopyWith( + _$ServerErrorImpl value, + $Res Function(_$ServerErrorImpl) then, + ) = __$$ServerErrorImplCopyWithImpl<$Res>; + @useResult + $Res call({ApiFailure failure}); + + $ApiFailureCopyWith<$Res> get failure; +} + +/// @nodoc +class __$$ServerErrorImplCopyWithImpl<$Res> + extends _$OutletFailureCopyWithImpl<$Res, _$ServerErrorImpl> + implements _$$ServerErrorImplCopyWith<$Res> { + __$$ServerErrorImplCopyWithImpl( + _$ServerErrorImpl _value, + $Res Function(_$ServerErrorImpl) _then, + ) : super(_value, _then); + + /// Create a copy of OutletFailure + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? failure = null}) { + return _then( + _$ServerErrorImpl( + null == failure + ? _value.failure + : failure // ignore: cast_nullable_to_non_nullable + as ApiFailure, + ), + ); + } + + /// Create a copy of OutletFailure + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $ApiFailureCopyWith<$Res> get failure { + return $ApiFailureCopyWith<$Res>(_value.failure, (value) { + return _then(_value.copyWith(failure: value)); + }); + } +} + +/// @nodoc + +class _$ServerErrorImpl implements _ServerError { + const _$ServerErrorImpl(this.failure); + + @override + final ApiFailure failure; + + @override + String toString() { + return 'OutletFailure.serverError(failure: $failure)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ServerErrorImpl && + (identical(other.failure, failure) || other.failure == failure)); + } + + @override + int get hashCode => Object.hash(runtimeType, failure); + + /// Create a copy of OutletFailure + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ServerErrorImplCopyWith<_$ServerErrorImpl> get copyWith => + __$$ServerErrorImplCopyWithImpl<_$ServerErrorImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(ApiFailure failure) serverError, + required TResult Function() unexpectedError, + required TResult Function() empty, + required TResult Function(String erroMessage) dynamicErrorMessage, + }) { + return serverError(failure); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(ApiFailure failure)? serverError, + TResult? Function()? unexpectedError, + TResult? Function()? empty, + TResult? Function(String erroMessage)? dynamicErrorMessage, + }) { + return serverError?.call(failure); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(ApiFailure failure)? serverError, + TResult Function()? unexpectedError, + TResult Function()? empty, + TResult Function(String erroMessage)? dynamicErrorMessage, + required TResult orElse(), + }) { + if (serverError != null) { + return serverError(failure); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_ServerError value) serverError, + required TResult Function(_UnexpectedError value) unexpectedError, + required TResult Function(_Empty value) empty, + required TResult Function(_DynamicErrorMessage value) dynamicErrorMessage, + }) { + return serverError(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_ServerError value)? serverError, + TResult? Function(_UnexpectedError value)? unexpectedError, + TResult? Function(_Empty value)? empty, + TResult? Function(_DynamicErrorMessage value)? dynamicErrorMessage, + }) { + return serverError?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_ServerError value)? serverError, + TResult Function(_UnexpectedError value)? unexpectedError, + TResult Function(_Empty value)? empty, + TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage, + required TResult orElse(), + }) { + if (serverError != null) { + return serverError(this); + } + return orElse(); + } +} + +abstract class _ServerError implements OutletFailure { + const factory _ServerError(final ApiFailure failure) = _$ServerErrorImpl; + + ApiFailure get failure; + + /// Create a copy of OutletFailure + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ServerErrorImplCopyWith<_$ServerErrorImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$UnexpectedErrorImplCopyWith<$Res> { + factory _$$UnexpectedErrorImplCopyWith( + _$UnexpectedErrorImpl value, + $Res Function(_$UnexpectedErrorImpl) then, + ) = __$$UnexpectedErrorImplCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$UnexpectedErrorImplCopyWithImpl<$Res> + extends _$OutletFailureCopyWithImpl<$Res, _$UnexpectedErrorImpl> + implements _$$UnexpectedErrorImplCopyWith<$Res> { + __$$UnexpectedErrorImplCopyWithImpl( + _$UnexpectedErrorImpl _value, + $Res Function(_$UnexpectedErrorImpl) _then, + ) : super(_value, _then); + + /// Create a copy of OutletFailure + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc + +class _$UnexpectedErrorImpl implements _UnexpectedError { + const _$UnexpectedErrorImpl(); + + @override + String toString() { + return 'OutletFailure.unexpectedError()'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && other is _$UnexpectedErrorImpl); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(ApiFailure failure) serverError, + required TResult Function() unexpectedError, + required TResult Function() empty, + required TResult Function(String erroMessage) dynamicErrorMessage, + }) { + return unexpectedError(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(ApiFailure failure)? serverError, + TResult? Function()? unexpectedError, + TResult? Function()? empty, + TResult? Function(String erroMessage)? dynamicErrorMessage, + }) { + return unexpectedError?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(ApiFailure failure)? serverError, + TResult Function()? unexpectedError, + TResult Function()? empty, + TResult Function(String erroMessage)? dynamicErrorMessage, + required TResult orElse(), + }) { + if (unexpectedError != null) { + return unexpectedError(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_ServerError value) serverError, + required TResult Function(_UnexpectedError value) unexpectedError, + required TResult Function(_Empty value) empty, + required TResult Function(_DynamicErrorMessage value) dynamicErrorMessage, + }) { + return unexpectedError(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_ServerError value)? serverError, + TResult? Function(_UnexpectedError value)? unexpectedError, + TResult? Function(_Empty value)? empty, + TResult? Function(_DynamicErrorMessage value)? dynamicErrorMessage, + }) { + return unexpectedError?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_ServerError value)? serverError, + TResult Function(_UnexpectedError value)? unexpectedError, + TResult Function(_Empty value)? empty, + TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage, + required TResult orElse(), + }) { + if (unexpectedError != null) { + return unexpectedError(this); + } + return orElse(); + } +} + +abstract class _UnexpectedError implements OutletFailure { + const factory _UnexpectedError() = _$UnexpectedErrorImpl; +} + +/// @nodoc +abstract class _$$EmptyImplCopyWith<$Res> { + factory _$$EmptyImplCopyWith( + _$EmptyImpl value, + $Res Function(_$EmptyImpl) then, + ) = __$$EmptyImplCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$EmptyImplCopyWithImpl<$Res> + extends _$OutletFailureCopyWithImpl<$Res, _$EmptyImpl> + implements _$$EmptyImplCopyWith<$Res> { + __$$EmptyImplCopyWithImpl( + _$EmptyImpl _value, + $Res Function(_$EmptyImpl) _then, + ) : super(_value, _then); + + /// Create a copy of OutletFailure + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc + +class _$EmptyImpl implements _Empty { + const _$EmptyImpl(); + + @override + String toString() { + return 'OutletFailure.empty()'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && other is _$EmptyImpl); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(ApiFailure failure) serverError, + required TResult Function() unexpectedError, + required TResult Function() empty, + required TResult Function(String erroMessage) dynamicErrorMessage, + }) { + return empty(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(ApiFailure failure)? serverError, + TResult? Function()? unexpectedError, + TResult? Function()? empty, + TResult? Function(String erroMessage)? dynamicErrorMessage, + }) { + return empty?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(ApiFailure failure)? serverError, + TResult Function()? unexpectedError, + TResult Function()? empty, + TResult Function(String erroMessage)? dynamicErrorMessage, + required TResult orElse(), + }) { + if (empty != null) { + return empty(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_ServerError value) serverError, + required TResult Function(_UnexpectedError value) unexpectedError, + required TResult Function(_Empty value) empty, + required TResult Function(_DynamicErrorMessage value) dynamicErrorMessage, + }) { + return empty(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_ServerError value)? serverError, + TResult? Function(_UnexpectedError value)? unexpectedError, + TResult? Function(_Empty value)? empty, + TResult? Function(_DynamicErrorMessage value)? dynamicErrorMessage, + }) { + return empty?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_ServerError value)? serverError, + TResult Function(_UnexpectedError value)? unexpectedError, + TResult Function(_Empty value)? empty, + TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage, + required TResult orElse(), + }) { + if (empty != null) { + return empty(this); + } + return orElse(); + } +} + +abstract class _Empty implements OutletFailure { + const factory _Empty() = _$EmptyImpl; +} + +/// @nodoc +abstract class _$$DynamicErrorMessageImplCopyWith<$Res> { + factory _$$DynamicErrorMessageImplCopyWith( + _$DynamicErrorMessageImpl value, + $Res Function(_$DynamicErrorMessageImpl) then, + ) = __$$DynamicErrorMessageImplCopyWithImpl<$Res>; + @useResult + $Res call({String erroMessage}); +} + +/// @nodoc +class __$$DynamicErrorMessageImplCopyWithImpl<$Res> + extends _$OutletFailureCopyWithImpl<$Res, _$DynamicErrorMessageImpl> + implements _$$DynamicErrorMessageImplCopyWith<$Res> { + __$$DynamicErrorMessageImplCopyWithImpl( + _$DynamicErrorMessageImpl _value, + $Res Function(_$DynamicErrorMessageImpl) _then, + ) : super(_value, _then); + + /// Create a copy of OutletFailure + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? erroMessage = null}) { + return _then( + _$DynamicErrorMessageImpl( + null == erroMessage + ? _value.erroMessage + : erroMessage // ignore: cast_nullable_to_non_nullable + as String, + ), + ); + } +} + +/// @nodoc + +class _$DynamicErrorMessageImpl implements _DynamicErrorMessage { + const _$DynamicErrorMessageImpl(this.erroMessage); + + @override + final String erroMessage; + + @override + String toString() { + return 'OutletFailure.dynamicErrorMessage(erroMessage: $erroMessage)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$DynamicErrorMessageImpl && + (identical(other.erroMessage, erroMessage) || + other.erroMessage == erroMessage)); + } + + @override + int get hashCode => Object.hash(runtimeType, erroMessage); + + /// Create a copy of OutletFailure + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$DynamicErrorMessageImplCopyWith<_$DynamicErrorMessageImpl> get copyWith => + __$$DynamicErrorMessageImplCopyWithImpl<_$DynamicErrorMessageImpl>( + this, + _$identity, + ); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(ApiFailure failure) serverError, + required TResult Function() unexpectedError, + required TResult Function() empty, + required TResult Function(String erroMessage) dynamicErrorMessage, + }) { + return dynamicErrorMessage(erroMessage); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(ApiFailure failure)? serverError, + TResult? Function()? unexpectedError, + TResult? Function()? empty, + TResult? Function(String erroMessage)? dynamicErrorMessage, + }) { + return dynamicErrorMessage?.call(erroMessage); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(ApiFailure failure)? serverError, + TResult Function()? unexpectedError, + TResult Function()? empty, + TResult Function(String erroMessage)? dynamicErrorMessage, + required TResult orElse(), + }) { + if (dynamicErrorMessage != null) { + return dynamicErrorMessage(erroMessage); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_ServerError value) serverError, + required TResult Function(_UnexpectedError value) unexpectedError, + required TResult Function(_Empty value) empty, + required TResult Function(_DynamicErrorMessage value) dynamicErrorMessage, + }) { + return dynamicErrorMessage(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_ServerError value)? serverError, + TResult? Function(_UnexpectedError value)? unexpectedError, + TResult? Function(_Empty value)? empty, + TResult? Function(_DynamicErrorMessage value)? dynamicErrorMessage, + }) { + return dynamicErrorMessage?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_ServerError value)? serverError, + TResult Function(_UnexpectedError value)? unexpectedError, + TResult Function(_Empty value)? empty, + TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage, + required TResult orElse(), + }) { + if (dynamicErrorMessage != null) { + return dynamicErrorMessage(this); + } + return orElse(); + } +} + +abstract class _DynamicErrorMessage implements OutletFailure { + const factory _DynamicErrorMessage(final String erroMessage) = + _$DynamicErrorMessageImpl; + + String get erroMessage; + + /// Create a copy of OutletFailure + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$DynamicErrorMessageImplCopyWith<_$DynamicErrorMessageImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +mixin _$Outlet { + String get id => throw _privateConstructorUsedError; + String get organizationId => throw _privateConstructorUsedError; + String get name => throw _privateConstructorUsedError; + String get address => throw _privateConstructorUsedError; + String get phoneNumber => throw _privateConstructorUsedError; + String get businessType => throw _privateConstructorUsedError; + String get currency => throw _privateConstructorUsedError; + double get taxRate => throw _privateConstructorUsedError; + bool get isActive => throw _privateConstructorUsedError; + String get createdAt => throw _privateConstructorUsedError; + String get updatedAt => throw _privateConstructorUsedError; + + /// Create a copy of Outlet + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $OutletCopyWith get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $OutletCopyWith<$Res> { + factory $OutletCopyWith(Outlet value, $Res Function(Outlet) then) = + _$OutletCopyWithImpl<$Res, Outlet>; + @useResult + $Res call({ + String id, + String organizationId, + String name, + String address, + String phoneNumber, + String businessType, + String currency, + double taxRate, + bool isActive, + String createdAt, + String updatedAt, + }); +} + +/// @nodoc +class _$OutletCopyWithImpl<$Res, $Val extends Outlet> + implements $OutletCopyWith<$Res> { + _$OutletCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of Outlet + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? organizationId = null, + Object? name = null, + Object? address = null, + Object? phoneNumber = null, + Object? businessType = null, + Object? currency = null, + Object? taxRate = null, + Object? isActive = null, + Object? createdAt = null, + Object? updatedAt = null, + }) { + return _then( + _value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + organizationId: null == organizationId + ? _value.organizationId + : organizationId // ignore: cast_nullable_to_non_nullable + as String, + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + address: null == address + ? _value.address + : address // ignore: cast_nullable_to_non_nullable + as String, + phoneNumber: null == phoneNumber + ? _value.phoneNumber + : phoneNumber // ignore: cast_nullable_to_non_nullable + as String, + businessType: null == businessType + ? _value.businessType + : businessType // ignore: cast_nullable_to_non_nullable + as String, + currency: null == currency + ? _value.currency + : currency // ignore: cast_nullable_to_non_nullable + as String, + taxRate: null == taxRate + ? _value.taxRate + : taxRate // ignore: cast_nullable_to_non_nullable + as double, + isActive: null == isActive + ? _value.isActive + : isActive // ignore: cast_nullable_to_non_nullable + as bool, + createdAt: null == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as String, + updatedAt: null == updatedAt + ? _value.updatedAt + : updatedAt // ignore: cast_nullable_to_non_nullable + as String, + ) + as $Val, + ); + } +} + +/// @nodoc +abstract class _$$OutletImplCopyWith<$Res> implements $OutletCopyWith<$Res> { + factory _$$OutletImplCopyWith( + _$OutletImpl value, + $Res Function(_$OutletImpl) then, + ) = __$$OutletImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({ + String id, + String organizationId, + String name, + String address, + String phoneNumber, + String businessType, + String currency, + double taxRate, + bool isActive, + String createdAt, + String updatedAt, + }); +} + +/// @nodoc +class __$$OutletImplCopyWithImpl<$Res> + extends _$OutletCopyWithImpl<$Res, _$OutletImpl> + implements _$$OutletImplCopyWith<$Res> { + __$$OutletImplCopyWithImpl( + _$OutletImpl _value, + $Res Function(_$OutletImpl) _then, + ) : super(_value, _then); + + /// Create a copy of Outlet + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? organizationId = null, + Object? name = null, + Object? address = null, + Object? phoneNumber = null, + Object? businessType = null, + Object? currency = null, + Object? taxRate = null, + Object? isActive = null, + Object? createdAt = null, + Object? updatedAt = null, + }) { + return _then( + _$OutletImpl( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + organizationId: null == organizationId + ? _value.organizationId + : organizationId // ignore: cast_nullable_to_non_nullable + as String, + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + address: null == address + ? _value.address + : address // ignore: cast_nullable_to_non_nullable + as String, + phoneNumber: null == phoneNumber + ? _value.phoneNumber + : phoneNumber // ignore: cast_nullable_to_non_nullable + as String, + businessType: null == businessType + ? _value.businessType + : businessType // ignore: cast_nullable_to_non_nullable + as String, + currency: null == currency + ? _value.currency + : currency // ignore: cast_nullable_to_non_nullable + as String, + taxRate: null == taxRate + ? _value.taxRate + : taxRate // ignore: cast_nullable_to_non_nullable + as double, + isActive: null == isActive + ? _value.isActive + : isActive // ignore: cast_nullable_to_non_nullable + as bool, + createdAt: null == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as String, + updatedAt: null == updatedAt + ? _value.updatedAt + : updatedAt // ignore: cast_nullable_to_non_nullable + as String, + ), + ); + } +} + +/// @nodoc + +class _$OutletImpl implements _Outlet { + const _$OutletImpl({ + required this.id, + required this.organizationId, + required this.name, + required this.address, + required this.phoneNumber, + required this.businessType, + required this.currency, + required this.taxRate, + required this.isActive, + required this.createdAt, + required this.updatedAt, + }); + + @override + final String id; + @override + final String organizationId; + @override + final String name; + @override + final String address; + @override + final String phoneNumber; + @override + final String businessType; + @override + final String currency; + @override + final double taxRate; + @override + final bool isActive; + @override + final String createdAt; + @override + final String updatedAt; + + @override + String toString() { + return 'Outlet(id: $id, organizationId: $organizationId, name: $name, address: $address, phoneNumber: $phoneNumber, businessType: $businessType, currency: $currency, taxRate: $taxRate, isActive: $isActive, createdAt: $createdAt, updatedAt: $updatedAt)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$OutletImpl && + (identical(other.id, id) || other.id == id) && + (identical(other.organizationId, organizationId) || + other.organizationId == organizationId) && + (identical(other.name, name) || other.name == name) && + (identical(other.address, address) || other.address == address) && + (identical(other.phoneNumber, phoneNumber) || + other.phoneNumber == phoneNumber) && + (identical(other.businessType, businessType) || + other.businessType == businessType) && + (identical(other.currency, currency) || + other.currency == currency) && + (identical(other.taxRate, taxRate) || other.taxRate == taxRate) && + (identical(other.isActive, isActive) || + other.isActive == isActive) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && + (identical(other.updatedAt, updatedAt) || + other.updatedAt == updatedAt)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + id, + organizationId, + name, + address, + phoneNumber, + businessType, + currency, + taxRate, + isActive, + createdAt, + updatedAt, + ); + + /// Create a copy of Outlet + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$OutletImplCopyWith<_$OutletImpl> get copyWith => + __$$OutletImplCopyWithImpl<_$OutletImpl>(this, _$identity); +} + +abstract class _Outlet implements Outlet { + const factory _Outlet({ + required final String id, + required final String organizationId, + required final String name, + required final String address, + required final String phoneNumber, + required final String businessType, + required final String currency, + required final double taxRate, + required final bool isActive, + required final String createdAt, + required final String updatedAt, + }) = _$OutletImpl; + + @override + String get id; + @override + String get organizationId; + @override + String get name; + @override + String get address; + @override + String get phoneNumber; + @override + String get businessType; + @override + String get currency; + @override + double get taxRate; + @override + bool get isActive; + @override + String get createdAt; + @override + String get updatedAt; + + /// Create a copy of Outlet + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$OutletImplCopyWith<_$OutletImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/domain/outlet/repositories/i_outlet_repository.dart b/lib/domain/outlet/repositories/i_outlet_repository.dart new file mode 100644 index 0000000..42e222d --- /dev/null +++ b/lib/domain/outlet/repositories/i_outlet_repository.dart @@ -0,0 +1,10 @@ +part of '../outlet.dart'; + +abstract class IOutletRepository { + Future>> getOutlets({ + int page = 1, + int limit = 10, + }); + + Future> getOutletById(String id); +} diff --git a/lib/infrastructure/outlet/datasources/local_data_provider.dart b/lib/infrastructure/outlet/datasources/local_data_provider.dart new file mode 100644 index 0000000..5f9bd0a --- /dev/null +++ b/lib/infrastructure/outlet/datasources/local_data_provider.dart @@ -0,0 +1,37 @@ +import 'dart:convert'; + +import 'package:injectable/injectable.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +import '../../../common/constant/local_storage_key.dart'; +import '../../../domain/outlet/outlet.dart'; +import '../outlet_dtos.dart'; + +@injectable +class OutletLocalDatasource { + final SharedPreferences _sharedPreferences; + // final String _logName = 'OutletLocalDataProvider'; + + OutletLocalDatasource(this._sharedPreferences); + + Future saveCurrentOutlet(OutletDto outlet) async { + final outletJsonString = jsonEncode(outlet.toJson()); + await _sharedPreferences.setString( + LocalStorageKey.outlet, + outletJsonString, + ); + } + + Future currentOutlet() async { + final outletString = _sharedPreferences.getString(LocalStorageKey.outlet); + if (outletString == null) return Outlet.empty(); + + final Map outletMap = jsonDecode(outletString); + final outletDto = OutletDto.fromJson(outletMap); + return outletDto.toDomain(); + } + + Future deleteCurrentOutlet() async { + await _sharedPreferences.remove(LocalStorageKey.outlet); + } +} diff --git a/lib/infrastructure/outlet/datasources/remote_data_provider.dart b/lib/infrastructure/outlet/datasources/remote_data_provider.dart new file mode 100644 index 0000000..a61e830 --- /dev/null +++ b/lib/infrastructure/outlet/datasources/remote_data_provider.dart @@ -0,0 +1,67 @@ +import 'dart:developer'; + +import 'package:data_channel/data_channel.dart'; +import 'package:injectable/injectable.dart'; + +import '../../../common/api/api_client.dart'; +import '../../../common/api/api_failure.dart'; +import '../../../common/function/app_function.dart'; +import '../../../common/url/api_path.dart'; +import '../../../domain/outlet/outlet.dart'; +import '../outlet_dtos.dart'; + +@injectable +class OutletRemoteDataProvider { + final ApiClient _apiClient; + final _logName = 'OutletRemoteDataProvider'; + + OutletRemoteDataProvider(this._apiClient); + + Future>> fetchOutlets({ + int page = 1, + int limit = 10, + }) async { + try { + final response = await _apiClient.get( + '${ApiPath.outlets}/list', + params: {'page': page, 'limit': limit}, + headers: getAuthorizationHeader(), + ); + + if (response.data['data'] == null) { + return DC.error(OutletFailure.empty()); + } + + final outlets = (response.data['data'] as List) + .map((e) => OutletDto.fromJson(e as Map)) + .toList(); + + return DC.data(outlets); + } on ApiFailure catch (e, s) { + log('fetchOutletError', name: _logName, error: e, stackTrace: s); + return DC.error(OutletFailure.serverError(e)); + } + } + + Future> fetchOutletById(String id) async { + try { + final response = await _apiClient.get( + '${ApiPath.outlets}/detail/$id', + headers: getAuthorizationHeader(), + ); + + if (response.data['data'] == null) { + return DC.error(OutletFailure.empty()); + } + + final outlet = OutletDto.fromJson( + response.data['data'] as Map, + ); + + return DC.data(outlet); + } on ApiFailure catch (e, s) { + log('fetchOutletByIdError', name: _logName, error: e, stackTrace: s); + return DC.error(OutletFailure.serverError(e)); + } + } +} diff --git a/lib/infrastructure/outlet/dtos/outlet_dto.dart b/lib/infrastructure/outlet/dtos/outlet_dto.dart new file mode 100644 index 0000000..2f06097 --- /dev/null +++ b/lib/infrastructure/outlet/dtos/outlet_dto.dart @@ -0,0 +1,38 @@ +part of '../outlet_dtos.dart'; + +@freezed +class OutletDto with _$OutletDto { + const OutletDto._(); + + const factory OutletDto({ + @JsonKey(name: "id") String? id, + @JsonKey(name: "organization_id") String? organizationId, + @JsonKey(name: "name") String? name, + @JsonKey(name: "address") String? address, + @JsonKey(name: "phone_number") String? phoneNumber, + @JsonKey(name: "business_type") String? businessType, + @JsonKey(name: "currency") String? currency, + @JsonKey(name: "tax_rate") double? taxRate, + @JsonKey(name: "is_active") bool? isActive, + @JsonKey(name: "created_at") String? createdAt, + @JsonKey(name: "updated_at") String? updatedAt, + }) = _OutletDto; + + factory OutletDto.fromJson(Map json) => + _$OutletDtoFromJson(json); + + /// Mapping ke domain + Outlet toDomain() => Outlet( + id: id ?? '', + organizationId: organizationId ?? '', + name: name ?? '', + address: address ?? '', + phoneNumber: phoneNumber ?? '', + businessType: businessType ?? '', + currency: currency ?? '', + taxRate: taxRate ?? 0.0, + isActive: isActive ?? false, + createdAt: createdAt ?? '', + updatedAt: updatedAt ?? '', + ); +} diff --git a/lib/infrastructure/outlet/outlet_dtos.dart b/lib/infrastructure/outlet/outlet_dtos.dart new file mode 100644 index 0000000..1fc9e57 --- /dev/null +++ b/lib/infrastructure/outlet/outlet_dtos.dart @@ -0,0 +1,8 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +import '../../domain/outlet/outlet.dart'; + +part 'outlet_dtos.freezed.dart'; +part 'outlet_dtos.g.dart'; + +part 'dtos/outlet_dto.dart'; diff --git a/lib/infrastructure/outlet/outlet_dtos.freezed.dart b/lib/infrastructure/outlet/outlet_dtos.freezed.dart new file mode 100644 index 0000000..f74bd98 --- /dev/null +++ b/lib/infrastructure/outlet/outlet_dtos.freezed.dart @@ -0,0 +1,431 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'outlet_dtos.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models', +); + +OutletDto _$OutletDtoFromJson(Map json) { + return _OutletDto.fromJson(json); +} + +/// @nodoc +mixin _$OutletDto { + @JsonKey(name: "id") + String? get id => throw _privateConstructorUsedError; + @JsonKey(name: "organization_id") + String? get organizationId => throw _privateConstructorUsedError; + @JsonKey(name: "name") + String? get name => throw _privateConstructorUsedError; + @JsonKey(name: "address") + String? get address => throw _privateConstructorUsedError; + @JsonKey(name: "phone_number") + String? get phoneNumber => throw _privateConstructorUsedError; + @JsonKey(name: "business_type") + String? get businessType => throw _privateConstructorUsedError; + @JsonKey(name: "currency") + String? get currency => throw _privateConstructorUsedError; + @JsonKey(name: "tax_rate") + double? get taxRate => throw _privateConstructorUsedError; + @JsonKey(name: "is_active") + bool? get isActive => throw _privateConstructorUsedError; + @JsonKey(name: "created_at") + String? get createdAt => throw _privateConstructorUsedError; + @JsonKey(name: "updated_at") + String? get updatedAt => throw _privateConstructorUsedError; + + /// Serializes this OutletDto to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of OutletDto + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $OutletDtoCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $OutletDtoCopyWith<$Res> { + factory $OutletDtoCopyWith(OutletDto value, $Res Function(OutletDto) then) = + _$OutletDtoCopyWithImpl<$Res, OutletDto>; + @useResult + $Res call({ + @JsonKey(name: "id") String? id, + @JsonKey(name: "organization_id") String? organizationId, + @JsonKey(name: "name") String? name, + @JsonKey(name: "address") String? address, + @JsonKey(name: "phone_number") String? phoneNumber, + @JsonKey(name: "business_type") String? businessType, + @JsonKey(name: "currency") String? currency, + @JsonKey(name: "tax_rate") double? taxRate, + @JsonKey(name: "is_active") bool? isActive, + @JsonKey(name: "created_at") String? createdAt, + @JsonKey(name: "updated_at") String? updatedAt, + }); +} + +/// @nodoc +class _$OutletDtoCopyWithImpl<$Res, $Val extends OutletDto> + implements $OutletDtoCopyWith<$Res> { + _$OutletDtoCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of OutletDto + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = freezed, + Object? organizationId = freezed, + Object? name = freezed, + Object? address = freezed, + Object? phoneNumber = freezed, + Object? businessType = freezed, + Object? currency = freezed, + Object? taxRate = freezed, + Object? isActive = freezed, + Object? createdAt = freezed, + Object? updatedAt = freezed, + }) { + return _then( + _value.copyWith( + id: freezed == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String?, + organizationId: freezed == organizationId + ? _value.organizationId + : organizationId // ignore: cast_nullable_to_non_nullable + as String?, + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + address: freezed == address + ? _value.address + : address // ignore: cast_nullable_to_non_nullable + as String?, + phoneNumber: freezed == phoneNumber + ? _value.phoneNumber + : phoneNumber // ignore: cast_nullable_to_non_nullable + as String?, + businessType: freezed == businessType + ? _value.businessType + : businessType // ignore: cast_nullable_to_non_nullable + as String?, + currency: freezed == currency + ? _value.currency + : currency // ignore: cast_nullable_to_non_nullable + as String?, + taxRate: freezed == taxRate + ? _value.taxRate + : taxRate // ignore: cast_nullable_to_non_nullable + as double?, + isActive: freezed == isActive + ? _value.isActive + : isActive // ignore: cast_nullable_to_non_nullable + as bool?, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as String?, + updatedAt: freezed == updatedAt + ? _value.updatedAt + : updatedAt // ignore: cast_nullable_to_non_nullable + as String?, + ) + as $Val, + ); + } +} + +/// @nodoc +abstract class _$$OutletDtoImplCopyWith<$Res> + implements $OutletDtoCopyWith<$Res> { + factory _$$OutletDtoImplCopyWith( + _$OutletDtoImpl value, + $Res Function(_$OutletDtoImpl) then, + ) = __$$OutletDtoImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({ + @JsonKey(name: "id") String? id, + @JsonKey(name: "organization_id") String? organizationId, + @JsonKey(name: "name") String? name, + @JsonKey(name: "address") String? address, + @JsonKey(name: "phone_number") String? phoneNumber, + @JsonKey(name: "business_type") String? businessType, + @JsonKey(name: "currency") String? currency, + @JsonKey(name: "tax_rate") double? taxRate, + @JsonKey(name: "is_active") bool? isActive, + @JsonKey(name: "created_at") String? createdAt, + @JsonKey(name: "updated_at") String? updatedAt, + }); +} + +/// @nodoc +class __$$OutletDtoImplCopyWithImpl<$Res> + extends _$OutletDtoCopyWithImpl<$Res, _$OutletDtoImpl> + implements _$$OutletDtoImplCopyWith<$Res> { + __$$OutletDtoImplCopyWithImpl( + _$OutletDtoImpl _value, + $Res Function(_$OutletDtoImpl) _then, + ) : super(_value, _then); + + /// Create a copy of OutletDto + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = freezed, + Object? organizationId = freezed, + Object? name = freezed, + Object? address = freezed, + Object? phoneNumber = freezed, + Object? businessType = freezed, + Object? currency = freezed, + Object? taxRate = freezed, + Object? isActive = freezed, + Object? createdAt = freezed, + Object? updatedAt = freezed, + }) { + return _then( + _$OutletDtoImpl( + id: freezed == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String?, + organizationId: freezed == organizationId + ? _value.organizationId + : organizationId // ignore: cast_nullable_to_non_nullable + as String?, + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + address: freezed == address + ? _value.address + : address // ignore: cast_nullable_to_non_nullable + as String?, + phoneNumber: freezed == phoneNumber + ? _value.phoneNumber + : phoneNumber // ignore: cast_nullable_to_non_nullable + as String?, + businessType: freezed == businessType + ? _value.businessType + : businessType // ignore: cast_nullable_to_non_nullable + as String?, + currency: freezed == currency + ? _value.currency + : currency // ignore: cast_nullable_to_non_nullable + as String?, + taxRate: freezed == taxRate + ? _value.taxRate + : taxRate // ignore: cast_nullable_to_non_nullable + as double?, + isActive: freezed == isActive + ? _value.isActive + : isActive // ignore: cast_nullable_to_non_nullable + as bool?, + createdAt: freezed == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as String?, + updatedAt: freezed == updatedAt + ? _value.updatedAt + : updatedAt // ignore: cast_nullable_to_non_nullable + as String?, + ), + ); + } +} + +/// @nodoc +@JsonSerializable() +class _$OutletDtoImpl extends _OutletDto { + const _$OutletDtoImpl({ + @JsonKey(name: "id") this.id, + @JsonKey(name: "organization_id") this.organizationId, + @JsonKey(name: "name") this.name, + @JsonKey(name: "address") this.address, + @JsonKey(name: "phone_number") this.phoneNumber, + @JsonKey(name: "business_type") this.businessType, + @JsonKey(name: "currency") this.currency, + @JsonKey(name: "tax_rate") this.taxRate, + @JsonKey(name: "is_active") this.isActive, + @JsonKey(name: "created_at") this.createdAt, + @JsonKey(name: "updated_at") this.updatedAt, + }) : super._(); + + factory _$OutletDtoImpl.fromJson(Map json) => + _$$OutletDtoImplFromJson(json); + + @override + @JsonKey(name: "id") + final String? id; + @override + @JsonKey(name: "organization_id") + final String? organizationId; + @override + @JsonKey(name: "name") + final String? name; + @override + @JsonKey(name: "address") + final String? address; + @override + @JsonKey(name: "phone_number") + final String? phoneNumber; + @override + @JsonKey(name: "business_type") + final String? businessType; + @override + @JsonKey(name: "currency") + final String? currency; + @override + @JsonKey(name: "tax_rate") + final double? taxRate; + @override + @JsonKey(name: "is_active") + final bool? isActive; + @override + @JsonKey(name: "created_at") + final String? createdAt; + @override + @JsonKey(name: "updated_at") + final String? updatedAt; + + @override + String toString() { + return 'OutletDto(id: $id, organizationId: $organizationId, name: $name, address: $address, phoneNumber: $phoneNumber, businessType: $businessType, currency: $currency, taxRate: $taxRate, isActive: $isActive, createdAt: $createdAt, updatedAt: $updatedAt)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$OutletDtoImpl && + (identical(other.id, id) || other.id == id) && + (identical(other.organizationId, organizationId) || + other.organizationId == organizationId) && + (identical(other.name, name) || other.name == name) && + (identical(other.address, address) || other.address == address) && + (identical(other.phoneNumber, phoneNumber) || + other.phoneNumber == phoneNumber) && + (identical(other.businessType, businessType) || + other.businessType == businessType) && + (identical(other.currency, currency) || + other.currency == currency) && + (identical(other.taxRate, taxRate) || other.taxRate == taxRate) && + (identical(other.isActive, isActive) || + other.isActive == isActive) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && + (identical(other.updatedAt, updatedAt) || + other.updatedAt == updatedAt)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash( + runtimeType, + id, + organizationId, + name, + address, + phoneNumber, + businessType, + currency, + taxRate, + isActive, + createdAt, + updatedAt, + ); + + /// Create a copy of OutletDto + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$OutletDtoImplCopyWith<_$OutletDtoImpl> get copyWith => + __$$OutletDtoImplCopyWithImpl<_$OutletDtoImpl>(this, _$identity); + + @override + Map toJson() { + return _$$OutletDtoImplToJson(this); + } +} + +abstract class _OutletDto extends OutletDto { + const factory _OutletDto({ + @JsonKey(name: "id") final String? id, + @JsonKey(name: "organization_id") final String? organizationId, + @JsonKey(name: "name") final String? name, + @JsonKey(name: "address") final String? address, + @JsonKey(name: "phone_number") final String? phoneNumber, + @JsonKey(name: "business_type") final String? businessType, + @JsonKey(name: "currency") final String? currency, + @JsonKey(name: "tax_rate") final double? taxRate, + @JsonKey(name: "is_active") final bool? isActive, + @JsonKey(name: "created_at") final String? createdAt, + @JsonKey(name: "updated_at") final String? updatedAt, + }) = _$OutletDtoImpl; + const _OutletDto._() : super._(); + + factory _OutletDto.fromJson(Map json) = + _$OutletDtoImpl.fromJson; + + @override + @JsonKey(name: "id") + String? get id; + @override + @JsonKey(name: "organization_id") + String? get organizationId; + @override + @JsonKey(name: "name") + String? get name; + @override + @JsonKey(name: "address") + String? get address; + @override + @JsonKey(name: "phone_number") + String? get phoneNumber; + @override + @JsonKey(name: "business_type") + String? get businessType; + @override + @JsonKey(name: "currency") + String? get currency; + @override + @JsonKey(name: "tax_rate") + double? get taxRate; + @override + @JsonKey(name: "is_active") + bool? get isActive; + @override + @JsonKey(name: "created_at") + String? get createdAt; + @override + @JsonKey(name: "updated_at") + String? get updatedAt; + + /// Create a copy of OutletDto + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$OutletDtoImplCopyWith<_$OutletDtoImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/infrastructure/outlet/outlet_dtos.g.dart b/lib/infrastructure/outlet/outlet_dtos.g.dart new file mode 100644 index 0000000..b0c6810 --- /dev/null +++ b/lib/infrastructure/outlet/outlet_dtos.g.dart @@ -0,0 +1,37 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'outlet_dtos.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$OutletDtoImpl _$$OutletDtoImplFromJson(Map json) => + _$OutletDtoImpl( + id: json['id'] as String?, + organizationId: json['organization_id'] as String?, + name: json['name'] as String?, + address: json['address'] as String?, + phoneNumber: json['phone_number'] as String?, + businessType: json['business_type'] as String?, + currency: json['currency'] as String?, + taxRate: (json['tax_rate'] as num?)?.toDouble(), + isActive: json['is_active'] as bool?, + createdAt: json['created_at'] as String?, + updatedAt: json['updated_at'] as String?, + ); + +Map _$$OutletDtoImplToJson(_$OutletDtoImpl instance) => + { + 'id': instance.id, + 'organization_id': instance.organizationId, + 'name': instance.name, + 'address': instance.address, + 'phone_number': instance.phoneNumber, + 'business_type': instance.businessType, + 'currency': instance.currency, + 'tax_rate': instance.taxRate, + 'is_active': instance.isActive, + 'created_at': instance.createdAt, + 'updated_at': instance.updatedAt, + }; diff --git a/lib/infrastructure/outlet/repositories/outlet_repository.dart b/lib/infrastructure/outlet/repositories/outlet_repository.dart new file mode 100644 index 0000000..dd62f4c --- /dev/null +++ b/lib/infrastructure/outlet/repositories/outlet_repository.dart @@ -0,0 +1,62 @@ +import 'dart:developer'; + +import 'package:dartz/dartz.dart'; +import 'package:injectable/injectable.dart'; + +import '../../../domain/outlet/outlet.dart'; +import '../datasources/local_data_provider.dart'; +import '../datasources/remote_data_provider.dart'; + +@Injectable(as: IOutletRepository) +class OutletRepository implements IOutletRepository { + final OutletRemoteDataProvider _remoteDataProvider; + final OutletLocalDatasource _localDataProvider; + + final _logName = 'OutletRepository'; + OutletRepository(this._remoteDataProvider, this._localDataProvider); + + @override + Future>> getOutlets({ + int page = 1, + int limit = 10, + }) async { + try { + final result = await _remoteDataProvider.fetchOutlets( + page: page, + limit: limit, + ); + + if (result.hasError) { + return left(result.error!); + } + + final outlets = result.data!.map((dto) => dto.toDomain()).toList(); + + return right(outlets); + } catch (e, s) { + log('getOutlets', name: _logName, error: e, stackTrace: s); + return left(const OutletFailure.unexpectedError()); + } + } + + @override + Future> getOutletById(String id) async { + try { + final localOutlet = await _localDataProvider.currentOutlet(); + if (localOutlet.id == id) { + return right(localOutlet); + } + + final result = await _remoteDataProvider.fetchOutletById(id); + if (result.hasError) { + return left(result.error!); + } + + final outlet = result.data!.toDomain(); + return right(outlet); + } catch (e, s) { + log('getOutletById', name: _logName, error: e, stackTrace: s); + return left(const OutletFailure.unexpectedError()); + } + } +} diff --git a/lib/injection.config.dart b/lib/injection.config.dart index 58b6c6b..4c636e8 100644 --- a/lib/injection.config.dart +++ b/lib/injection.config.dart @@ -21,6 +21,7 @@ import 'package:apskel_pos_flutter_v2/common/di/di_shared_preferences.dart' import 'package:apskel_pos_flutter_v2/common/network/network_client.dart' as _i171; import 'package:apskel_pos_flutter_v2/domain/auth/auth.dart' as _i776; +import 'package:apskel_pos_flutter_v2/domain/outlet/outlet.dart' as _i552; import 'package:apskel_pos_flutter_v2/env.dart' as _i923; import 'package:apskel_pos_flutter_v2/infrastructure/auth/datasources/local_data_provider.dart' as _i204; @@ -28,6 +29,12 @@ import 'package:apskel_pos_flutter_v2/infrastructure/auth/datasources/remote_dat as _i370; import 'package:apskel_pos_flutter_v2/infrastructure/auth/repositories/auth_repository.dart' as _i941; +import 'package:apskel_pos_flutter_v2/infrastructure/outlet/datasources/local_data_provider.dart' + as _i693; +import 'package:apskel_pos_flutter_v2/infrastructure/outlet/datasources/remote_data_provider.dart' + as _i132; +import 'package:apskel_pos_flutter_v2/infrastructure/outlet/repositories/outlet_repository.dart' + as _i845; import 'package:apskel_pos_flutter_v2/presentation/router/app_router.dart' as _i800; import 'package:connectivity_plus/connectivity_plus.dart' as _i895; @@ -64,6 +71,9 @@ extension GetItInjectableX on _i174.GetIt { gh.factory<_i204.AuthLocalDataProvider>( () => _i204.AuthLocalDataProvider(gh<_i460.SharedPreferences>()), ); + gh.factory<_i693.OutletLocalDatasource>( + () => _i693.OutletLocalDatasource(gh<_i460.SharedPreferences>()), + ); gh.lazySingleton<_i457.ApiClient>( () => _i457.ApiClient(gh<_i361.Dio>(), gh<_i923.Env>()), ); @@ -71,18 +81,30 @@ extension GetItInjectableX on _i174.GetIt { gh.factory<_i370.AuthRemoteDataProvider>( () => _i370.AuthRemoteDataProvider(gh<_i457.ApiClient>()), ); + gh.factory<_i132.OutletRemoteDataProvider>( + () => _i132.OutletRemoteDataProvider(gh<_i457.ApiClient>()), + ); gh.factory<_i776.IAuthRepository>( () => _i941.AuthRepository( gh<_i370.AuthRemoteDataProvider>(), gh<_i204.AuthLocalDataProvider>(), ), ); - gh.factory<_i343.AuthBloc>( - () => _i343.AuthBloc(gh<_i776.IAuthRepository>()), + gh.factory<_i552.IOutletRepository>( + () => _i845.OutletRepository( + gh<_i132.OutletRemoteDataProvider>(), + gh<_i693.OutletLocalDatasource>(), + ), ); gh.factory<_i46.LoginFormBloc>( () => _i46.LoginFormBloc(gh<_i776.IAuthRepository>()), ); + gh.factory<_i343.AuthBloc>( + () => _i343.AuthBloc( + gh<_i776.IAuthRepository>(), + gh<_i552.IOutletRepository>(), + ), + ); return this; } } diff --git a/lib/presentation/components/loader/loader_with_text.dart b/lib/presentation/components/loader/loader_with_text.dart new file mode 100644 index 0000000..5458b3f --- /dev/null +++ b/lib/presentation/components/loader/loader_with_text.dart @@ -0,0 +1,27 @@ +import 'package:flutter/widgets.dart'; +import 'package:flutter_spinkit/flutter_spinkit.dart'; + +import '../../../common/theme/theme.dart'; +import '../spaces/space.dart'; + +class LoaderWithText extends StatelessWidget { + const LoaderWithText({super.key}); + + @override + Widget build(BuildContext context) { + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SpinKitFadingCircle(color: AppColor.primary), + SpaceWidth(10), + Text( + 'Loading...', + style: AppStyle.md.copyWith( + color: AppColor.primary, + fontWeight: FontWeight.w500, + ), + ), + ], + ); + } +} diff --git a/lib/presentation/pages/main/pages/home/home_page.dart b/lib/presentation/pages/main/pages/home/home_page.dart index edc555d..b1ac15f 100644 --- a/lib/presentation/pages/main/pages/home/home_page.dart +++ b/lib/presentation/pages/main/pages/home/home_page.dart @@ -1,12 +1,33 @@ import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; +import '../../../../../common/theme/theme.dart'; +import 'widgets/home_left_panel.dart'; +import 'widgets/home_right_panel.dart'; + @RoutePage() class HomePage extends StatelessWidget { const HomePage({super.key}); @override Widget build(BuildContext context) { - return const Center(child: Text('Home Page')); + return Hero( + tag: 'confirmation_screen', + child: Scaffold( + backgroundColor: AppColor.white, + body: Column( + children: [ + Expanded( + child: Row( + children: [ + Expanded(flex: 3, child: HomeLeftPanel()), + Expanded(flex: 2, child: HomeRightPanel()), + ], + ), + ), + ], + ), + ), + ); } } diff --git a/lib/presentation/pages/main/pages/home/widgets/home_left_panel.dart b/lib/presentation/pages/main/pages/home/widgets/home_left_panel.dart new file mode 100644 index 0000000..8d6daf1 --- /dev/null +++ b/lib/presentation/pages/main/pages/home/widgets/home_left_panel.dart @@ -0,0 +1,16 @@ +import 'package:flutter/widgets.dart'; + +import 'home_title.dart'; + +class HomeLeftPanel extends StatelessWidget { + const HomeLeftPanel({super.key}); + + @override + Widget build(BuildContext context) { + return Column( + children: [ + HomeTitle(controller: TextEditingController(), onChanged: (value) {}), + ], + ); + } +} diff --git a/lib/presentation/pages/main/pages/home/widgets/home_right_panel.dart b/lib/presentation/pages/main/pages/home/widgets/home_right_panel.dart new file mode 100644 index 0000000..ecb2a47 --- /dev/null +++ b/lib/presentation/pages/main/pages/home/widgets/home_right_panel.dart @@ -0,0 +1,10 @@ +import 'package:flutter/widgets.dart'; + +class HomeRightPanel extends StatelessWidget { + const HomeRightPanel({super.key}); + + @override + Widget build(BuildContext context) { + return const Placeholder(); + } +} diff --git a/lib/presentation/pages/main/pages/home/widgets/home_title.dart b/lib/presentation/pages/main/pages/home/widgets/home_title.dart new file mode 100644 index 0000000..9229cbc --- /dev/null +++ b/lib/presentation/pages/main/pages/home/widgets/home_title.dart @@ -0,0 +1,51 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +import '../../../../../../application/auth/auth_bloc.dart'; +import '../../../../../../common/extension/extension.dart'; +import '../../../../../../common/theme/theme.dart'; +import '../../../../../components/spaces/space.dart'; + +class HomeTitle extends StatelessWidget { + final TextEditingController controller; + final Function(String value)? onChanged; + const HomeTitle({super.key, required this.controller, this.onChanged}); + + @override + Widget build(BuildContext context) { + return Container( + height: context.deviceHeight * 0.1, + padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0), + decoration: BoxDecoration(color: AppColor.white), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + BlocBuilder( + builder: (context, state) { + return Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + state.outlet.name, + style: AppStyle.xl.copyWith( + color: AppColor.primary, + fontWeight: FontWeight.w600, + ), + ), + SpaceWidth(2), + Icon( + Icons.keyboard_arrow_down, + color: AppColor.primary, + size: 18, + ), + ], + ); + }, + ), + ], + ), + ); + } +}