feat: category
This commit is contained in:
parent
f84090c0e6
commit
4a4f6388d7
@ -0,0 +1,55 @@
|
|||||||
|
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/category/category.dart';
|
||||||
|
|
||||||
|
part 'category_loader_event.dart';
|
||||||
|
part 'category_loader_state.dart';
|
||||||
|
part 'category_loader_bloc.freezed.dart';
|
||||||
|
|
||||||
|
@injectable
|
||||||
|
class CategoryLoaderBloc
|
||||||
|
extends Bloc<CategoryLoaderEvent, CategoryLoaderState> {
|
||||||
|
final ICategoryRepository _repository;
|
||||||
|
CategoryLoaderBloc(this._repository) : super(CategoryLoaderState.initial()) {
|
||||||
|
on<CategoryLoaderEvent>(_onCategoryLoaderEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onCategoryLoaderEvent(
|
||||||
|
CategoryLoaderEvent event,
|
||||||
|
Emitter<CategoryLoaderState> emit,
|
||||||
|
) {
|
||||||
|
return event.map(
|
||||||
|
fetched: (e) async {
|
||||||
|
emit(state.copyWith(isFetching: true, failureOptionCategory: none()));
|
||||||
|
|
||||||
|
final result = await _repository.get();
|
||||||
|
|
||||||
|
result.fold(
|
||||||
|
(f) {
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
isFetching: false,
|
||||||
|
failureOptionCategory: optionOf(f),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
(categories) {
|
||||||
|
// tambahkan "All Data" di awal list
|
||||||
|
final updatedCategories = [Category.addAllData(), ...categories];
|
||||||
|
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
isFetching: false,
|
||||||
|
categories: updatedCategories,
|
||||||
|
failureOptionCategory: none(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,370 @@
|
|||||||
|
// 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 'category_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 _$CategoryLoaderEvent {
|
||||||
|
@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 $CategoryLoaderEventCopyWith<$Res> {
|
||||||
|
factory $CategoryLoaderEventCopyWith(
|
||||||
|
CategoryLoaderEvent value,
|
||||||
|
$Res Function(CategoryLoaderEvent) then,
|
||||||
|
) = _$CategoryLoaderEventCopyWithImpl<$Res, CategoryLoaderEvent>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class _$CategoryLoaderEventCopyWithImpl<$Res, $Val extends CategoryLoaderEvent>
|
||||||
|
implements $CategoryLoaderEventCopyWith<$Res> {
|
||||||
|
_$CategoryLoaderEventCopyWithImpl(this._value, this._then);
|
||||||
|
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Val _value;
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Res Function($Val) _then;
|
||||||
|
|
||||||
|
/// Create a copy of CategoryLoaderEvent
|
||||||
|
/// 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 _$CategoryLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
|
||||||
|
implements _$$FetchedImplCopyWith<$Res> {
|
||||||
|
__$$FetchedImplCopyWithImpl(
|
||||||
|
_$FetchedImpl _value,
|
||||||
|
$Res Function(_$FetchedImpl) _then,
|
||||||
|
) : super(_value, _then);
|
||||||
|
|
||||||
|
/// Create a copy of CategoryLoaderEvent
|
||||||
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
|
||||||
|
class _$FetchedImpl implements _Fetched {
|
||||||
|
const _$FetchedImpl();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'CategoryLoaderEvent.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 CategoryLoaderEvent {
|
||||||
|
const factory _Fetched() = _$FetchedImpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
mixin _$CategoryLoaderState {
|
||||||
|
List<Category> get categories => throw _privateConstructorUsedError;
|
||||||
|
Option<CategoryFailure> get failureOptionCategory =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
bool get isFetching => throw _privateConstructorUsedError;
|
||||||
|
|
||||||
|
/// Create a copy of CategoryLoaderState
|
||||||
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
|
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||||
|
$CategoryLoaderStateCopyWith<CategoryLoaderState> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class $CategoryLoaderStateCopyWith<$Res> {
|
||||||
|
factory $CategoryLoaderStateCopyWith(
|
||||||
|
CategoryLoaderState value,
|
||||||
|
$Res Function(CategoryLoaderState) then,
|
||||||
|
) = _$CategoryLoaderStateCopyWithImpl<$Res, CategoryLoaderState>;
|
||||||
|
@useResult
|
||||||
|
$Res call({
|
||||||
|
List<Category> categories,
|
||||||
|
Option<CategoryFailure> failureOptionCategory,
|
||||||
|
bool isFetching,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class _$CategoryLoaderStateCopyWithImpl<$Res, $Val extends CategoryLoaderState>
|
||||||
|
implements $CategoryLoaderStateCopyWith<$Res> {
|
||||||
|
_$CategoryLoaderStateCopyWithImpl(this._value, this._then);
|
||||||
|
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Val _value;
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Res Function($Val) _then;
|
||||||
|
|
||||||
|
/// Create a copy of CategoryLoaderState
|
||||||
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
|
@pragma('vm:prefer-inline')
|
||||||
|
@override
|
||||||
|
$Res call({
|
||||||
|
Object? categories = null,
|
||||||
|
Object? failureOptionCategory = null,
|
||||||
|
Object? isFetching = null,
|
||||||
|
}) {
|
||||||
|
return _then(
|
||||||
|
_value.copyWith(
|
||||||
|
categories: null == categories
|
||||||
|
? _value.categories
|
||||||
|
: categories // ignore: cast_nullable_to_non_nullable
|
||||||
|
as List<Category>,
|
||||||
|
failureOptionCategory: null == failureOptionCategory
|
||||||
|
? _value.failureOptionCategory
|
||||||
|
: failureOptionCategory // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Option<CategoryFailure>,
|
||||||
|
isFetching: null == isFetching
|
||||||
|
? _value.isFetching
|
||||||
|
: isFetching // ignore: cast_nullable_to_non_nullable
|
||||||
|
as bool,
|
||||||
|
)
|
||||||
|
as $Val,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class _$$CategoryLoaderStateImplCopyWith<$Res>
|
||||||
|
implements $CategoryLoaderStateCopyWith<$Res> {
|
||||||
|
factory _$$CategoryLoaderStateImplCopyWith(
|
||||||
|
_$CategoryLoaderStateImpl value,
|
||||||
|
$Res Function(_$CategoryLoaderStateImpl) then,
|
||||||
|
) = __$$CategoryLoaderStateImplCopyWithImpl<$Res>;
|
||||||
|
@override
|
||||||
|
@useResult
|
||||||
|
$Res call({
|
||||||
|
List<Category> categories,
|
||||||
|
Option<CategoryFailure> failureOptionCategory,
|
||||||
|
bool isFetching,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class __$$CategoryLoaderStateImplCopyWithImpl<$Res>
|
||||||
|
extends _$CategoryLoaderStateCopyWithImpl<$Res, _$CategoryLoaderStateImpl>
|
||||||
|
implements _$$CategoryLoaderStateImplCopyWith<$Res> {
|
||||||
|
__$$CategoryLoaderStateImplCopyWithImpl(
|
||||||
|
_$CategoryLoaderStateImpl _value,
|
||||||
|
$Res Function(_$CategoryLoaderStateImpl) _then,
|
||||||
|
) : super(_value, _then);
|
||||||
|
|
||||||
|
/// Create a copy of CategoryLoaderState
|
||||||
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
|
@pragma('vm:prefer-inline')
|
||||||
|
@override
|
||||||
|
$Res call({
|
||||||
|
Object? categories = null,
|
||||||
|
Object? failureOptionCategory = null,
|
||||||
|
Object? isFetching = null,
|
||||||
|
}) {
|
||||||
|
return _then(
|
||||||
|
_$CategoryLoaderStateImpl(
|
||||||
|
categories: null == categories
|
||||||
|
? _value._categories
|
||||||
|
: categories // ignore: cast_nullable_to_non_nullable
|
||||||
|
as List<Category>,
|
||||||
|
failureOptionCategory: null == failureOptionCategory
|
||||||
|
? _value.failureOptionCategory
|
||||||
|
: failureOptionCategory // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Option<CategoryFailure>,
|
||||||
|
isFetching: null == isFetching
|
||||||
|
? _value.isFetching
|
||||||
|
: isFetching // ignore: cast_nullable_to_non_nullable
|
||||||
|
as bool,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
|
||||||
|
class _$CategoryLoaderStateImpl implements _CategoryLoaderState {
|
||||||
|
const _$CategoryLoaderStateImpl({
|
||||||
|
required final List<Category> categories,
|
||||||
|
required this.failureOptionCategory,
|
||||||
|
this.isFetching = false,
|
||||||
|
}) : _categories = categories;
|
||||||
|
|
||||||
|
final List<Category> _categories;
|
||||||
|
@override
|
||||||
|
List<Category> get categories {
|
||||||
|
if (_categories is EqualUnmodifiableListView) return _categories;
|
||||||
|
// ignore: implicit_dynamic_type
|
||||||
|
return EqualUnmodifiableListView(_categories);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
final Option<CategoryFailure> failureOptionCategory;
|
||||||
|
@override
|
||||||
|
@JsonKey()
|
||||||
|
final bool isFetching;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'CategoryLoaderState(categories: $categories, failureOptionCategory: $failureOptionCategory, isFetching: $isFetching)';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
return identical(this, other) ||
|
||||||
|
(other.runtimeType == runtimeType &&
|
||||||
|
other is _$CategoryLoaderStateImpl &&
|
||||||
|
const DeepCollectionEquality().equals(
|
||||||
|
other._categories,
|
||||||
|
_categories,
|
||||||
|
) &&
|
||||||
|
(identical(other.failureOptionCategory, failureOptionCategory) ||
|
||||||
|
other.failureOptionCategory == failureOptionCategory) &&
|
||||||
|
(identical(other.isFetching, isFetching) ||
|
||||||
|
other.isFetching == isFetching));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => Object.hash(
|
||||||
|
runtimeType,
|
||||||
|
const DeepCollectionEquality().hash(_categories),
|
||||||
|
failureOptionCategory,
|
||||||
|
isFetching,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Create a copy of CategoryLoaderState
|
||||||
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
|
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||||
|
@override
|
||||||
|
@pragma('vm:prefer-inline')
|
||||||
|
_$$CategoryLoaderStateImplCopyWith<_$CategoryLoaderStateImpl> get copyWith =>
|
||||||
|
__$$CategoryLoaderStateImplCopyWithImpl<_$CategoryLoaderStateImpl>(
|
||||||
|
this,
|
||||||
|
_$identity,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class _CategoryLoaderState implements CategoryLoaderState {
|
||||||
|
const factory _CategoryLoaderState({
|
||||||
|
required final List<Category> categories,
|
||||||
|
required final Option<CategoryFailure> failureOptionCategory,
|
||||||
|
final bool isFetching,
|
||||||
|
}) = _$CategoryLoaderStateImpl;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Category> get categories;
|
||||||
|
@override
|
||||||
|
Option<CategoryFailure> get failureOptionCategory;
|
||||||
|
@override
|
||||||
|
bool get isFetching;
|
||||||
|
|
||||||
|
/// Create a copy of CategoryLoaderState
|
||||||
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
|
@override
|
||||||
|
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||||
|
_$$CategoryLoaderStateImplCopyWith<_$CategoryLoaderStateImpl> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
part of 'category_loader_bloc.dart';
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
class CategoryLoaderEvent with _$CategoryLoaderEvent {
|
||||||
|
const factory CategoryLoaderEvent.fetched() = _Fetched;
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
part of 'category_loader_bloc.dart';
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
class CategoryLoaderState with _$CategoryLoaderState {
|
||||||
|
const factory CategoryLoaderState({
|
||||||
|
required List<Category> categories,
|
||||||
|
required Option<CategoryFailure> failureOptionCategory,
|
||||||
|
@Default(false) bool isFetching,
|
||||||
|
}) = _CategoryLoaderState;
|
||||||
|
|
||||||
|
factory CategoryLoaderState.initial() =>
|
||||||
|
CategoryLoaderState(categories: [], failureOptionCategory: none());
|
||||||
|
}
|
||||||
@ -5,4 +5,7 @@ class ApiPath {
|
|||||||
|
|
||||||
// Analytic
|
// Analytic
|
||||||
static const String salesAnalytic = '/api/v1/analytics/sales';
|
static const String salesAnalytic = '/api/v1/analytics/sales';
|
||||||
|
|
||||||
|
// Category
|
||||||
|
static const String category = '/api/v1/categories';
|
||||||
}
|
}
|
||||||
|
|||||||
10
lib/domain/category/category.dart
Normal file
10
lib/domain/category/category.dart
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import 'package:dartz/dartz.dart';
|
||||||
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||||
|
|
||||||
|
import '../../common/api/api_failure.dart';
|
||||||
|
|
||||||
|
part 'category.freezed.dart';
|
||||||
|
|
||||||
|
part 'entities/category_entity.dart';
|
||||||
|
part 'failures/category_failure.dart';
|
||||||
|
part 'repositories/i_auth_repository.dart';
|
||||||
952
lib/domain/category/category.freezed.dart
Normal file
952
lib/domain/category/category.freezed.dart
Normal file
@ -0,0 +1,952 @@
|
|||||||
|
// 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 'category.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 _$Category {
|
||||||
|
String get id => throw _privateConstructorUsedError;
|
||||||
|
String get organizationId => throw _privateConstructorUsedError;
|
||||||
|
String get name => throw _privateConstructorUsedError;
|
||||||
|
String get description => throw _privateConstructorUsedError;
|
||||||
|
String get businessType => throw _privateConstructorUsedError;
|
||||||
|
Map<String, dynamic> get metadata => throw _privateConstructorUsedError;
|
||||||
|
DateTime? get createdAt => throw _privateConstructorUsedError;
|
||||||
|
DateTime? get updatedAt => throw _privateConstructorUsedError;
|
||||||
|
|
||||||
|
/// Create a copy of Category
|
||||||
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
|
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||||
|
$CategoryCopyWith<Category> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class $CategoryCopyWith<$Res> {
|
||||||
|
factory $CategoryCopyWith(Category value, $Res Function(Category) then) =
|
||||||
|
_$CategoryCopyWithImpl<$Res, Category>;
|
||||||
|
@useResult
|
||||||
|
$Res call({
|
||||||
|
String id,
|
||||||
|
String organizationId,
|
||||||
|
String name,
|
||||||
|
String description,
|
||||||
|
String businessType,
|
||||||
|
Map<String, dynamic> metadata,
|
||||||
|
DateTime? createdAt,
|
||||||
|
DateTime? updatedAt,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class _$CategoryCopyWithImpl<$Res, $Val extends Category>
|
||||||
|
implements $CategoryCopyWith<$Res> {
|
||||||
|
_$CategoryCopyWithImpl(this._value, this._then);
|
||||||
|
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Val _value;
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Res Function($Val) _then;
|
||||||
|
|
||||||
|
/// Create a copy of Category
|
||||||
|
/// 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? description = null,
|
||||||
|
Object? businessType = null,
|
||||||
|
Object? metadata = null,
|
||||||
|
Object? createdAt = freezed,
|
||||||
|
Object? updatedAt = freezed,
|
||||||
|
}) {
|
||||||
|
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,
|
||||||
|
description: null == description
|
||||||
|
? _value.description
|
||||||
|
: description // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String,
|
||||||
|
businessType: null == businessType
|
||||||
|
? _value.businessType
|
||||||
|
: businessType // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String,
|
||||||
|
metadata: null == metadata
|
||||||
|
? _value.metadata
|
||||||
|
: metadata // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Map<String, dynamic>,
|
||||||
|
createdAt: freezed == createdAt
|
||||||
|
? _value.createdAt
|
||||||
|
: createdAt // ignore: cast_nullable_to_non_nullable
|
||||||
|
as DateTime?,
|
||||||
|
updatedAt: freezed == updatedAt
|
||||||
|
? _value.updatedAt
|
||||||
|
: updatedAt // ignore: cast_nullable_to_non_nullable
|
||||||
|
as DateTime?,
|
||||||
|
)
|
||||||
|
as $Val,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class _$$CategoryImplCopyWith<$Res>
|
||||||
|
implements $CategoryCopyWith<$Res> {
|
||||||
|
factory _$$CategoryImplCopyWith(
|
||||||
|
_$CategoryImpl value,
|
||||||
|
$Res Function(_$CategoryImpl) then,
|
||||||
|
) = __$$CategoryImplCopyWithImpl<$Res>;
|
||||||
|
@override
|
||||||
|
@useResult
|
||||||
|
$Res call({
|
||||||
|
String id,
|
||||||
|
String organizationId,
|
||||||
|
String name,
|
||||||
|
String description,
|
||||||
|
String businessType,
|
||||||
|
Map<String, dynamic> metadata,
|
||||||
|
DateTime? createdAt,
|
||||||
|
DateTime? updatedAt,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class __$$CategoryImplCopyWithImpl<$Res>
|
||||||
|
extends _$CategoryCopyWithImpl<$Res, _$CategoryImpl>
|
||||||
|
implements _$$CategoryImplCopyWith<$Res> {
|
||||||
|
__$$CategoryImplCopyWithImpl(
|
||||||
|
_$CategoryImpl _value,
|
||||||
|
$Res Function(_$CategoryImpl) _then,
|
||||||
|
) : super(_value, _then);
|
||||||
|
|
||||||
|
/// Create a copy of Category
|
||||||
|
/// 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? description = null,
|
||||||
|
Object? businessType = null,
|
||||||
|
Object? metadata = null,
|
||||||
|
Object? createdAt = freezed,
|
||||||
|
Object? updatedAt = freezed,
|
||||||
|
}) {
|
||||||
|
return _then(
|
||||||
|
_$CategoryImpl(
|
||||||
|
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,
|
||||||
|
description: null == description
|
||||||
|
? _value.description
|
||||||
|
: description // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String,
|
||||||
|
businessType: null == businessType
|
||||||
|
? _value.businessType
|
||||||
|
: businessType // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String,
|
||||||
|
metadata: null == metadata
|
||||||
|
? _value._metadata
|
||||||
|
: metadata // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Map<String, dynamic>,
|
||||||
|
createdAt: freezed == createdAt
|
||||||
|
? _value.createdAt
|
||||||
|
: createdAt // ignore: cast_nullable_to_non_nullable
|
||||||
|
as DateTime?,
|
||||||
|
updatedAt: freezed == updatedAt
|
||||||
|
? _value.updatedAt
|
||||||
|
: updatedAt // ignore: cast_nullable_to_non_nullable
|
||||||
|
as DateTime?,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
|
||||||
|
class _$CategoryImpl implements _Category {
|
||||||
|
const _$CategoryImpl({
|
||||||
|
required this.id,
|
||||||
|
required this.organizationId,
|
||||||
|
required this.name,
|
||||||
|
required this.description,
|
||||||
|
required this.businessType,
|
||||||
|
required final Map<String, dynamic> metadata,
|
||||||
|
this.createdAt,
|
||||||
|
this.updatedAt,
|
||||||
|
}) : _metadata = metadata;
|
||||||
|
|
||||||
|
@override
|
||||||
|
final String id;
|
||||||
|
@override
|
||||||
|
final String organizationId;
|
||||||
|
@override
|
||||||
|
final String name;
|
||||||
|
@override
|
||||||
|
final String description;
|
||||||
|
@override
|
||||||
|
final String businessType;
|
||||||
|
final Map<String, dynamic> _metadata;
|
||||||
|
@override
|
||||||
|
Map<String, dynamic> get metadata {
|
||||||
|
if (_metadata is EqualUnmodifiableMapView) return _metadata;
|
||||||
|
// ignore: implicit_dynamic_type
|
||||||
|
return EqualUnmodifiableMapView(_metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
final DateTime? createdAt;
|
||||||
|
@override
|
||||||
|
final DateTime? updatedAt;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'Category(id: $id, organizationId: $organizationId, name: $name, description: $description, businessType: $businessType, metadata: $metadata, createdAt: $createdAt, updatedAt: $updatedAt)';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
return identical(this, other) ||
|
||||||
|
(other.runtimeType == runtimeType &&
|
||||||
|
other is _$CategoryImpl &&
|
||||||
|
(identical(other.id, id) || other.id == id) &&
|
||||||
|
(identical(other.organizationId, organizationId) ||
|
||||||
|
other.organizationId == organizationId) &&
|
||||||
|
(identical(other.name, name) || other.name == name) &&
|
||||||
|
(identical(other.description, description) ||
|
||||||
|
other.description == description) &&
|
||||||
|
(identical(other.businessType, businessType) ||
|
||||||
|
other.businessType == businessType) &&
|
||||||
|
const DeepCollectionEquality().equals(other._metadata, _metadata) &&
|
||||||
|
(identical(other.createdAt, createdAt) ||
|
||||||
|
other.createdAt == createdAt) &&
|
||||||
|
(identical(other.updatedAt, updatedAt) ||
|
||||||
|
other.updatedAt == updatedAt));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => Object.hash(
|
||||||
|
runtimeType,
|
||||||
|
id,
|
||||||
|
organizationId,
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
businessType,
|
||||||
|
const DeepCollectionEquality().hash(_metadata),
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Create a copy of Category
|
||||||
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
|
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||||
|
@override
|
||||||
|
@pragma('vm:prefer-inline')
|
||||||
|
_$$CategoryImplCopyWith<_$CategoryImpl> get copyWith =>
|
||||||
|
__$$CategoryImplCopyWithImpl<_$CategoryImpl>(this, _$identity);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class _Category implements Category {
|
||||||
|
const factory _Category({
|
||||||
|
required final String id,
|
||||||
|
required final String organizationId,
|
||||||
|
required final String name,
|
||||||
|
required final String description,
|
||||||
|
required final String businessType,
|
||||||
|
required final Map<String, dynamic> metadata,
|
||||||
|
final DateTime? createdAt,
|
||||||
|
final DateTime? updatedAt,
|
||||||
|
}) = _$CategoryImpl;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get id;
|
||||||
|
@override
|
||||||
|
String get organizationId;
|
||||||
|
@override
|
||||||
|
String get name;
|
||||||
|
@override
|
||||||
|
String get description;
|
||||||
|
@override
|
||||||
|
String get businessType;
|
||||||
|
@override
|
||||||
|
Map<String, dynamic> get metadata;
|
||||||
|
@override
|
||||||
|
DateTime? get createdAt;
|
||||||
|
@override
|
||||||
|
DateTime? get updatedAt;
|
||||||
|
|
||||||
|
/// Create a copy of Category
|
||||||
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
|
@override
|
||||||
|
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||||
|
_$$CategoryImplCopyWith<_$CategoryImpl> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
mixin _$CategoryFailure {
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult when<TResult extends Object?>({
|
||||||
|
required TResult Function(ApiFailure failure) serverError,
|
||||||
|
required TResult Function() unexpectedError,
|
||||||
|
required TResult Function() empty,
|
||||||
|
required TResult Function(String erroMessage) dynamicErrorMessage,
|
||||||
|
}) => throw _privateConstructorUsedError;
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult? whenOrNull<TResult extends Object?>({
|
||||||
|
TResult? Function(ApiFailure failure)? serverError,
|
||||||
|
TResult? Function()? unexpectedError,
|
||||||
|
TResult? Function()? empty,
|
||||||
|
TResult? Function(String erroMessage)? dynamicErrorMessage,
|
||||||
|
}) => throw _privateConstructorUsedError;
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeWhen<TResult extends Object?>({
|
||||||
|
TResult Function(ApiFailure failure)? serverError,
|
||||||
|
TResult Function()? unexpectedError,
|
||||||
|
TResult Function()? empty,
|
||||||
|
TResult Function(String erroMessage)? dynamicErrorMessage,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) => throw _privateConstructorUsedError;
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult map<TResult extends Object?>({
|
||||||
|
required TResult Function(_ServerError value) serverError,
|
||||||
|
required TResult Function(_UnexpectedError value) unexpectedError,
|
||||||
|
required TResult Function(_Empty value) empty,
|
||||||
|
required TResult Function(_DynamicErrorMessage value) dynamicErrorMessage,
|
||||||
|
}) => throw _privateConstructorUsedError;
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult? mapOrNull<TResult extends Object?>({
|
||||||
|
TResult? Function(_ServerError value)? serverError,
|
||||||
|
TResult? Function(_UnexpectedError value)? unexpectedError,
|
||||||
|
TResult? Function(_Empty value)? empty,
|
||||||
|
TResult? Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||||
|
}) => throw _privateConstructorUsedError;
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeMap<TResult extends Object?>({
|
||||||
|
TResult Function(_ServerError value)? serverError,
|
||||||
|
TResult Function(_UnexpectedError value)? unexpectedError,
|
||||||
|
TResult Function(_Empty value)? empty,
|
||||||
|
TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) => throw _privateConstructorUsedError;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class $CategoryFailureCopyWith<$Res> {
|
||||||
|
factory $CategoryFailureCopyWith(
|
||||||
|
CategoryFailure value,
|
||||||
|
$Res Function(CategoryFailure) then,
|
||||||
|
) = _$CategoryFailureCopyWithImpl<$Res, CategoryFailure>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class _$CategoryFailureCopyWithImpl<$Res, $Val extends CategoryFailure>
|
||||||
|
implements $CategoryFailureCopyWith<$Res> {
|
||||||
|
_$CategoryFailureCopyWithImpl(this._value, this._then);
|
||||||
|
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Val _value;
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Res Function($Val) _then;
|
||||||
|
|
||||||
|
/// Create a copy of CategoryFailure
|
||||||
|
/// 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 _$CategoryFailureCopyWithImpl<$Res, _$ServerErrorImpl>
|
||||||
|
implements _$$ServerErrorImplCopyWith<$Res> {
|
||||||
|
__$$ServerErrorImplCopyWithImpl(
|
||||||
|
_$ServerErrorImpl _value,
|
||||||
|
$Res Function(_$ServerErrorImpl) _then,
|
||||||
|
) : super(_value, _then);
|
||||||
|
|
||||||
|
/// Create a copy of CategoryFailure
|
||||||
|
/// 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 CategoryFailure
|
||||||
|
/// 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 'CategoryFailure.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 CategoryFailure
|
||||||
|
/// 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<TResult extends Object?>({
|
||||||
|
required TResult Function(ApiFailure failure) serverError,
|
||||||
|
required TResult Function() unexpectedError,
|
||||||
|
required TResult Function() empty,
|
||||||
|
required TResult Function(String erroMessage) dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return serverError(failure);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult? whenOrNull<TResult extends Object?>({
|
||||||
|
TResult? Function(ApiFailure failure)? serverError,
|
||||||
|
TResult? Function()? unexpectedError,
|
||||||
|
TResult? Function()? empty,
|
||||||
|
TResult? Function(String erroMessage)? dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return serverError?.call(failure);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeWhen<TResult extends Object?>({
|
||||||
|
TResult Function(ApiFailure failure)? serverError,
|
||||||
|
TResult Function()? unexpectedError,
|
||||||
|
TResult Function()? empty,
|
||||||
|
TResult Function(String erroMessage)? dynamicErrorMessage,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) {
|
||||||
|
if (serverError != null) {
|
||||||
|
return serverError(failure);
|
||||||
|
}
|
||||||
|
return orElse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult map<TResult extends Object?>({
|
||||||
|
required TResult Function(_ServerError value) serverError,
|
||||||
|
required TResult Function(_UnexpectedError value) unexpectedError,
|
||||||
|
required TResult Function(_Empty value) empty,
|
||||||
|
required TResult Function(_DynamicErrorMessage value) dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return serverError(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult? mapOrNull<TResult extends Object?>({
|
||||||
|
TResult? Function(_ServerError value)? serverError,
|
||||||
|
TResult? Function(_UnexpectedError value)? unexpectedError,
|
||||||
|
TResult? Function(_Empty value)? empty,
|
||||||
|
TResult? Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return serverError?.call(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeMap<TResult extends Object?>({
|
||||||
|
TResult Function(_ServerError value)? serverError,
|
||||||
|
TResult Function(_UnexpectedError value)? unexpectedError,
|
||||||
|
TResult Function(_Empty value)? empty,
|
||||||
|
TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) {
|
||||||
|
if (serverError != null) {
|
||||||
|
return serverError(this);
|
||||||
|
}
|
||||||
|
return orElse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class _ServerError implements CategoryFailure {
|
||||||
|
const factory _ServerError(final ApiFailure failure) = _$ServerErrorImpl;
|
||||||
|
|
||||||
|
ApiFailure get failure;
|
||||||
|
|
||||||
|
/// Create a copy of CategoryFailure
|
||||||
|
/// 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 _$CategoryFailureCopyWithImpl<$Res, _$UnexpectedErrorImpl>
|
||||||
|
implements _$$UnexpectedErrorImplCopyWith<$Res> {
|
||||||
|
__$$UnexpectedErrorImplCopyWithImpl(
|
||||||
|
_$UnexpectedErrorImpl _value,
|
||||||
|
$Res Function(_$UnexpectedErrorImpl) _then,
|
||||||
|
) : super(_value, _then);
|
||||||
|
|
||||||
|
/// Create a copy of CategoryFailure
|
||||||
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
|
||||||
|
class _$UnexpectedErrorImpl implements _UnexpectedError {
|
||||||
|
const _$UnexpectedErrorImpl();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'CategoryFailure.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<TResult extends Object?>({
|
||||||
|
required TResult Function(ApiFailure failure) serverError,
|
||||||
|
required TResult Function() unexpectedError,
|
||||||
|
required TResult Function() empty,
|
||||||
|
required TResult Function(String erroMessage) dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return unexpectedError();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult? whenOrNull<TResult extends Object?>({
|
||||||
|
TResult? Function(ApiFailure failure)? serverError,
|
||||||
|
TResult? Function()? unexpectedError,
|
||||||
|
TResult? Function()? empty,
|
||||||
|
TResult? Function(String erroMessage)? dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return unexpectedError?.call();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeWhen<TResult extends Object?>({
|
||||||
|
TResult Function(ApiFailure failure)? serverError,
|
||||||
|
TResult Function()? unexpectedError,
|
||||||
|
TResult Function()? empty,
|
||||||
|
TResult Function(String erroMessage)? dynamicErrorMessage,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) {
|
||||||
|
if (unexpectedError != null) {
|
||||||
|
return unexpectedError();
|
||||||
|
}
|
||||||
|
return orElse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult map<TResult extends Object?>({
|
||||||
|
required TResult Function(_ServerError value) serverError,
|
||||||
|
required TResult Function(_UnexpectedError value) unexpectedError,
|
||||||
|
required TResult Function(_Empty value) empty,
|
||||||
|
required TResult Function(_DynamicErrorMessage value) dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return unexpectedError(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult? mapOrNull<TResult extends Object?>({
|
||||||
|
TResult? Function(_ServerError value)? serverError,
|
||||||
|
TResult? Function(_UnexpectedError value)? unexpectedError,
|
||||||
|
TResult? Function(_Empty value)? empty,
|
||||||
|
TResult? Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return unexpectedError?.call(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeMap<TResult extends Object?>({
|
||||||
|
TResult Function(_ServerError value)? serverError,
|
||||||
|
TResult Function(_UnexpectedError value)? unexpectedError,
|
||||||
|
TResult Function(_Empty value)? empty,
|
||||||
|
TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) {
|
||||||
|
if (unexpectedError != null) {
|
||||||
|
return unexpectedError(this);
|
||||||
|
}
|
||||||
|
return orElse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class _UnexpectedError implements CategoryFailure {
|
||||||
|
const factory _UnexpectedError() = _$UnexpectedErrorImpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class _$$EmptyImplCopyWith<$Res> {
|
||||||
|
factory _$$EmptyImplCopyWith(
|
||||||
|
_$EmptyImpl value,
|
||||||
|
$Res Function(_$EmptyImpl) then,
|
||||||
|
) = __$$EmptyImplCopyWithImpl<$Res>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class __$$EmptyImplCopyWithImpl<$Res>
|
||||||
|
extends _$CategoryFailureCopyWithImpl<$Res, _$EmptyImpl>
|
||||||
|
implements _$$EmptyImplCopyWith<$Res> {
|
||||||
|
__$$EmptyImplCopyWithImpl(
|
||||||
|
_$EmptyImpl _value,
|
||||||
|
$Res Function(_$EmptyImpl) _then,
|
||||||
|
) : super(_value, _then);
|
||||||
|
|
||||||
|
/// Create a copy of CategoryFailure
|
||||||
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
|
||||||
|
class _$EmptyImpl implements _Empty {
|
||||||
|
const _$EmptyImpl();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'CategoryFailure.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<TResult extends Object?>({
|
||||||
|
required TResult Function(ApiFailure failure) serverError,
|
||||||
|
required TResult Function() unexpectedError,
|
||||||
|
required TResult Function() empty,
|
||||||
|
required TResult Function(String erroMessage) dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult? whenOrNull<TResult extends Object?>({
|
||||||
|
TResult? Function(ApiFailure failure)? serverError,
|
||||||
|
TResult? Function()? unexpectedError,
|
||||||
|
TResult? Function()? empty,
|
||||||
|
TResult? Function(String erroMessage)? dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return empty?.call();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeWhen<TResult extends Object?>({
|
||||||
|
TResult Function(ApiFailure failure)? serverError,
|
||||||
|
TResult Function()? unexpectedError,
|
||||||
|
TResult Function()? empty,
|
||||||
|
TResult Function(String erroMessage)? dynamicErrorMessage,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) {
|
||||||
|
if (empty != null) {
|
||||||
|
return empty();
|
||||||
|
}
|
||||||
|
return orElse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult map<TResult extends Object?>({
|
||||||
|
required TResult Function(_ServerError value) serverError,
|
||||||
|
required TResult Function(_UnexpectedError value) unexpectedError,
|
||||||
|
required TResult Function(_Empty value) empty,
|
||||||
|
required TResult Function(_DynamicErrorMessage value) dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return empty(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult? mapOrNull<TResult extends Object?>({
|
||||||
|
TResult? Function(_ServerError value)? serverError,
|
||||||
|
TResult? Function(_UnexpectedError value)? unexpectedError,
|
||||||
|
TResult? Function(_Empty value)? empty,
|
||||||
|
TResult? Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return empty?.call(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeMap<TResult extends Object?>({
|
||||||
|
TResult Function(_ServerError value)? serverError,
|
||||||
|
TResult Function(_UnexpectedError value)? unexpectedError,
|
||||||
|
TResult Function(_Empty value)? empty,
|
||||||
|
TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) {
|
||||||
|
if (empty != null) {
|
||||||
|
return empty(this);
|
||||||
|
}
|
||||||
|
return orElse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class _Empty implements CategoryFailure {
|
||||||
|
const factory _Empty() = _$EmptyImpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class _$$DynamicErrorMessageImplCopyWith<$Res> {
|
||||||
|
factory _$$DynamicErrorMessageImplCopyWith(
|
||||||
|
_$DynamicErrorMessageImpl value,
|
||||||
|
$Res Function(_$DynamicErrorMessageImpl) then,
|
||||||
|
) = __$$DynamicErrorMessageImplCopyWithImpl<$Res>;
|
||||||
|
@useResult
|
||||||
|
$Res call({String erroMessage});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class __$$DynamicErrorMessageImplCopyWithImpl<$Res>
|
||||||
|
extends _$CategoryFailureCopyWithImpl<$Res, _$DynamicErrorMessageImpl>
|
||||||
|
implements _$$DynamicErrorMessageImplCopyWith<$Res> {
|
||||||
|
__$$DynamicErrorMessageImplCopyWithImpl(
|
||||||
|
_$DynamicErrorMessageImpl _value,
|
||||||
|
$Res Function(_$DynamicErrorMessageImpl) _then,
|
||||||
|
) : super(_value, _then);
|
||||||
|
|
||||||
|
/// Create a copy of CategoryFailure
|
||||||
|
/// 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 'CategoryFailure.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 CategoryFailure
|
||||||
|
/// 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<TResult extends Object?>({
|
||||||
|
required TResult Function(ApiFailure failure) serverError,
|
||||||
|
required TResult Function() unexpectedError,
|
||||||
|
required TResult Function() empty,
|
||||||
|
required TResult Function(String erroMessage) dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return dynamicErrorMessage(erroMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult? whenOrNull<TResult extends Object?>({
|
||||||
|
TResult? Function(ApiFailure failure)? serverError,
|
||||||
|
TResult? Function()? unexpectedError,
|
||||||
|
TResult? Function()? empty,
|
||||||
|
TResult? Function(String erroMessage)? dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return dynamicErrorMessage?.call(erroMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeWhen<TResult extends Object?>({
|
||||||
|
TResult Function(ApiFailure failure)? serverError,
|
||||||
|
TResult Function()? unexpectedError,
|
||||||
|
TResult Function()? empty,
|
||||||
|
TResult Function(String erroMessage)? dynamicErrorMessage,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) {
|
||||||
|
if (dynamicErrorMessage != null) {
|
||||||
|
return dynamicErrorMessage(erroMessage);
|
||||||
|
}
|
||||||
|
return orElse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult map<TResult extends Object?>({
|
||||||
|
required TResult Function(_ServerError value) serverError,
|
||||||
|
required TResult Function(_UnexpectedError value) unexpectedError,
|
||||||
|
required TResult Function(_Empty value) empty,
|
||||||
|
required TResult Function(_DynamicErrorMessage value) dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return dynamicErrorMessage(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult? mapOrNull<TResult extends Object?>({
|
||||||
|
TResult? Function(_ServerError value)? serverError,
|
||||||
|
TResult? Function(_UnexpectedError value)? unexpectedError,
|
||||||
|
TResult? Function(_Empty value)? empty,
|
||||||
|
TResult? Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||||
|
}) {
|
||||||
|
return dynamicErrorMessage?.call(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@optionalTypeArgs
|
||||||
|
TResult maybeMap<TResult extends Object?>({
|
||||||
|
TResult Function(_ServerError value)? serverError,
|
||||||
|
TResult Function(_UnexpectedError value)? unexpectedError,
|
||||||
|
TResult Function(_Empty value)? empty,
|
||||||
|
TResult Function(_DynamicErrorMessage value)? dynamicErrorMessage,
|
||||||
|
required TResult orElse(),
|
||||||
|
}) {
|
||||||
|
if (dynamicErrorMessage != null) {
|
||||||
|
return dynamicErrorMessage(this);
|
||||||
|
}
|
||||||
|
return orElse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class _DynamicErrorMessage implements CategoryFailure {
|
||||||
|
const factory _DynamicErrorMessage(final String erroMessage) =
|
||||||
|
_$DynamicErrorMessageImpl;
|
||||||
|
|
||||||
|
String get erroMessage;
|
||||||
|
|
||||||
|
/// Create a copy of CategoryFailure
|
||||||
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
|
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||||
|
_$$DynamicErrorMessageImplCopyWith<_$DynamicErrorMessageImpl> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
||||||
33
lib/domain/category/entities/category_entity.dart
Normal file
33
lib/domain/category/entities/category_entity.dart
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
part of '../category.dart';
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
class Category with _$Category {
|
||||||
|
const factory Category({
|
||||||
|
required String id,
|
||||||
|
required String organizationId,
|
||||||
|
required String name,
|
||||||
|
required String description,
|
||||||
|
required String businessType,
|
||||||
|
required Map<String, dynamic> metadata,
|
||||||
|
DateTime? createdAt,
|
||||||
|
DateTime? updatedAt,
|
||||||
|
}) = _Category;
|
||||||
|
|
||||||
|
factory Category.empty() => const Category(
|
||||||
|
id: '',
|
||||||
|
organizationId: '',
|
||||||
|
name: '',
|
||||||
|
description: '',
|
||||||
|
businessType: '',
|
||||||
|
metadata: {},
|
||||||
|
);
|
||||||
|
|
||||||
|
factory Category.addAllData() => Category(
|
||||||
|
id: 'all',
|
||||||
|
organizationId: '',
|
||||||
|
name: 'Semua',
|
||||||
|
description: '',
|
||||||
|
businessType: '',
|
||||||
|
metadata: {},
|
||||||
|
);
|
||||||
|
}
|
||||||
10
lib/domain/category/failures/category_failure.dart
Normal file
10
lib/domain/category/failures/category_failure.dart
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
part of '../category.dart';
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
sealed class CategoryFailure with _$CategoryFailure {
|
||||||
|
const factory CategoryFailure.serverError(ApiFailure failure) = _ServerError;
|
||||||
|
const factory CategoryFailure.unexpectedError() = _UnexpectedError;
|
||||||
|
const factory CategoryFailure.empty() = _Empty;
|
||||||
|
const factory CategoryFailure.dynamicErrorMessage(String erroMessage) =
|
||||||
|
_DynamicErrorMessage;
|
||||||
|
}
|
||||||
9
lib/domain/category/repositories/i_auth_repository.dart
Normal file
9
lib/domain/category/repositories/i_auth_repository.dart
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
part of '../category.dart';
|
||||||
|
|
||||||
|
abstract class ICategoryRepository {
|
||||||
|
Future<Either<CategoryFailure, List<Category>>> get({
|
||||||
|
int page = 1,
|
||||||
|
int limit = 20,
|
||||||
|
bool isActive = true,
|
||||||
|
});
|
||||||
|
}
|
||||||
8
lib/infrastructure/category/category_dtos.dart
Normal file
8
lib/infrastructure/category/category_dtos.dart
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||||
|
|
||||||
|
import '../../domain/category/category.dart';
|
||||||
|
|
||||||
|
part 'category_dtos.freezed.dart';
|
||||||
|
part 'category_dtos.g.dart';
|
||||||
|
|
||||||
|
part 'dto/category_dto.dart';
|
||||||
368
lib/infrastructure/category/category_dtos.freezed.dart
Normal file
368
lib/infrastructure/category/category_dtos.freezed.dart
Normal file
@ -0,0 +1,368 @@
|
|||||||
|
// 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 'category_dtos.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',
|
||||||
|
);
|
||||||
|
|
||||||
|
CategoryDto _$CategoryDtoFromJson(Map<String, dynamic> json) {
|
||||||
|
return _CategoryDto.fromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
mixin _$CategoryDto {
|
||||||
|
@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: 'description')
|
||||||
|
String? get description => throw _privateConstructorUsedError;
|
||||||
|
@JsonKey(name: 'business_type')
|
||||||
|
String? get businessType => throw _privateConstructorUsedError;
|
||||||
|
@JsonKey(name: 'metadata')
|
||||||
|
Map<String, dynamic>? get metadata => throw _privateConstructorUsedError;
|
||||||
|
@JsonKey(name: 'created_at')
|
||||||
|
DateTime? get createdAt => throw _privateConstructorUsedError;
|
||||||
|
@JsonKey(name: 'updated_at')
|
||||||
|
DateTime? get updatedAt => throw _privateConstructorUsedError;
|
||||||
|
|
||||||
|
/// Serializes this CategoryDto to a JSON map.
|
||||||
|
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||||
|
|
||||||
|
/// Create a copy of CategoryDto
|
||||||
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
|
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||||
|
$CategoryDtoCopyWith<CategoryDto> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class $CategoryDtoCopyWith<$Res> {
|
||||||
|
factory $CategoryDtoCopyWith(
|
||||||
|
CategoryDto value,
|
||||||
|
$Res Function(CategoryDto) then,
|
||||||
|
) = _$CategoryDtoCopyWithImpl<$Res, CategoryDto>;
|
||||||
|
@useResult
|
||||||
|
$Res call({
|
||||||
|
@JsonKey(name: 'id') String? id,
|
||||||
|
@JsonKey(name: 'organization_id') String? organizationId,
|
||||||
|
@JsonKey(name: 'name') String? name,
|
||||||
|
@JsonKey(name: 'description') String? description,
|
||||||
|
@JsonKey(name: 'business_type') String? businessType,
|
||||||
|
@JsonKey(name: 'metadata') Map<String, dynamic>? metadata,
|
||||||
|
@JsonKey(name: 'created_at') DateTime? createdAt,
|
||||||
|
@JsonKey(name: 'updated_at') DateTime? updatedAt,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class _$CategoryDtoCopyWithImpl<$Res, $Val extends CategoryDto>
|
||||||
|
implements $CategoryDtoCopyWith<$Res> {
|
||||||
|
_$CategoryDtoCopyWithImpl(this._value, this._then);
|
||||||
|
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Val _value;
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Res Function($Val) _then;
|
||||||
|
|
||||||
|
/// Create a copy of CategoryDto
|
||||||
|
/// 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? description = freezed,
|
||||||
|
Object? businessType = freezed,
|
||||||
|
Object? metadata = 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?,
|
||||||
|
description: freezed == description
|
||||||
|
? _value.description
|
||||||
|
: description // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String?,
|
||||||
|
businessType: freezed == businessType
|
||||||
|
? _value.businessType
|
||||||
|
: businessType // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String?,
|
||||||
|
metadata: freezed == metadata
|
||||||
|
? _value.metadata
|
||||||
|
: metadata // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Map<String, dynamic>?,
|
||||||
|
createdAt: freezed == createdAt
|
||||||
|
? _value.createdAt
|
||||||
|
: createdAt // ignore: cast_nullable_to_non_nullable
|
||||||
|
as DateTime?,
|
||||||
|
updatedAt: freezed == updatedAt
|
||||||
|
? _value.updatedAt
|
||||||
|
: updatedAt // ignore: cast_nullable_to_non_nullable
|
||||||
|
as DateTime?,
|
||||||
|
)
|
||||||
|
as $Val,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class _$$CategoryDtoImplCopyWith<$Res>
|
||||||
|
implements $CategoryDtoCopyWith<$Res> {
|
||||||
|
factory _$$CategoryDtoImplCopyWith(
|
||||||
|
_$CategoryDtoImpl value,
|
||||||
|
$Res Function(_$CategoryDtoImpl) then,
|
||||||
|
) = __$$CategoryDtoImplCopyWithImpl<$Res>;
|
||||||
|
@override
|
||||||
|
@useResult
|
||||||
|
$Res call({
|
||||||
|
@JsonKey(name: 'id') String? id,
|
||||||
|
@JsonKey(name: 'organization_id') String? organizationId,
|
||||||
|
@JsonKey(name: 'name') String? name,
|
||||||
|
@JsonKey(name: 'description') String? description,
|
||||||
|
@JsonKey(name: 'business_type') String? businessType,
|
||||||
|
@JsonKey(name: 'metadata') Map<String, dynamic>? metadata,
|
||||||
|
@JsonKey(name: 'created_at') DateTime? createdAt,
|
||||||
|
@JsonKey(name: 'updated_at') DateTime? updatedAt,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class __$$CategoryDtoImplCopyWithImpl<$Res>
|
||||||
|
extends _$CategoryDtoCopyWithImpl<$Res, _$CategoryDtoImpl>
|
||||||
|
implements _$$CategoryDtoImplCopyWith<$Res> {
|
||||||
|
__$$CategoryDtoImplCopyWithImpl(
|
||||||
|
_$CategoryDtoImpl _value,
|
||||||
|
$Res Function(_$CategoryDtoImpl) _then,
|
||||||
|
) : super(_value, _then);
|
||||||
|
|
||||||
|
/// Create a copy of CategoryDto
|
||||||
|
/// 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? description = freezed,
|
||||||
|
Object? businessType = freezed,
|
||||||
|
Object? metadata = freezed,
|
||||||
|
Object? createdAt = freezed,
|
||||||
|
Object? updatedAt = freezed,
|
||||||
|
}) {
|
||||||
|
return _then(
|
||||||
|
_$CategoryDtoImpl(
|
||||||
|
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?,
|
||||||
|
description: freezed == description
|
||||||
|
? _value.description
|
||||||
|
: description // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String?,
|
||||||
|
businessType: freezed == businessType
|
||||||
|
? _value.businessType
|
||||||
|
: businessType // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String?,
|
||||||
|
metadata: freezed == metadata
|
||||||
|
? _value._metadata
|
||||||
|
: metadata // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Map<String, dynamic>?,
|
||||||
|
createdAt: freezed == createdAt
|
||||||
|
? _value.createdAt
|
||||||
|
: createdAt // ignore: cast_nullable_to_non_nullable
|
||||||
|
as DateTime?,
|
||||||
|
updatedAt: freezed == updatedAt
|
||||||
|
? _value.updatedAt
|
||||||
|
: updatedAt // ignore: cast_nullable_to_non_nullable
|
||||||
|
as DateTime?,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
@JsonSerializable()
|
||||||
|
class _$CategoryDtoImpl extends _CategoryDto {
|
||||||
|
const _$CategoryDtoImpl({
|
||||||
|
@JsonKey(name: 'id') this.id,
|
||||||
|
@JsonKey(name: 'organization_id') this.organizationId,
|
||||||
|
@JsonKey(name: 'name') this.name,
|
||||||
|
@JsonKey(name: 'description') this.description,
|
||||||
|
@JsonKey(name: 'business_type') this.businessType,
|
||||||
|
@JsonKey(name: 'metadata') final Map<String, dynamic>? metadata,
|
||||||
|
@JsonKey(name: 'created_at') this.createdAt,
|
||||||
|
@JsonKey(name: 'updated_at') this.updatedAt,
|
||||||
|
}) : _metadata = metadata,
|
||||||
|
super._();
|
||||||
|
|
||||||
|
factory _$CategoryDtoImpl.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$$CategoryDtoImplFromJson(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: 'description')
|
||||||
|
final String? description;
|
||||||
|
@override
|
||||||
|
@JsonKey(name: 'business_type')
|
||||||
|
final String? businessType;
|
||||||
|
final Map<String, dynamic>? _metadata;
|
||||||
|
@override
|
||||||
|
@JsonKey(name: 'metadata')
|
||||||
|
Map<String, dynamic>? get metadata {
|
||||||
|
final value = _metadata;
|
||||||
|
if (value == null) return null;
|
||||||
|
if (_metadata is EqualUnmodifiableMapView) return _metadata;
|
||||||
|
// ignore: implicit_dynamic_type
|
||||||
|
return EqualUnmodifiableMapView(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@JsonKey(name: 'created_at')
|
||||||
|
final DateTime? createdAt;
|
||||||
|
@override
|
||||||
|
@JsonKey(name: 'updated_at')
|
||||||
|
final DateTime? updatedAt;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'CategoryDto(id: $id, organizationId: $organizationId, name: $name, description: $description, businessType: $businessType, metadata: $metadata, createdAt: $createdAt, updatedAt: $updatedAt)';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
return identical(this, other) ||
|
||||||
|
(other.runtimeType == runtimeType &&
|
||||||
|
other is _$CategoryDtoImpl &&
|
||||||
|
(identical(other.id, id) || other.id == id) &&
|
||||||
|
(identical(other.organizationId, organizationId) ||
|
||||||
|
other.organizationId == organizationId) &&
|
||||||
|
(identical(other.name, name) || other.name == name) &&
|
||||||
|
(identical(other.description, description) ||
|
||||||
|
other.description == description) &&
|
||||||
|
(identical(other.businessType, businessType) ||
|
||||||
|
other.businessType == businessType) &&
|
||||||
|
const DeepCollectionEquality().equals(other._metadata, _metadata) &&
|
||||||
|
(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,
|
||||||
|
description,
|
||||||
|
businessType,
|
||||||
|
const DeepCollectionEquality().hash(_metadata),
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Create a copy of CategoryDto
|
||||||
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
|
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||||
|
@override
|
||||||
|
@pragma('vm:prefer-inline')
|
||||||
|
_$$CategoryDtoImplCopyWith<_$CategoryDtoImpl> get copyWith =>
|
||||||
|
__$$CategoryDtoImplCopyWithImpl<_$CategoryDtoImpl>(this, _$identity);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return _$$CategoryDtoImplToJson(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class _CategoryDto extends CategoryDto {
|
||||||
|
const factory _CategoryDto({
|
||||||
|
@JsonKey(name: 'id') final String? id,
|
||||||
|
@JsonKey(name: 'organization_id') final String? organizationId,
|
||||||
|
@JsonKey(name: 'name') final String? name,
|
||||||
|
@JsonKey(name: 'description') final String? description,
|
||||||
|
@JsonKey(name: 'business_type') final String? businessType,
|
||||||
|
@JsonKey(name: 'metadata') final Map<String, dynamic>? metadata,
|
||||||
|
@JsonKey(name: 'created_at') final DateTime? createdAt,
|
||||||
|
@JsonKey(name: 'updated_at') final DateTime? updatedAt,
|
||||||
|
}) = _$CategoryDtoImpl;
|
||||||
|
const _CategoryDto._() : super._();
|
||||||
|
|
||||||
|
factory _CategoryDto.fromJson(Map<String, dynamic> json) =
|
||||||
|
_$CategoryDtoImpl.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: 'description')
|
||||||
|
String? get description;
|
||||||
|
@override
|
||||||
|
@JsonKey(name: 'business_type')
|
||||||
|
String? get businessType;
|
||||||
|
@override
|
||||||
|
@JsonKey(name: 'metadata')
|
||||||
|
Map<String, dynamic>? get metadata;
|
||||||
|
@override
|
||||||
|
@JsonKey(name: 'created_at')
|
||||||
|
DateTime? get createdAt;
|
||||||
|
@override
|
||||||
|
@JsonKey(name: 'updated_at')
|
||||||
|
DateTime? get updatedAt;
|
||||||
|
|
||||||
|
/// Create a copy of CategoryDto
|
||||||
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
|
@override
|
||||||
|
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||||
|
_$$CategoryDtoImplCopyWith<_$CategoryDtoImpl> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
||||||
35
lib/infrastructure/category/category_dtos.g.dart
Normal file
35
lib/infrastructure/category/category_dtos.g.dart
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'category_dtos.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonSerializableGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
_$CategoryDtoImpl _$$CategoryDtoImplFromJson(Map<String, dynamic> json) =>
|
||||||
|
_$CategoryDtoImpl(
|
||||||
|
id: json['id'] as String?,
|
||||||
|
organizationId: json['organization_id'] as String?,
|
||||||
|
name: json['name'] as String?,
|
||||||
|
description: json['description'] as String?,
|
||||||
|
businessType: json['business_type'] as String?,
|
||||||
|
metadata: json['metadata'] as Map<String, dynamic>?,
|
||||||
|
createdAt: json['created_at'] == null
|
||||||
|
? null
|
||||||
|
: DateTime.parse(json['created_at'] as String),
|
||||||
|
updatedAt: json['updated_at'] == null
|
||||||
|
? null
|
||||||
|
: DateTime.parse(json['updated_at'] as String),
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$$CategoryDtoImplToJson(_$CategoryDtoImpl instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'id': instance.id,
|
||||||
|
'organization_id': instance.organizationId,
|
||||||
|
'name': instance.name,
|
||||||
|
'description': instance.description,
|
||||||
|
'business_type': instance.businessType,
|
||||||
|
'metadata': instance.metadata,
|
||||||
|
'created_at': instance.createdAt?.toIso8601String(),
|
||||||
|
'updated_at': instance.updatedAt?.toIso8601String(),
|
||||||
|
};
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
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/url/api_path.dart';
|
||||||
|
import '../../../domain/category/category.dart';
|
||||||
|
import '../category_dtos.dart';
|
||||||
|
|
||||||
|
@injectable
|
||||||
|
class CategoryRemoteDataProvider {
|
||||||
|
final ApiClient _apiClient;
|
||||||
|
final String _logName = 'CategoryRemoteDataProvider';
|
||||||
|
|
||||||
|
CategoryRemoteDataProvider(this._apiClient);
|
||||||
|
|
||||||
|
Future<DC<CategoryFailure, List<CategoryDto>>> fetch({
|
||||||
|
int page = 1,
|
||||||
|
int limit = 20,
|
||||||
|
bool isActive = true,
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
|
final response = await _apiClient.get(
|
||||||
|
ApiPath.category,
|
||||||
|
params: {'page': page, 'limit': limit, 'is_active': isActive},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.data['data'] == null) {
|
||||||
|
return DC.error(CategoryFailure.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
final dto = (response.data['data']['categories'] as List)
|
||||||
|
.map((item) => CategoryDto.fromJson(item))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return DC.data(dto);
|
||||||
|
} on ApiFailure catch (e, s) {
|
||||||
|
log('fetchCategoryError', name: _logName, error: e, stackTrace: s);
|
||||||
|
return DC.error(CategoryFailure.serverError(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
31
lib/infrastructure/category/dto/category_dto.dart
Normal file
31
lib/infrastructure/category/dto/category_dto.dart
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
part of '../category_dtos.dart';
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
class CategoryDto with _$CategoryDto {
|
||||||
|
const CategoryDto._();
|
||||||
|
|
||||||
|
const factory CategoryDto({
|
||||||
|
@JsonKey(name: 'id') String? id,
|
||||||
|
@JsonKey(name: 'organization_id') String? organizationId,
|
||||||
|
@JsonKey(name: 'name') String? name,
|
||||||
|
@JsonKey(name: 'description') String? description,
|
||||||
|
@JsonKey(name: 'business_type') String? businessType,
|
||||||
|
@JsonKey(name: 'metadata') Map<String, dynamic>? metadata,
|
||||||
|
@JsonKey(name: 'created_at') DateTime? createdAt,
|
||||||
|
@JsonKey(name: 'updated_at') DateTime? updatedAt,
|
||||||
|
}) = _CategoryDto;
|
||||||
|
|
||||||
|
factory CategoryDto.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$CategoryDtoFromJson(json);
|
||||||
|
|
||||||
|
Category toDomain() => Category(
|
||||||
|
id: id ?? '',
|
||||||
|
organizationId: organizationId ?? '',
|
||||||
|
name: name ?? '',
|
||||||
|
description: description ?? '',
|
||||||
|
businessType: businessType ?? '',
|
||||||
|
metadata: metadata ?? {},
|
||||||
|
createdAt: createdAt,
|
||||||
|
updatedAt: updatedAt,
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
|
import 'package:dartz/dartz.dart';
|
||||||
|
import 'package:injectable/injectable.dart';
|
||||||
|
|
||||||
|
import '../../../domain/category/category.dart';
|
||||||
|
import '../datasource/remote_data_provider.dart';
|
||||||
|
|
||||||
|
@Injectable(as: ICategoryRepository)
|
||||||
|
class CategoryRepository implements ICategoryRepository {
|
||||||
|
final CategoryRemoteDataProvider _dataProvider;
|
||||||
|
final String _logName = 'CategoryRepository';
|
||||||
|
|
||||||
|
CategoryRepository(this._dataProvider);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Either<CategoryFailure, List<Category>>> get({
|
||||||
|
int page = 1,
|
||||||
|
int limit = 20,
|
||||||
|
bool isActive = true,
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
|
final result = await _dataProvider.fetch(
|
||||||
|
page: page,
|
||||||
|
limit: limit,
|
||||||
|
isActive: isActive,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.hasError) {
|
||||||
|
return left(result.error!);
|
||||||
|
}
|
||||||
|
|
||||||
|
final auth = result.data!.map((e) => e.toDomain()).toList();
|
||||||
|
|
||||||
|
return right(auth);
|
||||||
|
} catch (e, s) {
|
||||||
|
log('getCategoryError', name: _logName, error: e, stackTrace: s);
|
||||||
|
return left(const CategoryFailure.unexpectedError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -14,6 +14,8 @@ import 'package:apskel_owner_flutter/application/auth/login_form/login_form_bloc
|
|||||||
as _i775;
|
as _i775;
|
||||||
import 'package:apskel_owner_flutter/application/auth/logout_form/logout_form_bloc.dart'
|
import 'package:apskel_owner_flutter/application/auth/logout_form/logout_form_bloc.dart'
|
||||||
as _i574;
|
as _i574;
|
||||||
|
import 'package:apskel_owner_flutter/application/category/category_loader/category_loader_bloc.dart'
|
||||||
|
as _i183;
|
||||||
import 'package:apskel_owner_flutter/application/language/language_bloc.dart'
|
import 'package:apskel_owner_flutter/application/language/language_bloc.dart'
|
||||||
as _i455;
|
as _i455;
|
||||||
import 'package:apskel_owner_flutter/application/sales/sales_loader/sales_loader_bloc.dart'
|
import 'package:apskel_owner_flutter/application/sales/sales_loader/sales_loader_bloc.dart'
|
||||||
@ -30,6 +32,7 @@ import 'package:apskel_owner_flutter/common/network/network_client.dart'
|
|||||||
import 'package:apskel_owner_flutter/domain/analytic/repositories/i_analytic_repository.dart'
|
import 'package:apskel_owner_flutter/domain/analytic/repositories/i_analytic_repository.dart'
|
||||||
as _i477;
|
as _i477;
|
||||||
import 'package:apskel_owner_flutter/domain/auth/auth.dart' as _i49;
|
import 'package:apskel_owner_flutter/domain/auth/auth.dart' as _i49;
|
||||||
|
import 'package:apskel_owner_flutter/domain/category/category.dart' as _i1020;
|
||||||
import 'package:apskel_owner_flutter/env.dart' as _i6;
|
import 'package:apskel_owner_flutter/env.dart' as _i6;
|
||||||
import 'package:apskel_owner_flutter/infrastructure/analytic/datasource/remote_data_provider.dart'
|
import 'package:apskel_owner_flutter/infrastructure/analytic/datasource/remote_data_provider.dart'
|
||||||
as _i866;
|
as _i866;
|
||||||
@ -41,6 +44,10 @@ import 'package:apskel_owner_flutter/infrastructure/auth/datasources/remote_data
|
|||||||
as _i17;
|
as _i17;
|
||||||
import 'package:apskel_owner_flutter/infrastructure/auth/repositories/auth_repository.dart'
|
import 'package:apskel_owner_flutter/infrastructure/auth/repositories/auth_repository.dart'
|
||||||
as _i1035;
|
as _i1035;
|
||||||
|
import 'package:apskel_owner_flutter/infrastructure/category/datasource/remote_data_provider.dart'
|
||||||
|
as _i333;
|
||||||
|
import 'package:apskel_owner_flutter/infrastructure/category/repositories/category_repository.dart'
|
||||||
|
as _i869;
|
||||||
import 'package:apskel_owner_flutter/presentation/router/app_router.dart'
|
import 'package:apskel_owner_flutter/presentation/router/app_router.dart'
|
||||||
as _i258;
|
as _i258;
|
||||||
import 'package:connectivity_plus/connectivity_plus.dart' as _i895;
|
import 'package:connectivity_plus/connectivity_plus.dart' as _i895;
|
||||||
@ -100,6 +107,9 @@ extension GetItInjectableX on _i174.GetIt {
|
|||||||
gh.factory<_i866.AnalyticRemoteDataProvider>(
|
gh.factory<_i866.AnalyticRemoteDataProvider>(
|
||||||
() => _i866.AnalyticRemoteDataProvider(gh<_i115.ApiClient>()),
|
() => _i866.AnalyticRemoteDataProvider(gh<_i115.ApiClient>()),
|
||||||
);
|
);
|
||||||
|
gh.factory<_i333.CategoryRemoteDataProvider>(
|
||||||
|
() => _i333.CategoryRemoteDataProvider(gh<_i115.ApiClient>()),
|
||||||
|
);
|
||||||
gh.factory<_i477.IAnalyticRepository>(
|
gh.factory<_i477.IAnalyticRepository>(
|
||||||
() => _i393.AnalyticRepository(gh<_i866.AnalyticRemoteDataProvider>()),
|
() => _i393.AnalyticRepository(gh<_i866.AnalyticRemoteDataProvider>()),
|
||||||
);
|
);
|
||||||
@ -109,6 +119,12 @@ extension GetItInjectableX on _i174.GetIt {
|
|||||||
gh<_i17.AuthRemoteDataProvider>(),
|
gh<_i17.AuthRemoteDataProvider>(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
gh.factory<_i1020.ICategoryRepository>(
|
||||||
|
() => _i869.CategoryRepository(gh<_i333.CategoryRemoteDataProvider>()),
|
||||||
|
);
|
||||||
|
gh.factory<_i183.CategoryLoaderBloc>(
|
||||||
|
() => _i183.CategoryLoaderBloc(gh<_i1020.ICategoryRepository>()),
|
||||||
|
);
|
||||||
gh.factory<_i882.SalesLoaderBloc>(
|
gh.factory<_i882.SalesLoaderBloc>(
|
||||||
() => _i882.SalesLoaderBloc(gh<_i477.IAnalyticRepository>()),
|
() => _i882.SalesLoaderBloc(gh<_i477.IAnalyticRepository>()),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,27 +1,37 @@
|
|||||||
import 'package:auto_route/auto_route.dart';
|
import 'package:auto_route/auto_route.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:line_icons/line_icons.dart';
|
import 'package:line_icons/line_icons.dart';
|
||||||
|
|
||||||
|
import '../../../application/category/category_loader/category_loader_bloc.dart';
|
||||||
import '../../../common/theme/theme.dart';
|
import '../../../common/theme/theme.dart';
|
||||||
|
import '../../../domain/category/category.dart';
|
||||||
|
import '../../../injection.dart';
|
||||||
import '../../components/appbar/appbar.dart';
|
import '../../components/appbar/appbar.dart';
|
||||||
import '../../components/button/button.dart';
|
import '../../components/button/button.dart';
|
||||||
import 'widgets/category_delegate.dart';
|
import 'widgets/category_delegate.dart';
|
||||||
import 'widgets/product_tile.dart';
|
import 'widgets/product_tile.dart';
|
||||||
|
|
||||||
@RoutePage()
|
@RoutePage()
|
||||||
class ProductPage extends StatefulWidget {
|
class ProductPage extends StatefulWidget implements AutoRouteWrapper {
|
||||||
const ProductPage({super.key});
|
const ProductPage({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ProductPage> createState() => _ProductPageState();
|
State<ProductPage> createState() => _ProductPageState();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget wrappedRoute(BuildContext context) => BlocProvider(
|
||||||
|
create: (context) =>
|
||||||
|
getIt<CategoryLoaderBloc>()..add(CategoryLoaderEvent.fetched()),
|
||||||
|
child: this,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ViewType { grid, list }
|
enum ViewType { grid, list }
|
||||||
|
|
||||||
class _ProductPageState extends State<ProductPage>
|
class _ProductPageState extends State<ProductPage>
|
||||||
with TickerProviderStateMixin {
|
with TickerProviderStateMixin {
|
||||||
String selectedCategory = 'Semua';
|
Category selectedCategory = Category.addAllData();
|
||||||
List<String> categories = ['Semua', 'Makanan', 'Minuman', 'Snack', 'Dessert'];
|
|
||||||
ViewType currentViewType = ViewType.grid;
|
ViewType currentViewType = ViewType.grid;
|
||||||
|
|
||||||
// Sample product data
|
// Sample product data
|
||||||
@ -121,7 +131,8 @@ class _ProductPageState extends State<ProductPage>
|
|||||||
List<Product> get filteredProducts {
|
List<Product> get filteredProducts {
|
||||||
return products.where((product) {
|
return products.where((product) {
|
||||||
bool matchesCategory =
|
bool matchesCategory =
|
||||||
selectedCategory == 'Semua' || product.category == selectedCategory;
|
selectedCategory.name == 'Semua' ||
|
||||||
|
product.category == selectedCategory.id;
|
||||||
return matchesCategory;
|
return matchesCategory;
|
||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
@ -173,10 +184,12 @@ class _ProductPageState extends State<ProductPage>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildCategoryFilter() {
|
Widget _buildCategoryFilter() {
|
||||||
|
return BlocBuilder<CategoryLoaderBloc, CategoryLoaderState>(
|
||||||
|
builder: (context, state) {
|
||||||
return SliverPersistentHeader(
|
return SliverPersistentHeader(
|
||||||
pinned: true,
|
pinned: true,
|
||||||
delegate: ProductCategoryHeaderDelegate(
|
delegate: ProductCategoryHeaderDelegate(
|
||||||
categories: categories,
|
categories: state.categories,
|
||||||
selectedCategory: selectedCategory,
|
selectedCategory: selectedCategory,
|
||||||
onCategoryChanged: (category) {
|
onCategoryChanged: (category) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -185,6 +198,8 @@ class _ProductPageState extends State<ProductPage>
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildProductContent() {
|
Widget _buildProductContent() {
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../../../../common/theme/theme.dart';
|
import '../../../../common/theme/theme.dart';
|
||||||
|
import '../../../../domain/category/category.dart';
|
||||||
|
|
||||||
class ProductCategoryHeaderDelegate extends SliverPersistentHeaderDelegate {
|
class ProductCategoryHeaderDelegate extends SliverPersistentHeaderDelegate {
|
||||||
final List<String> categories;
|
final List<Category> categories;
|
||||||
final String selectedCategory;
|
final Category selectedCategory;
|
||||||
final ValueChanged<String> onCategoryChanged;
|
final ValueChanged<Category> onCategoryChanged;
|
||||||
|
|
||||||
ProductCategoryHeaderDelegate({
|
ProductCategoryHeaderDelegate({
|
||||||
required this.categories,
|
required this.categories,
|
||||||
@ -35,7 +36,7 @@ class ProductCategoryHeaderDelegate extends SliverPersistentHeaderDelegate {
|
|||||||
return Container(
|
return Container(
|
||||||
margin: const EdgeInsets.only(right: 12.0),
|
margin: const EdgeInsets.only(right: 12.0),
|
||||||
child: FilterChip(
|
child: FilterChip(
|
||||||
label: Text(category),
|
label: Text(category.name),
|
||||||
selected: isSelected,
|
selected: isSelected,
|
||||||
onSelected: (selected) => onCategoryChanged(category),
|
onSelected: (selected) => onCategoryChanged(category),
|
||||||
backgroundColor: AppColor.surface,
|
backgroundColor: AppColor.surface,
|
||||||
@ -64,6 +65,7 @@ class ProductCategoryHeaderDelegate extends SliverPersistentHeaderDelegate {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
bool shouldRebuild(ProductCategoryHeaderDelegate oldDelegate) {
|
bool shouldRebuild(ProductCategoryHeaderDelegate oldDelegate) {
|
||||||
return oldDelegate.selectedCategory != selectedCategory;
|
return oldDelegate.categories != categories ||
|
||||||
|
oldDelegate.selectedCategory != selectedCategory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user