Customer Point

This commit is contained in:
efrilm
2025-09-18 13:01:31 +07:00
parent a5d66c63b7
commit 73918430b2
22 changed files with 1970 additions and 98 deletions
@@ -0,0 +1,42 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/customer/customer.dart';
part 'customer_point_loader_event.dart';
part 'customer_point_loader_state.dart';
part 'customer_point_loader_bloc.freezed.dart';
@injectable
class CustomerPointLoaderBloc
extends Bloc<CustomerPointLoaderEvent, CustomerPointLoaderState> {
final ICustomerRepository _repository;
CustomerPointLoaderBloc(this._repository)
: super(CustomerPointLoaderState.initial()) {
on<CustomerPointLoaderEvent>(_onCustomerPointLoaderEvent);
}
Future<void> _onCustomerPointLoaderEvent(
CustomerPointLoaderEvent event,
Emitter<CustomerPointLoaderState> emit,
) {
return event.map(
fetched: (e) async {
emit(
state.copyWith(isFetching: true, failureOptionCustomerPoint: none()),
);
final result = await _repository.getPoints();
var data = result.fold(
(f) => state.copyWith(failureOptionCustomerPoint: optionOf(f)),
(customerPoint) => state.copyWith(customerPoint: customerPoint),
);
emit(data.copyWith(isFetching: false));
},
);
}
}
@@ -0,0 +1,391 @@
// 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 'customer_point_loader_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(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 _$CustomerPointLoaderEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $CustomerPointLoaderEventCopyWith<$Res> {
factory $CustomerPointLoaderEventCopyWith(
CustomerPointLoaderEvent value,
$Res Function(CustomerPointLoaderEvent) then,
) = _$CustomerPointLoaderEventCopyWithImpl<$Res, CustomerPointLoaderEvent>;
}
/// @nodoc
class _$CustomerPointLoaderEventCopyWithImpl<
$Res,
$Val extends CustomerPointLoaderEvent
>
implements $CustomerPointLoaderEventCopyWith<$Res> {
_$CustomerPointLoaderEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of CustomerPointLoaderEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$FetchedImplCopyWith<$Res> {
factory _$$FetchedImplCopyWith(
_$FetchedImpl value,
$Res Function(_$FetchedImpl) then,
) = __$$FetchedImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$FetchedImplCopyWithImpl<$Res>
extends _$CustomerPointLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
implements _$$FetchedImplCopyWith<$Res> {
__$$FetchedImplCopyWithImpl(
_$FetchedImpl _value,
$Res Function(_$FetchedImpl) _then,
) : super(_value, _then);
/// Create a copy of CustomerPointLoaderEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$FetchedImpl implements _Fetched {
const _$FetchedImpl();
@override
String toString() {
return 'CustomerPointLoaderEvent.fetched()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$FetchedImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({required TResult Function() fetched}) {
return fetched();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({TResult? Function()? fetched}) {
return fetched?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) {
return fetched(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) {
return fetched?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(this);
}
return orElse();
}
}
abstract class _Fetched implements CustomerPointLoaderEvent {
const factory _Fetched() = _$FetchedImpl;
}
/// @nodoc
mixin _$CustomerPointLoaderState {
CustomerPoint get customerPoint => throw _privateConstructorUsedError;
Option<CustomerFailure> get failureOptionCustomerPoint =>
throw _privateConstructorUsedError;
bool get isFetching => throw _privateConstructorUsedError;
/// Create a copy of CustomerPointLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$CustomerPointLoaderStateCopyWith<CustomerPointLoaderState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $CustomerPointLoaderStateCopyWith<$Res> {
factory $CustomerPointLoaderStateCopyWith(
CustomerPointLoaderState value,
$Res Function(CustomerPointLoaderState) then,
) = _$CustomerPointLoaderStateCopyWithImpl<$Res, CustomerPointLoaderState>;
@useResult
$Res call({
CustomerPoint customerPoint,
Option<CustomerFailure> failureOptionCustomerPoint,
bool isFetching,
});
$CustomerPointCopyWith<$Res> get customerPoint;
}
/// @nodoc
class _$CustomerPointLoaderStateCopyWithImpl<
$Res,
$Val extends CustomerPointLoaderState
>
implements $CustomerPointLoaderStateCopyWith<$Res> {
_$CustomerPointLoaderStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of CustomerPointLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? customerPoint = null,
Object? failureOptionCustomerPoint = null,
Object? isFetching = null,
}) {
return _then(
_value.copyWith(
customerPoint: null == customerPoint
? _value.customerPoint
: customerPoint // ignore: cast_nullable_to_non_nullable
as CustomerPoint,
failureOptionCustomerPoint: null == failureOptionCustomerPoint
? _value.failureOptionCustomerPoint
: failureOptionCustomerPoint // ignore: cast_nullable_to_non_nullable
as Option<CustomerFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
/// Create a copy of CustomerPointLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$CustomerPointCopyWith<$Res> get customerPoint {
return $CustomerPointCopyWith<$Res>(_value.customerPoint, (value) {
return _then(_value.copyWith(customerPoint: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$CustomerPointLoaderStateImplCopyWith<$Res>
implements $CustomerPointLoaderStateCopyWith<$Res> {
factory _$$CustomerPointLoaderStateImplCopyWith(
_$CustomerPointLoaderStateImpl value,
$Res Function(_$CustomerPointLoaderStateImpl) then,
) = __$$CustomerPointLoaderStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
CustomerPoint customerPoint,
Option<CustomerFailure> failureOptionCustomerPoint,
bool isFetching,
});
@override
$CustomerPointCopyWith<$Res> get customerPoint;
}
/// @nodoc
class __$$CustomerPointLoaderStateImplCopyWithImpl<$Res>
extends
_$CustomerPointLoaderStateCopyWithImpl<
$Res,
_$CustomerPointLoaderStateImpl
>
implements _$$CustomerPointLoaderStateImplCopyWith<$Res> {
__$$CustomerPointLoaderStateImplCopyWithImpl(
_$CustomerPointLoaderStateImpl _value,
$Res Function(_$CustomerPointLoaderStateImpl) _then,
) : super(_value, _then);
/// Create a copy of CustomerPointLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? customerPoint = null,
Object? failureOptionCustomerPoint = null,
Object? isFetching = null,
}) {
return _then(
_$CustomerPointLoaderStateImpl(
customerPoint: null == customerPoint
? _value.customerPoint
: customerPoint // ignore: cast_nullable_to_non_nullable
as CustomerPoint,
failureOptionCustomerPoint: null == failureOptionCustomerPoint
? _value.failureOptionCustomerPoint
: failureOptionCustomerPoint // ignore: cast_nullable_to_non_nullable
as Option<CustomerFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$CustomerPointLoaderStateImpl implements _CustomerPointLoaderState {
const _$CustomerPointLoaderStateImpl({
required this.customerPoint,
required this.failureOptionCustomerPoint,
this.isFetching = false,
});
@override
final CustomerPoint customerPoint;
@override
final Option<CustomerFailure> failureOptionCustomerPoint;
@override
@JsonKey()
final bool isFetching;
@override
String toString() {
return 'CustomerPointLoaderState(customerPoint: $customerPoint, failureOptionCustomerPoint: $failureOptionCustomerPoint, isFetching: $isFetching)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CustomerPointLoaderStateImpl &&
(identical(other.customerPoint, customerPoint) ||
other.customerPoint == customerPoint) &&
(identical(
other.failureOptionCustomerPoint,
failureOptionCustomerPoint,
) ||
other.failureOptionCustomerPoint ==
failureOptionCustomerPoint) &&
(identical(other.isFetching, isFetching) ||
other.isFetching == isFetching));
}
@override
int get hashCode => Object.hash(
runtimeType,
customerPoint,
failureOptionCustomerPoint,
isFetching,
);
/// Create a copy of CustomerPointLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$CustomerPointLoaderStateImplCopyWith<_$CustomerPointLoaderStateImpl>
get copyWith =>
__$$CustomerPointLoaderStateImplCopyWithImpl<
_$CustomerPointLoaderStateImpl
>(this, _$identity);
}
abstract class _CustomerPointLoaderState implements CustomerPointLoaderState {
const factory _CustomerPointLoaderState({
required final CustomerPoint customerPoint,
required final Option<CustomerFailure> failureOptionCustomerPoint,
final bool isFetching,
}) = _$CustomerPointLoaderStateImpl;
@override
CustomerPoint get customerPoint;
@override
Option<CustomerFailure> get failureOptionCustomerPoint;
@override
bool get isFetching;
/// Create a copy of CustomerPointLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$CustomerPointLoaderStateImplCopyWith<_$CustomerPointLoaderStateImpl>
get copyWith => throw _privateConstructorUsedError;
}
@@ -0,0 +1,6 @@
part of 'customer_point_loader_bloc.dart';
@freezed
class CustomerPointLoaderEvent with _$CustomerPointLoaderEvent {
const factory CustomerPointLoaderEvent.fetched() = _Fetched;
}
@@ -0,0 +1,15 @@
part of 'customer_point_loader_bloc.dart';
@freezed
class CustomerPointLoaderState with _$CustomerPointLoaderState {
const factory CustomerPointLoaderState({
required CustomerPoint customerPoint,
required Option<CustomerFailure> failureOptionCustomerPoint,
@Default(false) bool isFetching,
}) = _CustomerPointLoaderState;
factory CustomerPointLoaderState.initial() => CustomerPointLoaderState(
customerPoint: CustomerPoint.empty(),
failureOptionCustomerPoint: none(),
);
}