feat: product analytic repo
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../domain/analytic/analytic.dart';
|
||||
import '../../../domain/analytic/repositories/i_analytic_repository.dart';
|
||||
|
||||
part 'product_analytic_loader_event.dart';
|
||||
part 'product_analytic_loader_state.dart';
|
||||
part 'product_analytic_loader_bloc.freezed.dart';
|
||||
|
||||
@injectable
|
||||
class ProductAnalyticLoaderBloc
|
||||
extends Bloc<ProductAnalyticLoaderEvent, ProductAnalyticLoaderState> {
|
||||
final IAnalyticRepository _repository;
|
||||
ProductAnalyticLoaderBloc(this._repository)
|
||||
: super(ProductAnalyticLoaderState.initial()) {
|
||||
on<ProductAnalyticLoaderEvent>(_onProductAnalyticLoaderEvent);
|
||||
}
|
||||
|
||||
Future<void> _onProductAnalyticLoaderEvent(
|
||||
ProductAnalyticLoaderEvent event,
|
||||
Emitter<ProductAnalyticLoaderState> emit,
|
||||
) {
|
||||
return event.map(
|
||||
fetched: (e) async {
|
||||
emit(
|
||||
state.copyWith(
|
||||
isFetching: true,
|
||||
failureOptionProductAnalytic: none(),
|
||||
),
|
||||
);
|
||||
|
||||
final result = await _repository.getProduct(
|
||||
dateFrom: DateTime.now().subtract(const Duration(days: 30)),
|
||||
dateTo: DateTime.now(),
|
||||
);
|
||||
|
||||
var data = result.fold(
|
||||
(f) => state.copyWith(failureOptionProductAnalytic: optionOf(f)),
|
||||
(productAnalytic) => state.copyWith(productAnalytic: productAnalytic),
|
||||
);
|
||||
|
||||
emit(data.copyWith(isFetching: false));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
+385
@@ -0,0 +1,385 @@
|
||||
// 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 'product_analytic_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 _$ProductAnalyticLoaderEvent {
|
||||
@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 $ProductAnalyticLoaderEventCopyWith<$Res> {
|
||||
factory $ProductAnalyticLoaderEventCopyWith(
|
||||
ProductAnalyticLoaderEvent value,
|
||||
$Res Function(ProductAnalyticLoaderEvent) then,
|
||||
) =
|
||||
_$ProductAnalyticLoaderEventCopyWithImpl<
|
||||
$Res,
|
||||
ProductAnalyticLoaderEvent
|
||||
>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$ProductAnalyticLoaderEventCopyWithImpl<
|
||||
$Res,
|
||||
$Val extends ProductAnalyticLoaderEvent
|
||||
>
|
||||
implements $ProductAnalyticLoaderEventCopyWith<$Res> {
|
||||
_$ProductAnalyticLoaderEventCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of ProductAnalyticLoaderEvent
|
||||
/// 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 _$ProductAnalyticLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
|
||||
implements _$$FetchedImplCopyWith<$Res> {
|
||||
__$$FetchedImplCopyWithImpl(
|
||||
_$FetchedImpl _value,
|
||||
$Res Function(_$FetchedImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of ProductAnalyticLoaderEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$FetchedImpl implements _Fetched {
|
||||
const _$FetchedImpl();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ProductAnalyticLoaderEvent.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 ProductAnalyticLoaderEvent {
|
||||
const factory _Fetched() = _$FetchedImpl;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$ProductAnalyticLoaderState {
|
||||
ProductAnalytic get productAnalytic => throw _privateConstructorUsedError;
|
||||
dynamic get failureOptionProductAnalytic =>
|
||||
throw _privateConstructorUsedError;
|
||||
bool get isFetching => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of ProductAnalyticLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$ProductAnalyticLoaderStateCopyWith<ProductAnalyticLoaderState>
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $ProductAnalyticLoaderStateCopyWith<$Res> {
|
||||
factory $ProductAnalyticLoaderStateCopyWith(
|
||||
ProductAnalyticLoaderState value,
|
||||
$Res Function(ProductAnalyticLoaderState) then,
|
||||
) =
|
||||
_$ProductAnalyticLoaderStateCopyWithImpl<
|
||||
$Res,
|
||||
ProductAnalyticLoaderState
|
||||
>;
|
||||
@useResult
|
||||
$Res call({
|
||||
ProductAnalytic productAnalytic,
|
||||
dynamic failureOptionProductAnalytic,
|
||||
bool isFetching,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$ProductAnalyticLoaderStateCopyWithImpl<
|
||||
$Res,
|
||||
$Val extends ProductAnalyticLoaderState
|
||||
>
|
||||
implements $ProductAnalyticLoaderStateCopyWith<$Res> {
|
||||
_$ProductAnalyticLoaderStateCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of ProductAnalyticLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? productAnalytic = freezed,
|
||||
Object? failureOptionProductAnalytic = freezed,
|
||||
Object? isFetching = null,
|
||||
}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
productAnalytic: freezed == productAnalytic
|
||||
? _value.productAnalytic
|
||||
: productAnalytic // ignore: cast_nullable_to_non_nullable
|
||||
as ProductAnalytic,
|
||||
failureOptionProductAnalytic:
|
||||
freezed == failureOptionProductAnalytic
|
||||
? _value.failureOptionProductAnalytic
|
||||
: failureOptionProductAnalytic // ignore: cast_nullable_to_non_nullable
|
||||
as dynamic,
|
||||
isFetching: null == isFetching
|
||||
? _value.isFetching
|
||||
: isFetching // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$ProductAnalyticLoaderStateImplCopyWith<$Res>
|
||||
implements $ProductAnalyticLoaderStateCopyWith<$Res> {
|
||||
factory _$$ProductAnalyticLoaderStateImplCopyWith(
|
||||
_$ProductAnalyticLoaderStateImpl value,
|
||||
$Res Function(_$ProductAnalyticLoaderStateImpl) then,
|
||||
) = __$$ProductAnalyticLoaderStateImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({
|
||||
ProductAnalytic productAnalytic,
|
||||
dynamic failureOptionProductAnalytic,
|
||||
bool isFetching,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$ProductAnalyticLoaderStateImplCopyWithImpl<$Res>
|
||||
extends
|
||||
_$ProductAnalyticLoaderStateCopyWithImpl<
|
||||
$Res,
|
||||
_$ProductAnalyticLoaderStateImpl
|
||||
>
|
||||
implements _$$ProductAnalyticLoaderStateImplCopyWith<$Res> {
|
||||
__$$ProductAnalyticLoaderStateImplCopyWithImpl(
|
||||
_$ProductAnalyticLoaderStateImpl _value,
|
||||
$Res Function(_$ProductAnalyticLoaderStateImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of ProductAnalyticLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? productAnalytic = freezed,
|
||||
Object? failureOptionProductAnalytic = freezed,
|
||||
Object? isFetching = null,
|
||||
}) {
|
||||
return _then(
|
||||
_$ProductAnalyticLoaderStateImpl(
|
||||
productAnalytic: freezed == productAnalytic
|
||||
? _value.productAnalytic
|
||||
: productAnalytic // ignore: cast_nullable_to_non_nullable
|
||||
as ProductAnalytic,
|
||||
failureOptionProductAnalytic: freezed == failureOptionProductAnalytic
|
||||
? _value.failureOptionProductAnalytic!
|
||||
: failureOptionProductAnalytic,
|
||||
isFetching: null == isFetching
|
||||
? _value.isFetching
|
||||
: isFetching // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$ProductAnalyticLoaderStateImpl implements _ProductAnalyticLoaderState {
|
||||
const _$ProductAnalyticLoaderStateImpl({
|
||||
required this.productAnalytic,
|
||||
required this.failureOptionProductAnalytic,
|
||||
this.isFetching = false,
|
||||
});
|
||||
|
||||
@override
|
||||
final ProductAnalytic productAnalytic;
|
||||
@override
|
||||
final dynamic failureOptionProductAnalytic;
|
||||
@override
|
||||
@JsonKey()
|
||||
final bool isFetching;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ProductAnalyticLoaderState(productAnalytic: $productAnalytic, failureOptionProductAnalytic: $failureOptionProductAnalytic, isFetching: $isFetching)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$ProductAnalyticLoaderStateImpl &&
|
||||
const DeepCollectionEquality().equals(
|
||||
other.productAnalytic,
|
||||
productAnalytic,
|
||||
) &&
|
||||
const DeepCollectionEquality().equals(
|
||||
other.failureOptionProductAnalytic,
|
||||
failureOptionProductAnalytic,
|
||||
) &&
|
||||
(identical(other.isFetching, isFetching) ||
|
||||
other.isFetching == isFetching));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
const DeepCollectionEquality().hash(productAnalytic),
|
||||
const DeepCollectionEquality().hash(failureOptionProductAnalytic),
|
||||
isFetching,
|
||||
);
|
||||
|
||||
/// Create a copy of ProductAnalyticLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$ProductAnalyticLoaderStateImplCopyWith<_$ProductAnalyticLoaderStateImpl>
|
||||
get copyWith =>
|
||||
__$$ProductAnalyticLoaderStateImplCopyWithImpl<
|
||||
_$ProductAnalyticLoaderStateImpl
|
||||
>(this, _$identity);
|
||||
}
|
||||
|
||||
abstract class _ProductAnalyticLoaderState
|
||||
implements ProductAnalyticLoaderState {
|
||||
const factory _ProductAnalyticLoaderState({
|
||||
required final ProductAnalytic productAnalytic,
|
||||
required final dynamic failureOptionProductAnalytic,
|
||||
final bool isFetching,
|
||||
}) = _$ProductAnalyticLoaderStateImpl;
|
||||
|
||||
@override
|
||||
ProductAnalytic get productAnalytic;
|
||||
@override
|
||||
dynamic get failureOptionProductAnalytic;
|
||||
@override
|
||||
bool get isFetching;
|
||||
|
||||
/// Create a copy of ProductAnalyticLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$ProductAnalyticLoaderStateImplCopyWith<_$ProductAnalyticLoaderStateImpl>
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
part of 'product_analytic_loader_bloc.dart';
|
||||
|
||||
@freezed
|
||||
class ProductAnalyticLoaderEvent with _$ProductAnalyticLoaderEvent {
|
||||
const factory ProductAnalyticLoaderEvent.fetched() = _Fetched;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
part of 'product_analytic_loader_bloc.dart';
|
||||
|
||||
@freezed
|
||||
class ProductAnalyticLoaderState with _$ProductAnalyticLoaderState {
|
||||
const factory ProductAnalyticLoaderState({
|
||||
required ProductAnalytic productAnalytic,
|
||||
required Option<AnalyticFailure> failureOptionProductAnalytic,
|
||||
@Default(false) bool isFetching,
|
||||
}) = _ProductAnalyticLoaderState;
|
||||
|
||||
factory ProductAnalyticLoaderState.initial() => ProductAnalyticLoaderState(
|
||||
productAnalytic: ProductAnalytic.empty(),
|
||||
failureOptionProductAnalytic: none(),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user