From 9e5a6cc7ae203e12bcbff52f967d43064400d661 Mon Sep 17 00:00:00 2001 From: efrilm Date: Mon, 27 Oct 2025 14:24:29 +0700 Subject: [PATCH] payment method --- .../payment_method_loader_bloc.dart | 83 + .../payment_method_loader_bloc.freezed.dart | 492 ++++++ .../payment_method_loader_event.dart | 8 + .../payment_method_loader_state.dart | 14 + lib/common/url/api_path.dart | 1 + .../entities/payment_method_entity.dart | 43 + .../failures/payment_method_failure.dart | 13 + lib/domain/payment_method/payment_method.dart | 10 + .../payment_method.freezed.dart | 1369 +++++++++++++++++ .../i_payment_method_repository.dart | 8 + .../datasources/remote_data_provider.dart | 45 + .../dtos/payment_method_dto.dart | 54 + .../payment_method/payment_method_dtos.dart | 8 + .../payment_method_dtos.freezed.dart | 627 ++++++++ .../payment_method/payment_method_dtos.g.dart | 53 + .../payment_method_repository.dart | 38 + lib/injection.config.dart | 19 + lib/presentation/app_widget.dart | 2 + .../components/card/payment_card.dart | 37 + .../payment_method_error_state_widget.dart | 72 + .../pages/checkout/checkout_page.dart | 12 +- .../widgets/checkout_right_panel.dart | 52 +- 22 files changed, 3058 insertions(+), 2 deletions(-) create mode 100644 lib/application/payment_method/payment_method_loader/payment_method_loader_bloc.dart create mode 100644 lib/application/payment_method/payment_method_loader/payment_method_loader_bloc.freezed.dart create mode 100644 lib/application/payment_method/payment_method_loader/payment_method_loader_event.dart create mode 100644 lib/application/payment_method/payment_method_loader/payment_method_loader_state.dart create mode 100644 lib/domain/payment_method/entities/payment_method_entity.dart create mode 100644 lib/domain/payment_method/failures/payment_method_failure.dart create mode 100644 lib/domain/payment_method/payment_method.dart create mode 100644 lib/domain/payment_method/payment_method.freezed.dart create mode 100644 lib/domain/payment_method/repositories/i_payment_method_repository.dart create mode 100644 lib/infrastructure/payment_method/datasources/remote_data_provider.dart create mode 100644 lib/infrastructure/payment_method/dtos/payment_method_dto.dart create mode 100644 lib/infrastructure/payment_method/payment_method_dtos.dart create mode 100644 lib/infrastructure/payment_method/payment_method_dtos.freezed.dart create mode 100644 lib/infrastructure/payment_method/payment_method_dtos.g.dart create mode 100644 lib/infrastructure/payment_method/repositories/payment_method_repository.dart create mode 100644 lib/presentation/components/card/payment_card.dart create mode 100644 lib/presentation/components/error/payment_method_error_state_widget.dart diff --git a/lib/application/payment_method/payment_method_loader/payment_method_loader_bloc.dart b/lib/application/payment_method/payment_method_loader/payment_method_loader_bloc.dart new file mode 100644 index 0000000..acc1e02 --- /dev/null +++ b/lib/application/payment_method/payment_method_loader/payment_method_loader_bloc.dart @@ -0,0 +1,83 @@ +import 'package:bloc/bloc.dart'; +import 'package:dartz/dartz.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:injectable/injectable.dart'; + +import '../../../domain/payment_method/payment_method.dart'; + +part 'payment_method_loader_event.dart'; +part 'payment_method_loader_state.dart'; +part 'payment_method_loader_bloc.freezed.dart'; + +@injectable +class PaymentMethodLoaderBloc + extends Bloc { + final IPaymentMethodRepository _repository; + PaymentMethodLoaderBloc(this._repository) + : super(PaymentMethodLoaderState.initial()) { + on(_onPaymentMethodLoaderEvent); + } + + Future _onPaymentMethodLoaderEvent( + PaymentMethodLoaderEvent event, + Emitter emit, + ) { + return event.map( + fetched: (e) async { + var newState = state; + + if (e.isRefresh) { + newState = newState.copyWith(isFetching: true); + emit(newState); + } + + newState = await _mapFetchedToState(newState, isRefresh: e.isRefresh); + emit(newState); + }, + ); + } + + Future _mapFetchedToState( + PaymentMethodLoaderState state, { + bool isRefresh = false, + }) async { + state = state.copyWith(isFetching: false); + + if (state.hasReachedMax && state.paymentMethods.isNotEmpty && !isRefresh) { + return state; + } + + if (isRefresh) { + state = state.copyWith( + page: 1, + failureOption: none(), + hasReachedMax: false, + paymentMethods: [], + ); + } + + final failureOrTable = await _repository.getPaymentMethods( + page: state.page, + ); + + state = failureOrTable.fold( + (f) { + if (state.paymentMethods.isNotEmpty) { + return state.copyWith(hasReachedMax: true); + } + return state.copyWith(failureOption: optionOf(f)); + }, + (paymentMethods) { + return state.copyWith( + paymentMethods: List.from(state.paymentMethods) + ..addAll(paymentMethods.paymentMethods), + failureOption: none(), + page: state.page + 1, + hasReachedMax: paymentMethods.paymentMethods.length < 10, + ); + }, + ); + + return state; + } +} diff --git a/lib/application/payment_method/payment_method_loader/payment_method_loader_bloc.freezed.dart b/lib/application/payment_method/payment_method_loader/payment_method_loader_bloc.freezed.dart new file mode 100644 index 0000000..4643b21 --- /dev/null +++ b/lib/application/payment_method/payment_method_loader/payment_method_loader_bloc.freezed.dart @@ -0,0 +1,492 @@ +// 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 'payment_method_loader_bloc.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 _$PaymentMethodLoaderEvent { + bool get isRefresh => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult when({ + required TResult Function(bool isRefresh) fetched, + }) => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(bool isRefresh)? fetched, + }) => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(bool isRefresh)? fetched, + required TResult orElse(), + }) => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_Fetched value) fetched, + }) => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Fetched value)? fetched, + }) => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Fetched value)? fetched, + required TResult orElse(), + }) => throw _privateConstructorUsedError; + + /// Create a copy of PaymentMethodLoaderEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $PaymentMethodLoaderEventCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PaymentMethodLoaderEventCopyWith<$Res> { + factory $PaymentMethodLoaderEventCopyWith( + PaymentMethodLoaderEvent value, + $Res Function(PaymentMethodLoaderEvent) then, + ) = _$PaymentMethodLoaderEventCopyWithImpl<$Res, PaymentMethodLoaderEvent>; + @useResult + $Res call({bool isRefresh}); +} + +/// @nodoc +class _$PaymentMethodLoaderEventCopyWithImpl< + $Res, + $Val extends PaymentMethodLoaderEvent +> + implements $PaymentMethodLoaderEventCopyWith<$Res> { + _$PaymentMethodLoaderEventCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of PaymentMethodLoaderEvent + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? isRefresh = null}) { + return _then( + _value.copyWith( + isRefresh: null == isRefresh + ? _value.isRefresh + : isRefresh // ignore: cast_nullable_to_non_nullable + as bool, + ) + as $Val, + ); + } +} + +/// @nodoc +abstract class _$$FetchedImplCopyWith<$Res> + implements $PaymentMethodLoaderEventCopyWith<$Res> { + factory _$$FetchedImplCopyWith( + _$FetchedImpl value, + $Res Function(_$FetchedImpl) then, + ) = __$$FetchedImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({bool isRefresh}); +} + +/// @nodoc +class __$$FetchedImplCopyWithImpl<$Res> + extends _$PaymentMethodLoaderEventCopyWithImpl<$Res, _$FetchedImpl> + implements _$$FetchedImplCopyWith<$Res> { + __$$FetchedImplCopyWithImpl( + _$FetchedImpl _value, + $Res Function(_$FetchedImpl) _then, + ) : super(_value, _then); + + /// Create a copy of PaymentMethodLoaderEvent + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? isRefresh = null}) { + return _then( + _$FetchedImpl( + isRefresh: null == isRefresh + ? _value.isRefresh + : isRefresh // ignore: cast_nullable_to_non_nullable + as bool, + ), + ); + } +} + +/// @nodoc + +class _$FetchedImpl implements _Fetched { + const _$FetchedImpl({this.isRefresh = false}); + + @override + @JsonKey() + final bool isRefresh; + + @override + String toString() { + return 'PaymentMethodLoaderEvent.fetched(isRefresh: $isRefresh)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$FetchedImpl && + (identical(other.isRefresh, isRefresh) || + other.isRefresh == isRefresh)); + } + + @override + int get hashCode => Object.hash(runtimeType, isRefresh); + + /// Create a copy of PaymentMethodLoaderEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$FetchedImplCopyWith<_$FetchedImpl> get copyWith => + __$$FetchedImplCopyWithImpl<_$FetchedImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(bool isRefresh) fetched, + }) { + return fetched(isRefresh); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(bool isRefresh)? fetched, + }) { + return fetched?.call(isRefresh); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(bool isRefresh)? fetched, + required TResult orElse(), + }) { + if (fetched != null) { + return fetched(isRefresh); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Fetched value) fetched, + }) { + return fetched(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Fetched value)? fetched, + }) { + return fetched?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Fetched value)? fetched, + required TResult orElse(), + }) { + if (fetched != null) { + return fetched(this); + } + return orElse(); + } +} + +abstract class _Fetched implements PaymentMethodLoaderEvent { + const factory _Fetched({final bool isRefresh}) = _$FetchedImpl; + + @override + bool get isRefresh; + + /// Create a copy of PaymentMethodLoaderEvent + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$FetchedImplCopyWith<_$FetchedImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +mixin _$PaymentMethodLoaderState { + List get paymentMethods => throw _privateConstructorUsedError; + Option get failureOption => + throw _privateConstructorUsedError; + bool get hasReachedMax => throw _privateConstructorUsedError; + bool get isFetching => throw _privateConstructorUsedError; + int get page => throw _privateConstructorUsedError; + + /// Create a copy of PaymentMethodLoaderState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $PaymentMethodLoaderStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PaymentMethodLoaderStateCopyWith<$Res> { + factory $PaymentMethodLoaderStateCopyWith( + PaymentMethodLoaderState value, + $Res Function(PaymentMethodLoaderState) then, + ) = _$PaymentMethodLoaderStateCopyWithImpl<$Res, PaymentMethodLoaderState>; + @useResult + $Res call({ + List paymentMethods, + Option failureOption, + bool hasReachedMax, + bool isFetching, + int page, + }); +} + +/// @nodoc +class _$PaymentMethodLoaderStateCopyWithImpl< + $Res, + $Val extends PaymentMethodLoaderState +> + implements $PaymentMethodLoaderStateCopyWith<$Res> { + _$PaymentMethodLoaderStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of PaymentMethodLoaderState + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? paymentMethods = null, + Object? failureOption = null, + Object? hasReachedMax = null, + Object? isFetching = null, + Object? page = null, + }) { + return _then( + _value.copyWith( + paymentMethods: null == paymentMethods + ? _value.paymentMethods + : paymentMethods // ignore: cast_nullable_to_non_nullable + as List, + failureOption: null == failureOption + ? _value.failureOption + : failureOption // ignore: cast_nullable_to_non_nullable + as Option, + hasReachedMax: null == hasReachedMax + ? _value.hasReachedMax + : hasReachedMax // ignore: cast_nullable_to_non_nullable + as bool, + isFetching: null == isFetching + ? _value.isFetching + : isFetching // ignore: cast_nullable_to_non_nullable + as bool, + page: null == page + ? _value.page + : page // ignore: cast_nullable_to_non_nullable + as int, + ) + as $Val, + ); + } +} + +/// @nodoc +abstract class _$$PaymentMethodLoaderStateImplCopyWith<$Res> + implements $PaymentMethodLoaderStateCopyWith<$Res> { + factory _$$PaymentMethodLoaderStateImplCopyWith( + _$PaymentMethodLoaderStateImpl value, + $Res Function(_$PaymentMethodLoaderStateImpl) then, + ) = __$$PaymentMethodLoaderStateImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({ + List paymentMethods, + Option failureOption, + bool hasReachedMax, + bool isFetching, + int page, + }); +} + +/// @nodoc +class __$$PaymentMethodLoaderStateImplCopyWithImpl<$Res> + extends + _$PaymentMethodLoaderStateCopyWithImpl< + $Res, + _$PaymentMethodLoaderStateImpl + > + implements _$$PaymentMethodLoaderStateImplCopyWith<$Res> { + __$$PaymentMethodLoaderStateImplCopyWithImpl( + _$PaymentMethodLoaderStateImpl _value, + $Res Function(_$PaymentMethodLoaderStateImpl) _then, + ) : super(_value, _then); + + /// Create a copy of PaymentMethodLoaderState + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? paymentMethods = null, + Object? failureOption = null, + Object? hasReachedMax = null, + Object? isFetching = null, + Object? page = null, + }) { + return _then( + _$PaymentMethodLoaderStateImpl( + paymentMethods: null == paymentMethods + ? _value._paymentMethods + : paymentMethods // ignore: cast_nullable_to_non_nullable + as List, + failureOption: null == failureOption + ? _value.failureOption + : failureOption // ignore: cast_nullable_to_non_nullable + as Option, + hasReachedMax: null == hasReachedMax + ? _value.hasReachedMax + : hasReachedMax // ignore: cast_nullable_to_non_nullable + as bool, + isFetching: null == isFetching + ? _value.isFetching + : isFetching // ignore: cast_nullable_to_non_nullable + as bool, + page: null == page + ? _value.page + : page // ignore: cast_nullable_to_non_nullable + as int, + ), + ); + } +} + +/// @nodoc + +class _$PaymentMethodLoaderStateImpl implements _PaymentMethodLoaderState { + _$PaymentMethodLoaderStateImpl({ + required final List paymentMethods, + required this.failureOption, + this.hasReachedMax = false, + this.isFetching = false, + this.page = 1, + }) : _paymentMethods = paymentMethods; + + final List _paymentMethods; + @override + List get paymentMethods { + if (_paymentMethods is EqualUnmodifiableListView) return _paymentMethods; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_paymentMethods); + } + + @override + final Option failureOption; + @override + @JsonKey() + final bool hasReachedMax; + @override + @JsonKey() + final bool isFetching; + @override + @JsonKey() + final int page; + + @override + String toString() { + return 'PaymentMethodLoaderState(paymentMethods: $paymentMethods, failureOption: $failureOption, hasReachedMax: $hasReachedMax, isFetching: $isFetching, page: $page)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$PaymentMethodLoaderStateImpl && + const DeepCollectionEquality().equals( + other._paymentMethods, + _paymentMethods, + ) && + (identical(other.failureOption, failureOption) || + other.failureOption == failureOption) && + (identical(other.hasReachedMax, hasReachedMax) || + other.hasReachedMax == hasReachedMax) && + (identical(other.isFetching, isFetching) || + other.isFetching == isFetching) && + (identical(other.page, page) || other.page == page)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + const DeepCollectionEquality().hash(_paymentMethods), + failureOption, + hasReachedMax, + isFetching, + page, + ); + + /// Create a copy of PaymentMethodLoaderState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$PaymentMethodLoaderStateImplCopyWith<_$PaymentMethodLoaderStateImpl> + get copyWith => + __$$PaymentMethodLoaderStateImplCopyWithImpl< + _$PaymentMethodLoaderStateImpl + >(this, _$identity); +} + +abstract class _PaymentMethodLoaderState implements PaymentMethodLoaderState { + factory _PaymentMethodLoaderState({ + required final List paymentMethods, + required final Option failureOption, + final bool hasReachedMax, + final bool isFetching, + final int page, + }) = _$PaymentMethodLoaderStateImpl; + + @override + List get paymentMethods; + @override + Option get failureOption; + @override + bool get hasReachedMax; + @override + bool get isFetching; + @override + int get page; + + /// Create a copy of PaymentMethodLoaderState + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$PaymentMethodLoaderStateImplCopyWith<_$PaymentMethodLoaderStateImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/application/payment_method/payment_method_loader/payment_method_loader_event.dart b/lib/application/payment_method/payment_method_loader/payment_method_loader_event.dart new file mode 100644 index 0000000..aeedff3 --- /dev/null +++ b/lib/application/payment_method/payment_method_loader/payment_method_loader_event.dart @@ -0,0 +1,8 @@ +part of 'payment_method_loader_bloc.dart'; + +@freezed +class PaymentMethodLoaderEvent with _$PaymentMethodLoaderEvent { + const factory PaymentMethodLoaderEvent.fetched({ + @Default(false) bool isRefresh, + }) = _Fetched; +} diff --git a/lib/application/payment_method/payment_method_loader/payment_method_loader_state.dart b/lib/application/payment_method/payment_method_loader/payment_method_loader_state.dart new file mode 100644 index 0000000..4fe8673 --- /dev/null +++ b/lib/application/payment_method/payment_method_loader/payment_method_loader_state.dart @@ -0,0 +1,14 @@ +part of 'payment_method_loader_bloc.dart'; + +@freezed +class PaymentMethodLoaderState with _$PaymentMethodLoaderState { + factory PaymentMethodLoaderState({ + required List paymentMethods, + required Option failureOption, + @Default(false) bool hasReachedMax, + @Default(false) bool isFetching, + @Default(1) int page, + }) = _PaymentMethodLoaderState; + factory PaymentMethodLoaderState.initial() => + PaymentMethodLoaderState(paymentMethods: [], failureOption: none()); +} diff --git a/lib/common/url/api_path.dart b/lib/common/url/api_path.dart index 6e019c1..3ef1dda 100644 --- a/lib/common/url/api_path.dart +++ b/lib/common/url/api_path.dart @@ -5,4 +5,5 @@ class ApiPath { static const String products = '/api/v1/products'; static const String tables = '/api/v1/tables'; static const String customers = '/api/v1/customers'; + static const String paymentMethods = '/api/v1/payment-methods'; } diff --git a/lib/domain/payment_method/entities/payment_method_entity.dart b/lib/domain/payment_method/entities/payment_method_entity.dart new file mode 100644 index 0000000..073378f --- /dev/null +++ b/lib/domain/payment_method/entities/payment_method_entity.dart @@ -0,0 +1,43 @@ +part of '../payment_method.dart'; + +@freezed +class ListPaymentMethod with _$ListPaymentMethod { + const factory ListPaymentMethod({ + required List paymentMethods, + required int totalCount, + required int page, + required int limit, + required int totalPages, + }) = _ListPaymentMethod; + + factory ListPaymentMethod.empty() => ListPaymentMethod( + paymentMethods: [], + totalCount: 0, + page: 0, + limit: 0, + totalPages: 0, + ); +} + +@freezed +class PaymentMethod with _$PaymentMethod { + const factory PaymentMethod({ + required String id, + required String organizationId, + required String name, + required String type, + required bool isActive, + required DateTime createdAt, + required DateTime updatedAt, + }) = _PaymentMethod; + + factory PaymentMethod.empty() => PaymentMethod( + id: '', + organizationId: '', + name: '', + type: '', + isActive: false, + createdAt: DateTime(1970), + updatedAt: DateTime(1970), + ); +} diff --git a/lib/domain/payment_method/failures/payment_method_failure.dart b/lib/domain/payment_method/failures/payment_method_failure.dart new file mode 100644 index 0000000..d462b6b --- /dev/null +++ b/lib/domain/payment_method/failures/payment_method_failure.dart @@ -0,0 +1,13 @@ +part of '../payment_method.dart'; + +@freezed +sealed class PaymentMethodFailure with _$PaymentMethodFailure { + const factory PaymentMethodFailure.serverError(ApiFailure failure) = + _ServerError; + const factory PaymentMethodFailure.unexpectedError() = _UnexpectedError; + const factory PaymentMethodFailure.empty() = _Empty; + const factory PaymentMethodFailure.localStorageError(String erroMessage) = + _LocalStorageError; + const factory PaymentMethodFailure.dynamicErrorMessage(String erroMessage) = + _DynamicErrorMessage; +} diff --git a/lib/domain/payment_method/payment_method.dart b/lib/domain/payment_method/payment_method.dart new file mode 100644 index 0000000..442bbe5 --- /dev/null +++ b/lib/domain/payment_method/payment_method.dart @@ -0,0 +1,10 @@ +import 'package:dartz/dartz.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +import '../../common/api/api_failure.dart'; + +part 'payment_method.freezed.dart'; + +part 'entities/payment_method_entity.dart'; +part 'failures/payment_method_failure.dart'; +part 'repositories/i_payment_method_repository.dart'; diff --git a/lib/domain/payment_method/payment_method.freezed.dart b/lib/domain/payment_method/payment_method.freezed.dart new file mode 100644 index 0000000..847d9f7 --- /dev/null +++ b/lib/domain/payment_method/payment_method.freezed.dart @@ -0,0 +1,1369 @@ +// 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 'payment_method.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 _$ListPaymentMethod { + List get paymentMethods => throw _privateConstructorUsedError; + int get totalCount => throw _privateConstructorUsedError; + int get page => throw _privateConstructorUsedError; + int get limit => throw _privateConstructorUsedError; + int get totalPages => throw _privateConstructorUsedError; + + /// Create a copy of ListPaymentMethod + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $ListPaymentMethodCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ListPaymentMethodCopyWith<$Res> { + factory $ListPaymentMethodCopyWith( + ListPaymentMethod value, + $Res Function(ListPaymentMethod) then, + ) = _$ListPaymentMethodCopyWithImpl<$Res, ListPaymentMethod>; + @useResult + $Res call({ + List paymentMethods, + int totalCount, + int page, + int limit, + int totalPages, + }); +} + +/// @nodoc +class _$ListPaymentMethodCopyWithImpl<$Res, $Val extends ListPaymentMethod> + implements $ListPaymentMethodCopyWith<$Res> { + _$ListPaymentMethodCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of ListPaymentMethod + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? paymentMethods = null, + Object? totalCount = null, + Object? page = null, + Object? limit = null, + Object? totalPages = null, + }) { + return _then( + _value.copyWith( + paymentMethods: null == paymentMethods + ? _value.paymentMethods + : paymentMethods // ignore: cast_nullable_to_non_nullable + as List, + totalCount: null == totalCount + ? _value.totalCount + : totalCount // ignore: cast_nullable_to_non_nullable + as int, + page: null == page + ? _value.page + : page // ignore: cast_nullable_to_non_nullable + as int, + limit: null == limit + ? _value.limit + : limit // ignore: cast_nullable_to_non_nullable + as int, + totalPages: null == totalPages + ? _value.totalPages + : totalPages // ignore: cast_nullable_to_non_nullable + as int, + ) + as $Val, + ); + } +} + +/// @nodoc +abstract class _$$ListPaymentMethodImplCopyWith<$Res> + implements $ListPaymentMethodCopyWith<$Res> { + factory _$$ListPaymentMethodImplCopyWith( + _$ListPaymentMethodImpl value, + $Res Function(_$ListPaymentMethodImpl) then, + ) = __$$ListPaymentMethodImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({ + List paymentMethods, + int totalCount, + int page, + int limit, + int totalPages, + }); +} + +/// @nodoc +class __$$ListPaymentMethodImplCopyWithImpl<$Res> + extends _$ListPaymentMethodCopyWithImpl<$Res, _$ListPaymentMethodImpl> + implements _$$ListPaymentMethodImplCopyWith<$Res> { + __$$ListPaymentMethodImplCopyWithImpl( + _$ListPaymentMethodImpl _value, + $Res Function(_$ListPaymentMethodImpl) _then, + ) : super(_value, _then); + + /// Create a copy of ListPaymentMethod + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? paymentMethods = null, + Object? totalCount = null, + Object? page = null, + Object? limit = null, + Object? totalPages = null, + }) { + return _then( + _$ListPaymentMethodImpl( + paymentMethods: null == paymentMethods + ? _value._paymentMethods + : paymentMethods // ignore: cast_nullable_to_non_nullable + as List, + totalCount: null == totalCount + ? _value.totalCount + : totalCount // ignore: cast_nullable_to_non_nullable + as int, + page: null == page + ? _value.page + : page // ignore: cast_nullable_to_non_nullable + as int, + limit: null == limit + ? _value.limit + : limit // ignore: cast_nullable_to_non_nullable + as int, + totalPages: null == totalPages + ? _value.totalPages + : totalPages // ignore: cast_nullable_to_non_nullable + as int, + ), + ); + } +} + +/// @nodoc + +class _$ListPaymentMethodImpl implements _ListPaymentMethod { + const _$ListPaymentMethodImpl({ + required final List paymentMethods, + required this.totalCount, + required this.page, + required this.limit, + required this.totalPages, + }) : _paymentMethods = paymentMethods; + + final List _paymentMethods; + @override + List get paymentMethods { + if (_paymentMethods is EqualUnmodifiableListView) return _paymentMethods; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_paymentMethods); + } + + @override + final int totalCount; + @override + final int page; + @override + final int limit; + @override + final int totalPages; + + @override + String toString() { + return 'ListPaymentMethod(paymentMethods: $paymentMethods, totalCount: $totalCount, page: $page, limit: $limit, totalPages: $totalPages)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ListPaymentMethodImpl && + const DeepCollectionEquality().equals( + other._paymentMethods, + _paymentMethods, + ) && + (identical(other.totalCount, totalCount) || + other.totalCount == totalCount) && + (identical(other.page, page) || other.page == page) && + (identical(other.limit, limit) || other.limit == limit) && + (identical(other.totalPages, totalPages) || + other.totalPages == totalPages)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + const DeepCollectionEquality().hash(_paymentMethods), + totalCount, + page, + limit, + totalPages, + ); + + /// Create a copy of ListPaymentMethod + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ListPaymentMethodImplCopyWith<_$ListPaymentMethodImpl> get copyWith => + __$$ListPaymentMethodImplCopyWithImpl<_$ListPaymentMethodImpl>( + this, + _$identity, + ); +} + +abstract class _ListPaymentMethod implements ListPaymentMethod { + const factory _ListPaymentMethod({ + required final List paymentMethods, + required final int totalCount, + required final int page, + required final int limit, + required final int totalPages, + }) = _$ListPaymentMethodImpl; + + @override + List get paymentMethods; + @override + int get totalCount; + @override + int get page; + @override + int get limit; + @override + int get totalPages; + + /// Create a copy of ListPaymentMethod + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ListPaymentMethodImplCopyWith<_$ListPaymentMethodImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +mixin _$PaymentMethod { + String get id => throw _privateConstructorUsedError; + String get organizationId => throw _privateConstructorUsedError; + String get name => throw _privateConstructorUsedError; + String get type => throw _privateConstructorUsedError; + bool get isActive => throw _privateConstructorUsedError; + DateTime get createdAt => throw _privateConstructorUsedError; + DateTime get updatedAt => throw _privateConstructorUsedError; + + /// Create a copy of PaymentMethod + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $PaymentMethodCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PaymentMethodCopyWith<$Res> { + factory $PaymentMethodCopyWith( + PaymentMethod value, + $Res Function(PaymentMethod) then, + ) = _$PaymentMethodCopyWithImpl<$Res, PaymentMethod>; + @useResult + $Res call({ + String id, + String organizationId, + String name, + String type, + bool isActive, + DateTime createdAt, + DateTime updatedAt, + }); +} + +/// @nodoc +class _$PaymentMethodCopyWithImpl<$Res, $Val extends PaymentMethod> + implements $PaymentMethodCopyWith<$Res> { + _$PaymentMethodCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of PaymentMethod + /// 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? type = 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, + type: null == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String, + 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 DateTime, + updatedAt: null == updatedAt + ? _value.updatedAt + : updatedAt // ignore: cast_nullable_to_non_nullable + as DateTime, + ) + as $Val, + ); + } +} + +/// @nodoc +abstract class _$$PaymentMethodImplCopyWith<$Res> + implements $PaymentMethodCopyWith<$Res> { + factory _$$PaymentMethodImplCopyWith( + _$PaymentMethodImpl value, + $Res Function(_$PaymentMethodImpl) then, + ) = __$$PaymentMethodImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({ + String id, + String organizationId, + String name, + String type, + bool isActive, + DateTime createdAt, + DateTime updatedAt, + }); +} + +/// @nodoc +class __$$PaymentMethodImplCopyWithImpl<$Res> + extends _$PaymentMethodCopyWithImpl<$Res, _$PaymentMethodImpl> + implements _$$PaymentMethodImplCopyWith<$Res> { + __$$PaymentMethodImplCopyWithImpl( + _$PaymentMethodImpl _value, + $Res Function(_$PaymentMethodImpl) _then, + ) : super(_value, _then); + + /// Create a copy of PaymentMethod + /// 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? type = null, + Object? isActive = null, + Object? createdAt = null, + Object? updatedAt = null, + }) { + return _then( + _$PaymentMethodImpl( + 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, + type: null == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String, + 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 DateTime, + updatedAt: null == updatedAt + ? _value.updatedAt + : updatedAt // ignore: cast_nullable_to_non_nullable + as DateTime, + ), + ); + } +} + +/// @nodoc + +class _$PaymentMethodImpl implements _PaymentMethod { + const _$PaymentMethodImpl({ + required this.id, + required this.organizationId, + required this.name, + required this.type, + required this.isActive, + required this.createdAt, + required this.updatedAt, + }); + + @override + final String id; + @override + final String organizationId; + @override + final String name; + @override + final String type; + @override + final bool isActive; + @override + final DateTime createdAt; + @override + final DateTime updatedAt; + + @override + String toString() { + return 'PaymentMethod(id: $id, organizationId: $organizationId, name: $name, type: $type, isActive: $isActive, createdAt: $createdAt, updatedAt: $updatedAt)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$PaymentMethodImpl && + (identical(other.id, id) || other.id == id) && + (identical(other.organizationId, organizationId) || + other.organizationId == organizationId) && + (identical(other.name, name) || other.name == name) && + (identical(other.type, type) || other.type == type) && + (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, + type, + isActive, + createdAt, + updatedAt, + ); + + /// Create a copy of PaymentMethod + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$PaymentMethodImplCopyWith<_$PaymentMethodImpl> get copyWith => + __$$PaymentMethodImplCopyWithImpl<_$PaymentMethodImpl>(this, _$identity); +} + +abstract class _PaymentMethod implements PaymentMethod { + const factory _PaymentMethod({ + required final String id, + required final String organizationId, + required final String name, + required final String type, + required final bool isActive, + required final DateTime createdAt, + required final DateTime updatedAt, + }) = _$PaymentMethodImpl; + + @override + String get id; + @override + String get organizationId; + @override + String get name; + @override + String get type; + @override + bool get isActive; + @override + DateTime get createdAt; + @override + DateTime get updatedAt; + + /// Create a copy of PaymentMethod + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$PaymentMethodImplCopyWith<_$PaymentMethodImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +mixin _$PaymentMethodFailure { + @optionalTypeArgs + TResult when({ + required TResult Function(ApiFailure failure) serverError, + required TResult Function() unexpectedError, + required TResult Function() empty, + required TResult Function(String erroMessage) localStorageError, + 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)? localStorageError, + 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)? localStorageError, + 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(_LocalStorageError value) localStorageError, + 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(_LocalStorageError value)? localStorageError, + 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(_LocalStorageError value)? localStorageError, + TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage, + required TResult orElse(), + }) => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PaymentMethodFailureCopyWith<$Res> { + factory $PaymentMethodFailureCopyWith( + PaymentMethodFailure value, + $Res Function(PaymentMethodFailure) then, + ) = _$PaymentMethodFailureCopyWithImpl<$Res, PaymentMethodFailure>; +} + +/// @nodoc +class _$PaymentMethodFailureCopyWithImpl< + $Res, + $Val extends PaymentMethodFailure +> + implements $PaymentMethodFailureCopyWith<$Res> { + _$PaymentMethodFailureCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of PaymentMethodFailure + /// 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 _$PaymentMethodFailureCopyWithImpl<$Res, _$ServerErrorImpl> + implements _$$ServerErrorImplCopyWith<$Res> { + __$$ServerErrorImplCopyWithImpl( + _$ServerErrorImpl _value, + $Res Function(_$ServerErrorImpl) _then, + ) : super(_value, _then); + + /// Create a copy of PaymentMethodFailure + /// 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 PaymentMethodFailure + /// 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 'PaymentMethodFailure.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 PaymentMethodFailure + /// 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) localStorageError, + 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)? localStorageError, + 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)? localStorageError, + 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(_LocalStorageError value) localStorageError, + 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(_LocalStorageError value)? localStorageError, + 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(_LocalStorageError value)? localStorageError, + TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage, + required TResult orElse(), + }) { + if (serverError != null) { + return serverError(this); + } + return orElse(); + } +} + +abstract class _ServerError implements PaymentMethodFailure { + const factory _ServerError(final ApiFailure failure) = _$ServerErrorImpl; + + ApiFailure get failure; + + /// Create a copy of PaymentMethodFailure + /// 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 _$PaymentMethodFailureCopyWithImpl<$Res, _$UnexpectedErrorImpl> + implements _$$UnexpectedErrorImplCopyWith<$Res> { + __$$UnexpectedErrorImplCopyWithImpl( + _$UnexpectedErrorImpl _value, + $Res Function(_$UnexpectedErrorImpl) _then, + ) : super(_value, _then); + + /// Create a copy of PaymentMethodFailure + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc + +class _$UnexpectedErrorImpl implements _UnexpectedError { + const _$UnexpectedErrorImpl(); + + @override + String toString() { + return 'PaymentMethodFailure.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) localStorageError, + 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)? localStorageError, + 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)? localStorageError, + 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(_LocalStorageError value) localStorageError, + 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(_LocalStorageError value)? localStorageError, + 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(_LocalStorageError value)? localStorageError, + TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage, + required TResult orElse(), + }) { + if (unexpectedError != null) { + return unexpectedError(this); + } + return orElse(); + } +} + +abstract class _UnexpectedError implements PaymentMethodFailure { + const factory _UnexpectedError() = _$UnexpectedErrorImpl; +} + +/// @nodoc +abstract class _$$EmptyImplCopyWith<$Res> { + factory _$$EmptyImplCopyWith( + _$EmptyImpl value, + $Res Function(_$EmptyImpl) then, + ) = __$$EmptyImplCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$EmptyImplCopyWithImpl<$Res> + extends _$PaymentMethodFailureCopyWithImpl<$Res, _$EmptyImpl> + implements _$$EmptyImplCopyWith<$Res> { + __$$EmptyImplCopyWithImpl( + _$EmptyImpl _value, + $Res Function(_$EmptyImpl) _then, + ) : super(_value, _then); + + /// Create a copy of PaymentMethodFailure + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc + +class _$EmptyImpl implements _Empty { + const _$EmptyImpl(); + + @override + String toString() { + return 'PaymentMethodFailure.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) localStorageError, + 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)? localStorageError, + 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)? localStorageError, + 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(_LocalStorageError value) localStorageError, + 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(_LocalStorageError value)? localStorageError, + 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(_LocalStorageError value)? localStorageError, + TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage, + required TResult orElse(), + }) { + if (empty != null) { + return empty(this); + } + return orElse(); + } +} + +abstract class _Empty implements PaymentMethodFailure { + const factory _Empty() = _$EmptyImpl; +} + +/// @nodoc +abstract class _$$LocalStorageErrorImplCopyWith<$Res> { + factory _$$LocalStorageErrorImplCopyWith( + _$LocalStorageErrorImpl value, + $Res Function(_$LocalStorageErrorImpl) then, + ) = __$$LocalStorageErrorImplCopyWithImpl<$Res>; + @useResult + $Res call({String erroMessage}); +} + +/// @nodoc +class __$$LocalStorageErrorImplCopyWithImpl<$Res> + extends _$PaymentMethodFailureCopyWithImpl<$Res, _$LocalStorageErrorImpl> + implements _$$LocalStorageErrorImplCopyWith<$Res> { + __$$LocalStorageErrorImplCopyWithImpl( + _$LocalStorageErrorImpl _value, + $Res Function(_$LocalStorageErrorImpl) _then, + ) : super(_value, _then); + + /// Create a copy of PaymentMethodFailure + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? erroMessage = null}) { + return _then( + _$LocalStorageErrorImpl( + null == erroMessage + ? _value.erroMessage + : erroMessage // ignore: cast_nullable_to_non_nullable + as String, + ), + ); + } +} + +/// @nodoc + +class _$LocalStorageErrorImpl implements _LocalStorageError { + const _$LocalStorageErrorImpl(this.erroMessage); + + @override + final String erroMessage; + + @override + String toString() { + return 'PaymentMethodFailure.localStorageError(erroMessage: $erroMessage)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$LocalStorageErrorImpl && + (identical(other.erroMessage, erroMessage) || + other.erroMessage == erroMessage)); + } + + @override + int get hashCode => Object.hash(runtimeType, erroMessage); + + /// Create a copy of PaymentMethodFailure + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$LocalStorageErrorImplCopyWith<_$LocalStorageErrorImpl> get copyWith => + __$$LocalStorageErrorImplCopyWithImpl<_$LocalStorageErrorImpl>( + 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) localStorageError, + required TResult Function(String erroMessage) dynamicErrorMessage, + }) { + return localStorageError(erroMessage); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(ApiFailure failure)? serverError, + TResult? Function()? unexpectedError, + TResult? Function()? empty, + TResult? Function(String erroMessage)? localStorageError, + TResult? Function(String erroMessage)? dynamicErrorMessage, + }) { + return localStorageError?.call(erroMessage); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(ApiFailure failure)? serverError, + TResult Function()? unexpectedError, + TResult Function()? empty, + TResult Function(String erroMessage)? localStorageError, + TResult Function(String erroMessage)? dynamicErrorMessage, + required TResult orElse(), + }) { + if (localStorageError != null) { + return localStorageError(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(_LocalStorageError value) localStorageError, + required TResult Function(_DynamicErrorMessage value) dynamicErrorMessage, + }) { + return localStorageError(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_ServerError value)? serverError, + TResult? Function(_UnexpectedError value)? unexpectedError, + TResult? Function(_Empty value)? empty, + TResult? Function(_LocalStorageError value)? localStorageError, + TResult? Function(_DynamicErrorMessage value)? dynamicErrorMessage, + }) { + return localStorageError?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_ServerError value)? serverError, + TResult Function(_UnexpectedError value)? unexpectedError, + TResult Function(_Empty value)? empty, + TResult Function(_LocalStorageError value)? localStorageError, + TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage, + required TResult orElse(), + }) { + if (localStorageError != null) { + return localStorageError(this); + } + return orElse(); + } +} + +abstract class _LocalStorageError implements PaymentMethodFailure { + const factory _LocalStorageError(final String erroMessage) = + _$LocalStorageErrorImpl; + + String get erroMessage; + + /// Create a copy of PaymentMethodFailure + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$LocalStorageErrorImplCopyWith<_$LocalStorageErrorImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @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 _$PaymentMethodFailureCopyWithImpl<$Res, _$DynamicErrorMessageImpl> + implements _$$DynamicErrorMessageImplCopyWith<$Res> { + __$$DynamicErrorMessageImplCopyWithImpl( + _$DynamicErrorMessageImpl _value, + $Res Function(_$DynamicErrorMessageImpl) _then, + ) : super(_value, _then); + + /// Create a copy of PaymentMethodFailure + /// 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 'PaymentMethodFailure.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 PaymentMethodFailure + /// 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) localStorageError, + 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)? localStorageError, + 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)? localStorageError, + 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(_LocalStorageError value) localStorageError, + 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(_LocalStorageError value)? localStorageError, + 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(_LocalStorageError value)? localStorageError, + TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage, + required TResult orElse(), + }) { + if (dynamicErrorMessage != null) { + return dynamicErrorMessage(this); + } + return orElse(); + } +} + +abstract class _DynamicErrorMessage implements PaymentMethodFailure { + const factory _DynamicErrorMessage(final String erroMessage) = + _$DynamicErrorMessageImpl; + + String get erroMessage; + + /// Create a copy of PaymentMethodFailure + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$DynamicErrorMessageImplCopyWith<_$DynamicErrorMessageImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/domain/payment_method/repositories/i_payment_method_repository.dart b/lib/domain/payment_method/repositories/i_payment_method_repository.dart new file mode 100644 index 0000000..8f368c2 --- /dev/null +++ b/lib/domain/payment_method/repositories/i_payment_method_repository.dart @@ -0,0 +1,8 @@ +part of '../payment_method.dart'; + +abstract class IPaymentMethodRepository { + Future> getPaymentMethods({ + int page = 1, + int limit = 30, + }); +} diff --git a/lib/infrastructure/payment_method/datasources/remote_data_provider.dart b/lib/infrastructure/payment_method/datasources/remote_data_provider.dart new file mode 100644 index 0000000..7a917ac --- /dev/null +++ b/lib/infrastructure/payment_method/datasources/remote_data_provider.dart @@ -0,0 +1,45 @@ +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/payment_method/payment_method.dart'; +import '../payment_method_dtos.dart'; + +@injectable +class PaymentMethodRemoteDataProvider { + final ApiClient _apiClient; + final _logName = 'PaymentMethodRemoteDataProvider'; + + PaymentMethodRemoteDataProvider(this._apiClient); + + Future> fetchPaymentMethods({ + int page = 1, + int limit = 30, + }) async { + try { + final response = await _apiClient.get( + ApiPath.paymentMethods, + params: {'page': page, 'limit': limit}, + headers: getAuthorizationHeader(), + ); + + if (response.data['success'] == false) { + return DC.error(PaymentMethodFailure.unexpectedError()); + } + + final paymentMethods = ListPaymentMethodDto.fromJson( + response.data['data'] as Map, + ); + + return DC.data(paymentMethods); + } on ApiFailure catch (e, s) { + log('fetchPaymentMethodsError', name: _logName, error: e, stackTrace: s); + return DC.error(PaymentMethodFailure.serverError(e)); + } + } +} diff --git a/lib/infrastructure/payment_method/dtos/payment_method_dto.dart b/lib/infrastructure/payment_method/dtos/payment_method_dto.dart new file mode 100644 index 0000000..3abd157 --- /dev/null +++ b/lib/infrastructure/payment_method/dtos/payment_method_dto.dart @@ -0,0 +1,54 @@ +part of '../payment_method_dtos.dart'; + +@freezed +class ListPaymentMethodDto with _$ListPaymentMethodDto { + const ListPaymentMethodDto._(); + + const factory ListPaymentMethodDto({ + @JsonKey(name: "payment_methods") List? paymentMethods, + @JsonKey(name: "total_count") int? totalCount, + @JsonKey(name: "page") int? page, + @JsonKey(name: "limit") int? limit, + @JsonKey(name: "total_pages") int? totalPages, + }) = _ListPaymentMethodDto; + + factory ListPaymentMethodDto.fromJson(Map json) => + _$ListPaymentMethodDtoFromJson(json); + + ListPaymentMethod toDomain() => ListPaymentMethod( + paymentMethods: paymentMethods?.map((e) => e.toDomain()).toList() ?? [], + totalCount: totalCount ?? 0, + page: page ?? 0, + limit: limit ?? 0, + totalPages: totalPages ?? 0, + ); +} + +@freezed +class PaymentMethodDto with _$PaymentMethodDto { + const PaymentMethodDto._(); + + const factory PaymentMethodDto({ + @JsonKey(name: "id") String? id, + @JsonKey(name: "organization_id") String? organizationId, + @JsonKey(name: "name") String? name, + @JsonKey(name: "type") String? type, + @JsonKey(name: "is_active") bool? isActive, + @JsonKey(name: "created_at") String? createdAt, + @JsonKey(name: "updated_at") String? updatedAt, + }) = _PaymentMethodDto; + + factory PaymentMethodDto.fromJson(Map json) => + _$PaymentMethodDtoFromJson(json); + + /// Mapping ke domain + PaymentMethod toDomain() => PaymentMethod( + id: id ?? '', + organizationId: organizationId ?? '', + name: name ?? '', + type: type ?? '', + isActive: isActive ?? false, + createdAt: createdAt != null ? DateTime.parse(createdAt!) : DateTime(1970), + updatedAt: updatedAt != null ? DateTime.parse(updatedAt!) : DateTime(1970), + ); +} diff --git a/lib/infrastructure/payment_method/payment_method_dtos.dart b/lib/infrastructure/payment_method/payment_method_dtos.dart new file mode 100644 index 0000000..842f9d1 --- /dev/null +++ b/lib/infrastructure/payment_method/payment_method_dtos.dart @@ -0,0 +1,8 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +import '../../domain/payment_method/payment_method.dart'; + +part 'payment_method_dtos.freezed.dart'; +part 'payment_method_dtos.g.dart'; + +part 'dtos/payment_method_dto.dart'; diff --git a/lib/infrastructure/payment_method/payment_method_dtos.freezed.dart b/lib/infrastructure/payment_method/payment_method_dtos.freezed.dart new file mode 100644 index 0000000..961adeb --- /dev/null +++ b/lib/infrastructure/payment_method/payment_method_dtos.freezed.dart @@ -0,0 +1,627 @@ +// 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 'payment_method_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', +); + +ListPaymentMethodDto _$ListPaymentMethodDtoFromJson(Map json) { + return _ListPaymentMethodDto.fromJson(json); +} + +/// @nodoc +mixin _$ListPaymentMethodDto { + @JsonKey(name: "payment_methods") + List? get paymentMethods => + throw _privateConstructorUsedError; + @JsonKey(name: "total_count") + int? get totalCount => throw _privateConstructorUsedError; + @JsonKey(name: "page") + int? get page => throw _privateConstructorUsedError; + @JsonKey(name: "limit") + int? get limit => throw _privateConstructorUsedError; + @JsonKey(name: "total_pages") + int? get totalPages => throw _privateConstructorUsedError; + + /// Serializes this ListPaymentMethodDto to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of ListPaymentMethodDto + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $ListPaymentMethodDtoCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ListPaymentMethodDtoCopyWith<$Res> { + factory $ListPaymentMethodDtoCopyWith( + ListPaymentMethodDto value, + $Res Function(ListPaymentMethodDto) then, + ) = _$ListPaymentMethodDtoCopyWithImpl<$Res, ListPaymentMethodDto>; + @useResult + $Res call({ + @JsonKey(name: "payment_methods") List? paymentMethods, + @JsonKey(name: "total_count") int? totalCount, + @JsonKey(name: "page") int? page, + @JsonKey(name: "limit") int? limit, + @JsonKey(name: "total_pages") int? totalPages, + }); +} + +/// @nodoc +class _$ListPaymentMethodDtoCopyWithImpl< + $Res, + $Val extends ListPaymentMethodDto +> + implements $ListPaymentMethodDtoCopyWith<$Res> { + _$ListPaymentMethodDtoCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of ListPaymentMethodDto + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? paymentMethods = freezed, + Object? totalCount = freezed, + Object? page = freezed, + Object? limit = freezed, + Object? totalPages = freezed, + }) { + return _then( + _value.copyWith( + paymentMethods: freezed == paymentMethods + ? _value.paymentMethods + : paymentMethods // ignore: cast_nullable_to_non_nullable + as List?, + totalCount: freezed == totalCount + ? _value.totalCount + : totalCount // ignore: cast_nullable_to_non_nullable + as int?, + page: freezed == page + ? _value.page + : page // ignore: cast_nullable_to_non_nullable + as int?, + limit: freezed == limit + ? _value.limit + : limit // ignore: cast_nullable_to_non_nullable + as int?, + totalPages: freezed == totalPages + ? _value.totalPages + : totalPages // ignore: cast_nullable_to_non_nullable + as int?, + ) + as $Val, + ); + } +} + +/// @nodoc +abstract class _$$ListPaymentMethodDtoImplCopyWith<$Res> + implements $ListPaymentMethodDtoCopyWith<$Res> { + factory _$$ListPaymentMethodDtoImplCopyWith( + _$ListPaymentMethodDtoImpl value, + $Res Function(_$ListPaymentMethodDtoImpl) then, + ) = __$$ListPaymentMethodDtoImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({ + @JsonKey(name: "payment_methods") List? paymentMethods, + @JsonKey(name: "total_count") int? totalCount, + @JsonKey(name: "page") int? page, + @JsonKey(name: "limit") int? limit, + @JsonKey(name: "total_pages") int? totalPages, + }); +} + +/// @nodoc +class __$$ListPaymentMethodDtoImplCopyWithImpl<$Res> + extends _$ListPaymentMethodDtoCopyWithImpl<$Res, _$ListPaymentMethodDtoImpl> + implements _$$ListPaymentMethodDtoImplCopyWith<$Res> { + __$$ListPaymentMethodDtoImplCopyWithImpl( + _$ListPaymentMethodDtoImpl _value, + $Res Function(_$ListPaymentMethodDtoImpl) _then, + ) : super(_value, _then); + + /// Create a copy of ListPaymentMethodDto + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? paymentMethods = freezed, + Object? totalCount = freezed, + Object? page = freezed, + Object? limit = freezed, + Object? totalPages = freezed, + }) { + return _then( + _$ListPaymentMethodDtoImpl( + paymentMethods: freezed == paymentMethods + ? _value._paymentMethods + : paymentMethods // ignore: cast_nullable_to_non_nullable + as List?, + totalCount: freezed == totalCount + ? _value.totalCount + : totalCount // ignore: cast_nullable_to_non_nullable + as int?, + page: freezed == page + ? _value.page + : page // ignore: cast_nullable_to_non_nullable + as int?, + limit: freezed == limit + ? _value.limit + : limit // ignore: cast_nullable_to_non_nullable + as int?, + totalPages: freezed == totalPages + ? _value.totalPages + : totalPages // ignore: cast_nullable_to_non_nullable + as int?, + ), + ); + } +} + +/// @nodoc +@JsonSerializable() +class _$ListPaymentMethodDtoImpl extends _ListPaymentMethodDto { + const _$ListPaymentMethodDtoImpl({ + @JsonKey(name: "payment_methods") + final List? paymentMethods, + @JsonKey(name: "total_count") this.totalCount, + @JsonKey(name: "page") this.page, + @JsonKey(name: "limit") this.limit, + @JsonKey(name: "total_pages") this.totalPages, + }) : _paymentMethods = paymentMethods, + super._(); + + factory _$ListPaymentMethodDtoImpl.fromJson(Map json) => + _$$ListPaymentMethodDtoImplFromJson(json); + + final List? _paymentMethods; + @override + @JsonKey(name: "payment_methods") + List? get paymentMethods { + final value = _paymentMethods; + if (value == null) return null; + if (_paymentMethods is EqualUnmodifiableListView) return _paymentMethods; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + + @override + @JsonKey(name: "total_count") + final int? totalCount; + @override + @JsonKey(name: "page") + final int? page; + @override + @JsonKey(name: "limit") + final int? limit; + @override + @JsonKey(name: "total_pages") + final int? totalPages; + + @override + String toString() { + return 'ListPaymentMethodDto(paymentMethods: $paymentMethods, totalCount: $totalCount, page: $page, limit: $limit, totalPages: $totalPages)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ListPaymentMethodDtoImpl && + const DeepCollectionEquality().equals( + other._paymentMethods, + _paymentMethods, + ) && + (identical(other.totalCount, totalCount) || + other.totalCount == totalCount) && + (identical(other.page, page) || other.page == page) && + (identical(other.limit, limit) || other.limit == limit) && + (identical(other.totalPages, totalPages) || + other.totalPages == totalPages)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash( + runtimeType, + const DeepCollectionEquality().hash(_paymentMethods), + totalCount, + page, + limit, + totalPages, + ); + + /// Create a copy of ListPaymentMethodDto + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ListPaymentMethodDtoImplCopyWith<_$ListPaymentMethodDtoImpl> + get copyWith => + __$$ListPaymentMethodDtoImplCopyWithImpl<_$ListPaymentMethodDtoImpl>( + this, + _$identity, + ); + + @override + Map toJson() { + return _$$ListPaymentMethodDtoImplToJson(this); + } +} + +abstract class _ListPaymentMethodDto extends ListPaymentMethodDto { + const factory _ListPaymentMethodDto({ + @JsonKey(name: "payment_methods") + final List? paymentMethods, + @JsonKey(name: "total_count") final int? totalCount, + @JsonKey(name: "page") final int? page, + @JsonKey(name: "limit") final int? limit, + @JsonKey(name: "total_pages") final int? totalPages, + }) = _$ListPaymentMethodDtoImpl; + const _ListPaymentMethodDto._() : super._(); + + factory _ListPaymentMethodDto.fromJson(Map json) = + _$ListPaymentMethodDtoImpl.fromJson; + + @override + @JsonKey(name: "payment_methods") + List? get paymentMethods; + @override + @JsonKey(name: "total_count") + int? get totalCount; + @override + @JsonKey(name: "page") + int? get page; + @override + @JsonKey(name: "limit") + int? get limit; + @override + @JsonKey(name: "total_pages") + int? get totalPages; + + /// Create a copy of ListPaymentMethodDto + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ListPaymentMethodDtoImplCopyWith<_$ListPaymentMethodDtoImpl> + get copyWith => throw _privateConstructorUsedError; +} + +PaymentMethodDto _$PaymentMethodDtoFromJson(Map json) { + return _PaymentMethodDto.fromJson(json); +} + +/// @nodoc +mixin _$PaymentMethodDto { + @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: "type") + String? get type => 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 PaymentMethodDto to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of PaymentMethodDto + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $PaymentMethodDtoCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PaymentMethodDtoCopyWith<$Res> { + factory $PaymentMethodDtoCopyWith( + PaymentMethodDto value, + $Res Function(PaymentMethodDto) then, + ) = _$PaymentMethodDtoCopyWithImpl<$Res, PaymentMethodDto>; + @useResult + $Res call({ + @JsonKey(name: "id") String? id, + @JsonKey(name: "organization_id") String? organizationId, + @JsonKey(name: "name") String? name, + @JsonKey(name: "type") String? type, + @JsonKey(name: "is_active") bool? isActive, + @JsonKey(name: "created_at") String? createdAt, + @JsonKey(name: "updated_at") String? updatedAt, + }); +} + +/// @nodoc +class _$PaymentMethodDtoCopyWithImpl<$Res, $Val extends PaymentMethodDto> + implements $PaymentMethodDtoCopyWith<$Res> { + _$PaymentMethodDtoCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of PaymentMethodDto + /// 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? type = 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?, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String?, + 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 _$$PaymentMethodDtoImplCopyWith<$Res> + implements $PaymentMethodDtoCopyWith<$Res> { + factory _$$PaymentMethodDtoImplCopyWith( + _$PaymentMethodDtoImpl value, + $Res Function(_$PaymentMethodDtoImpl) then, + ) = __$$PaymentMethodDtoImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({ + @JsonKey(name: "id") String? id, + @JsonKey(name: "organization_id") String? organizationId, + @JsonKey(name: "name") String? name, + @JsonKey(name: "type") String? type, + @JsonKey(name: "is_active") bool? isActive, + @JsonKey(name: "created_at") String? createdAt, + @JsonKey(name: "updated_at") String? updatedAt, + }); +} + +/// @nodoc +class __$$PaymentMethodDtoImplCopyWithImpl<$Res> + extends _$PaymentMethodDtoCopyWithImpl<$Res, _$PaymentMethodDtoImpl> + implements _$$PaymentMethodDtoImplCopyWith<$Res> { + __$$PaymentMethodDtoImplCopyWithImpl( + _$PaymentMethodDtoImpl _value, + $Res Function(_$PaymentMethodDtoImpl) _then, + ) : super(_value, _then); + + /// Create a copy of PaymentMethodDto + /// 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? type = freezed, + Object? isActive = freezed, + Object? createdAt = freezed, + Object? updatedAt = freezed, + }) { + return _then( + _$PaymentMethodDtoImpl( + 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?, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String?, + 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 _$PaymentMethodDtoImpl extends _PaymentMethodDto { + const _$PaymentMethodDtoImpl({ + @JsonKey(name: "id") this.id, + @JsonKey(name: "organization_id") this.organizationId, + @JsonKey(name: "name") this.name, + @JsonKey(name: "type") this.type, + @JsonKey(name: "is_active") this.isActive, + @JsonKey(name: "created_at") this.createdAt, + @JsonKey(name: "updated_at") this.updatedAt, + }) : super._(); + + factory _$PaymentMethodDtoImpl.fromJson(Map json) => + _$$PaymentMethodDtoImplFromJson(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: "type") + final String? type; + @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 'PaymentMethodDto(id: $id, organizationId: $organizationId, name: $name, type: $type, isActive: $isActive, createdAt: $createdAt, updatedAt: $updatedAt)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$PaymentMethodDtoImpl && + (identical(other.id, id) || other.id == id) && + (identical(other.organizationId, organizationId) || + other.organizationId == organizationId) && + (identical(other.name, name) || other.name == name) && + (identical(other.type, type) || other.type == type) && + (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, + type, + isActive, + createdAt, + updatedAt, + ); + + /// Create a copy of PaymentMethodDto + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$PaymentMethodDtoImplCopyWith<_$PaymentMethodDtoImpl> get copyWith => + __$$PaymentMethodDtoImplCopyWithImpl<_$PaymentMethodDtoImpl>( + this, + _$identity, + ); + + @override + Map toJson() { + return _$$PaymentMethodDtoImplToJson(this); + } +} + +abstract class _PaymentMethodDto extends PaymentMethodDto { + const factory _PaymentMethodDto({ + @JsonKey(name: "id") final String? id, + @JsonKey(name: "organization_id") final String? organizationId, + @JsonKey(name: "name") final String? name, + @JsonKey(name: "type") final String? type, + @JsonKey(name: "is_active") final bool? isActive, + @JsonKey(name: "created_at") final String? createdAt, + @JsonKey(name: "updated_at") final String? updatedAt, + }) = _$PaymentMethodDtoImpl; + const _PaymentMethodDto._() : super._(); + + factory _PaymentMethodDto.fromJson(Map json) = + _$PaymentMethodDtoImpl.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: "type") + String? get type; + @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 PaymentMethodDto + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$PaymentMethodDtoImplCopyWith<_$PaymentMethodDtoImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/infrastructure/payment_method/payment_method_dtos.g.dart b/lib/infrastructure/payment_method/payment_method_dtos.g.dart new file mode 100644 index 0000000..5a77575 --- /dev/null +++ b/lib/infrastructure/payment_method/payment_method_dtos.g.dart @@ -0,0 +1,53 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'payment_method_dtos.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$ListPaymentMethodDtoImpl _$$ListPaymentMethodDtoImplFromJson( + Map json, +) => _$ListPaymentMethodDtoImpl( + paymentMethods: (json['payment_methods'] as List?) + ?.map((e) => PaymentMethodDto.fromJson(e as Map)) + .toList(), + totalCount: (json['total_count'] as num?)?.toInt(), + page: (json['page'] as num?)?.toInt(), + limit: (json['limit'] as num?)?.toInt(), + totalPages: (json['total_pages'] as num?)?.toInt(), +); + +Map _$$ListPaymentMethodDtoImplToJson( + _$ListPaymentMethodDtoImpl instance, +) => { + 'payment_methods': instance.paymentMethods, + 'total_count': instance.totalCount, + 'page': instance.page, + 'limit': instance.limit, + 'total_pages': instance.totalPages, +}; + +_$PaymentMethodDtoImpl _$$PaymentMethodDtoImplFromJson( + Map json, +) => _$PaymentMethodDtoImpl( + id: json['id'] as String?, + organizationId: json['organization_id'] as String?, + name: json['name'] as String?, + type: json['type'] as String?, + isActive: json['is_active'] as bool?, + createdAt: json['created_at'] as String?, + updatedAt: json['updated_at'] as String?, +); + +Map _$$PaymentMethodDtoImplToJson( + _$PaymentMethodDtoImpl instance, +) => { + 'id': instance.id, + 'organization_id': instance.organizationId, + 'name': instance.name, + 'type': instance.type, + 'is_active': instance.isActive, + 'created_at': instance.createdAt, + 'updated_at': instance.updatedAt, +}; diff --git a/lib/infrastructure/payment_method/repositories/payment_method_repository.dart b/lib/infrastructure/payment_method/repositories/payment_method_repository.dart new file mode 100644 index 0000000..53cae6a --- /dev/null +++ b/lib/infrastructure/payment_method/repositories/payment_method_repository.dart @@ -0,0 +1,38 @@ +import 'dart:developer'; + +import 'package:dartz/dartz.dart'; +import 'package:injectable/injectable.dart'; + +import '../../../domain/payment_method/payment_method.dart'; +import '../datasources/remote_data_provider.dart'; + +@Injectable(as: IPaymentMethodRepository) +class PaymentMethodRepository implements IPaymentMethodRepository { + final PaymentMethodRemoteDataProvider _remoteDataProvider; + final _logName = 'PaymentMethodRepository'; + + PaymentMethodRepository(this._remoteDataProvider); + + @override + Future> getPaymentMethods({ + int page = 1, + int limit = 30, + }) async { + try { + final result = await _remoteDataProvider.fetchPaymentMethods( + page: page, + limit: limit, + ); + + if (result.hasError) { + return left(result.error!); + } + + final paymentMethods = result.data!.toDomain(); + return right(paymentMethods); + } catch (e) { + log('getPaymentMethodError', name: _logName, error: e); + return left(const PaymentMethodFailure.unexpectedError()); + } + } +} diff --git a/lib/injection.config.dart b/lib/injection.config.dart index a78a27a..ded1483 100644 --- a/lib/injection.config.dart +++ b/lib/injection.config.dart @@ -20,6 +20,8 @@ import 'package:apskel_pos_flutter_v2/application/customer/customer_loader/custo as _i683; import 'package:apskel_pos_flutter_v2/application/outlet/outlet_loader/outlet_loader_bloc.dart' as _i76; +import 'package:apskel_pos_flutter_v2/application/payment_method/payment_method_loader/payment_method_loader_bloc.dart' + as _i952; import 'package:apskel_pos_flutter_v2/application/product/product_loader/product_loader_bloc.dart' as _i13; import 'package:apskel_pos_flutter_v2/application/sync/sync_bloc.dart' as _i741; @@ -42,6 +44,8 @@ import 'package:apskel_pos_flutter_v2/domain/auth/auth.dart' as _i776; import 'package:apskel_pos_flutter_v2/domain/category/category.dart' as _i502; import 'package:apskel_pos_flutter_v2/domain/customer/customer.dart' as _i143; import 'package:apskel_pos_flutter_v2/domain/outlet/outlet.dart' as _i552; +import 'package:apskel_pos_flutter_v2/domain/payment_method/payment_method.dart' + as _i297; import 'package:apskel_pos_flutter_v2/domain/product/product.dart' as _i44; import 'package:apskel_pos_flutter_v2/domain/table/table.dart' as _i983; import 'package:apskel_pos_flutter_v2/env.dart' as _i923; @@ -67,6 +71,10 @@ import 'package:apskel_pos_flutter_v2/infrastructure/outlet/datasources/remote_d as _i132; import 'package:apskel_pos_flutter_v2/infrastructure/outlet/repositories/outlet_repository.dart' as _i845; +import 'package:apskel_pos_flutter_v2/infrastructure/payment_method/datasources/remote_data_provider.dart' + as _i833; +import 'package:apskel_pos_flutter_v2/infrastructure/payment_method/repositories/payment_method_repository.dart' + as _i167; import 'package:apskel_pos_flutter_v2/infrastructure/product/datasources/local_data_provider.dart' as _i464; import 'package:apskel_pos_flutter_v2/infrastructure/product/datasources/remote_data_provider.dart' @@ -147,6 +155,9 @@ extension GetItInjectableX on _i174.GetIt { gh.factory<_i841.CustomerRemoteDataProvider>( () => _i841.CustomerRemoteDataProvider(gh<_i457.ApiClient>()), ); + gh.factory<_i833.PaymentMethodRemoteDataProvider>( + () => _i833.PaymentMethodRemoteDataProvider(gh<_i457.ApiClient>()), + ); gh.factory<_i776.IAuthRepository>( () => _i941.AuthRepository( gh<_i370.AuthRemoteDataProvider>(), @@ -183,6 +194,11 @@ extension GetItInjectableX on _i174.GetIt { gh<_i693.OutletLocalDatasource>(), ), ); + gh.factory<_i297.IPaymentMethodRepository>( + () => _i167.PaymentMethodRepository( + gh<_i833.PaymentMethodRemoteDataProvider>(), + ), + ); gh.factory<_i46.LoginFormBloc>( () => _i46.LoginFormBloc(gh<_i776.IAuthRepository>()), ); @@ -195,6 +211,9 @@ extension GetItInjectableX on _i174.GetIt { gh.factory<_i683.CustomerLoaderBloc>( () => _i683.CustomerLoaderBloc(gh<_i143.ICustomerRepository>()), ); + gh.factory<_i952.PaymentMethodLoaderBloc>( + () => _i952.PaymentMethodLoaderBloc(gh<_i297.IPaymentMethodRepository>()), + ); gh.factory<_i343.AuthBloc>( () => _i343.AuthBloc( gh<_i776.IAuthRepository>(), diff --git a/lib/presentation/app_widget.dart b/lib/presentation/app_widget.dart index 3af7498..2aaac4c 100644 --- a/lib/presentation/app_widget.dart +++ b/lib/presentation/app_widget.dart @@ -5,6 +5,7 @@ import '../application/auth/auth_bloc.dart'; import '../application/category/category_loader/category_loader_bloc.dart'; import '../application/checkout/checkout_form/checkout_form_bloc.dart'; import '../application/outlet/outlet_loader/outlet_loader_bloc.dart'; +import '../application/payment_method/payment_method_loader/payment_method_loader_bloc.dart'; import '../application/product/product_loader/product_loader_bloc.dart'; import '../application/table/table_form/table_form_bloc.dart'; import '../application/table/table_loader/table_loader_bloc.dart'; @@ -35,6 +36,7 @@ class _AppWidgetState extends State { BlocProvider(create: (context) => getIt()), BlocProvider(create: (context) => getIt()), BlocProvider(create: (context) => getIt()), + BlocProvider(create: (context) => getIt()), ], child: MaterialApp.router( debugShowCheckedModeBanner: false, diff --git a/lib/presentation/components/card/payment_card.dart b/lib/presentation/components/card/payment_card.dart new file mode 100644 index 0000000..b0d0fc6 --- /dev/null +++ b/lib/presentation/components/card/payment_card.dart @@ -0,0 +1,37 @@ +import 'package:flutter/material.dart'; + +import '../../../common/theme/theme.dart'; +import '../../../domain/payment_method/payment_method.dart'; + +class PaymentCard extends StatelessWidget { + final PaymentMethod payment; + final bool isSelected; + final Function(bool)? onSelected; + const PaymentCard({ + super.key, + required this.payment, + required this.isSelected, + this.onSelected, + }); + + @override + Widget build(BuildContext context) { + return ChoiceChip( + label: Text(payment.name), + selected: isSelected, + onSelected: onSelected, + selectedColor: AppColor.primary, + backgroundColor: AppColor.white, + labelStyle: TextStyle( + color: isSelected ? AppColor.white : AppColor.primary, + fontWeight: FontWeight.bold, + ), + checkmarkColor: AppColor.white, + shape: RoundedRectangleBorder( + side: BorderSide(color: AppColor.primary), + borderRadius: BorderRadius.circular(8), + ), + padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), + ); + } +} diff --git a/lib/presentation/components/error/payment_method_error_state_widget.dart b/lib/presentation/components/error/payment_method_error_state_widget.dart new file mode 100644 index 0000000..a27e001 --- /dev/null +++ b/lib/presentation/components/error/payment_method_error_state_widget.dart @@ -0,0 +1,72 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +import '../../../application/payment_method/payment_method_loader/payment_method_loader_bloc.dart'; +import '../../../domain/payment_method/payment_method.dart'; +import '../card/error_card.dart'; + +class PaymentMethodErrorStateWidget extends StatelessWidget { + final PaymentMethodFailure failure; + const PaymentMethodErrorStateWidget({super.key, required this.failure}); + + @override + Widget build(BuildContext context) { + return failure.maybeMap( + orElse: () => ErrorCard( + title: 'Metode Pembayaran', + message: 'Terjadi Kesalahan saat memuat metode pembayaran', + onTap: () { + context.read().add( + PaymentMethodLoaderEvent.fetched(isRefresh: true), + ); + }, + ), + dynamicErrorMessage: (value) => ErrorCard( + title: 'Metode Pembayaran', + message: value.erroMessage, + onTap: () { + context.read().add( + PaymentMethodLoaderEvent.fetched(isRefresh: true), + ); + }, + ), + empty: (value) => ErrorCard( + title: 'Metode Pembayaran', + message: + 'Metode pembayaran masih kosong, silahkan tambahkan metode pembayaran', + onTap: () { + context.read().add( + PaymentMethodLoaderEvent.fetched(isRefresh: true), + ); + }, + ), + serverError: (value) => ErrorCard( + title: 'Metode Pembayaran', + message: 'Terjadi Kesalahan saat memuat metode pembayaran', + onTap: () { + context.read().add( + PaymentMethodLoaderEvent.fetched(isRefresh: true), + ); + }, + ), + localStorageError: (value) => ErrorCard( + title: 'Metode Pembayaran', + message: value.erroMessage, + onTap: () { + context.read().add( + PaymentMethodLoaderEvent.fetched(isRefresh: true), + ); + }, + ), + unexpectedError: (value) => ErrorCard( + title: 'Metode Pembayaran', + message: 'Terjadi Kesalahan saat memuat metode pembayaran', + onTap: () { + context.read().add( + PaymentMethodLoaderEvent.fetched(isRefresh: true), + ); + }, + ), + ); + } +} diff --git a/lib/presentation/pages/checkout/checkout_page.dart b/lib/presentation/pages/checkout/checkout_page.dart index 459261c..3f71f0c 100644 --- a/lib/presentation/pages/checkout/checkout_page.dart +++ b/lib/presentation/pages/checkout/checkout_page.dart @@ -3,13 +3,15 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import '../../../application/checkout/checkout_form/checkout_form_bloc.dart'; +import '../../../application/payment_method/payment_method_loader/payment_method_loader_bloc.dart'; import '../../../common/theme/theme.dart'; +import '../../../injection.dart'; import '../../components/spaces/space.dart'; import 'widgets/checkout_left_panel.dart'; import 'widgets/checkout_right_panel.dart'; @RoutePage() -class CheckoutPage extends StatelessWidget { +class CheckoutPage extends StatelessWidget implements AutoRouteWrapper { const CheckoutPage({super.key}); @override @@ -49,4 +51,12 @@ class CheckoutPage extends StatelessWidget { ), ); } + + @override + Widget wrappedRoute(BuildContext context) => BlocProvider( + create: (context) => + getIt() + ..add(PaymentMethodLoaderEvent.fetched(isRefresh: true)), + child: this, + ); } diff --git a/lib/presentation/pages/checkout/widgets/checkout_right_panel.dart b/lib/presentation/pages/checkout/widgets/checkout_right_panel.dart index fca29f7..9801ae3 100644 --- a/lib/presentation/pages/checkout/widgets/checkout_right_panel.dart +++ b/lib/presentation/pages/checkout/widgets/checkout_right_panel.dart @@ -1,8 +1,13 @@ import 'package:flutter/widgets.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import '../../../../application/payment_method/payment_method_loader/payment_method_loader_bloc.dart'; import '../../../../common/theme/theme.dart'; -import '../../../components/field/field.dart'; +import '../../../components/card/payment_card.dart'; +import '../../../components/error/payment_method_error_state_widget.dart'; +import '../../../components/loader/loader_with_text.dart'; import '../../../components/page/page_title.dart'; +import '../../../components/spaces/space.dart'; class CheckoutRightPanel extends StatelessWidget { const CheckoutRightPanel({super.key}); @@ -38,6 +43,51 @@ class CheckoutRightPanel extends StatelessWidget { // }, // ), // ), + Container( + padding: const EdgeInsets.all(16), + width: double.infinity, + decoration: BoxDecoration( + color: AppColor.white, + border: Border( + bottom: BorderSide(color: AppColor.border, width: 1.0), + ), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Metode Pembayaran', + style: AppStyle.lg.copyWith( + fontWeight: FontWeight.w600, + ), + ), + const SpaceHeight(12.0), + BlocBuilder< + PaymentMethodLoaderBloc, + PaymentMethodLoaderState + >( + builder: (context, state) { + if (state.isFetching) { + return Center(child: LoaderWithText()); + } + return state.failureOption.fold( + () => Wrap( + spacing: 12.0, + runSpacing: 8.0, + children: state.paymentMethods.map((item) { + return PaymentCard( + payment: item, + isSelected: true, + ); + }).toList(), + ), + (f) => PaymentMethodErrorStateWidget(failure: f), + ); + }, + ), + ], + ), + ), ], ), ),