price policy
This commit is contained in:
@@ -1,38 +1,54 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:worker/features/price_policy/data/datasources/price_policy_local_datasource.dart';
|
||||
import 'package:worker/core/network/dio_client.dart';
|
||||
import 'package:worker/features/price_policy/data/datasources/price_policy_remote_datasource.dart';
|
||||
import 'package:worker/features/price_policy/data/repositories/price_policy_repository_impl.dart';
|
||||
import 'package:worker/features/price_policy/domain/entities/price_document.dart';
|
||||
import 'package:worker/features/price_policy/domain/repositories/price_policy_repository.dart';
|
||||
|
||||
part 'price_documents_provider.g.dart';
|
||||
|
||||
/// Provider for local data source
|
||||
@riverpod
|
||||
PricePolicyLocalDataSource pricePolicyLocalDataSource(Ref ref) {
|
||||
return PricePolicyLocalDataSource();
|
||||
}
|
||||
|
||||
/// Provider for price policy repository
|
||||
@riverpod
|
||||
PricePolicyRepository pricePolicyRepository(Ref ref) {
|
||||
final localDataSource = ref.watch(pricePolicyLocalDataSourceProvider);
|
||||
|
||||
return PricePolicyRepositoryImpl(localDataSource: localDataSource);
|
||||
Future<PricePolicyRepository> pricePolicyRepository(Ref ref) async {
|
||||
final dioClient = await ref.watch(dioClientProvider.future);
|
||||
final remoteDataSource = PricePolicyRemoteDataSourceImpl(dioClient);
|
||||
return PricePolicyRepositoryImpl(remoteDataSource: remoteDataSource);
|
||||
}
|
||||
|
||||
/// Provider for all price policy documents
|
||||
@riverpod
|
||||
Future<List<PriceDocument>> priceDocuments(Ref ref) async {
|
||||
final repository = ref.watch(pricePolicyRepositoryProvider);
|
||||
final repository = await ref.watch(pricePolicyRepositoryProvider.future);
|
||||
return repository.getAllDocuments();
|
||||
}
|
||||
|
||||
/// Provider for filtered documents by category
|
||||
/// Provider for filtered documents by category with file path management
|
||||
@riverpod
|
||||
Future<List<PriceDocument>> filteredPriceDocuments(
|
||||
Ref ref,
|
||||
DocumentCategory category,
|
||||
) async {
|
||||
final repository = ref.watch(pricePolicyRepositoryProvider);
|
||||
return repository.getDocumentsByCategory(category);
|
||||
class FilteredPriceDocuments extends _$FilteredPriceDocuments {
|
||||
@override
|
||||
Future<List<PriceDocument>> build(DocumentCategory category) async {
|
||||
final repository = await ref.watch(pricePolicyRepositoryProvider.future);
|
||||
return repository.getDocumentsByCategory(category);
|
||||
}
|
||||
|
||||
/// Update a document's file path after download
|
||||
void updateDocumentFilePath(String documentTitle, String filePath) {
|
||||
state = state.whenData((documents) {
|
||||
return documents.map((doc) {
|
||||
if (doc.title == documentTitle) {
|
||||
return doc.copyWith(filePath: filePath);
|
||||
}
|
||||
return doc;
|
||||
}).toList();
|
||||
});
|
||||
}
|
||||
|
||||
/// Refresh documents
|
||||
Future<void> refresh() async {
|
||||
state = const AsyncValue.loading();
|
||||
state = await AsyncValue.guard(() async {
|
||||
final repository = await ref.read(pricePolicyRepositoryProvider.future);
|
||||
return repository.getDocumentsByCategory(category);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,60 +8,6 @@ part of 'price_documents_provider.dart';
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
/// Provider for local data source
|
||||
|
||||
@ProviderFor(pricePolicyLocalDataSource)
|
||||
const pricePolicyLocalDataSourceProvider =
|
||||
PricePolicyLocalDataSourceProvider._();
|
||||
|
||||
/// Provider for local data source
|
||||
|
||||
final class PricePolicyLocalDataSourceProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
PricePolicyLocalDataSource,
|
||||
PricePolicyLocalDataSource,
|
||||
PricePolicyLocalDataSource
|
||||
>
|
||||
with $Provider<PricePolicyLocalDataSource> {
|
||||
/// Provider for local data source
|
||||
const PricePolicyLocalDataSourceProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'pricePolicyLocalDataSourceProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$pricePolicyLocalDataSourceHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<PricePolicyLocalDataSource> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
PricePolicyLocalDataSource create(Ref ref) {
|
||||
return pricePolicyLocalDataSource(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(PricePolicyLocalDataSource value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<PricePolicyLocalDataSource>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$pricePolicyLocalDataSourceHash() =>
|
||||
r'dd1bee761fa7f050835508cf33bf34a788829483';
|
||||
|
||||
/// Provider for price policy repository
|
||||
|
||||
@ProviderFor(pricePolicyRepository)
|
||||
@@ -72,11 +18,13 @@ const pricePolicyRepositoryProvider = PricePolicyRepositoryProvider._();
|
||||
final class PricePolicyRepositoryProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
AsyncValue<PricePolicyRepository>,
|
||||
PricePolicyRepository,
|
||||
PricePolicyRepository,
|
||||
PricePolicyRepository
|
||||
FutureOr<PricePolicyRepository>
|
||||
>
|
||||
with $Provider<PricePolicyRepository> {
|
||||
with
|
||||
$FutureModifier<PricePolicyRepository>,
|
||||
$FutureProvider<PricePolicyRepository> {
|
||||
/// Provider for price policy repository
|
||||
const PricePolicyRepositoryProvider._()
|
||||
: super(
|
||||
@@ -94,26 +42,18 @@ final class PricePolicyRepositoryProvider
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<PricePolicyRepository> $createElement(
|
||||
$FutureProviderElement<PricePolicyRepository> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $ProviderElement(pointer);
|
||||
) => $FutureProviderElement(pointer);
|
||||
|
||||
@override
|
||||
PricePolicyRepository create(Ref ref) {
|
||||
FutureOr<PricePolicyRepository> create(Ref ref) {
|
||||
return pricePolicyRepository(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(PricePolicyRepository value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<PricePolicyRepository>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$pricePolicyRepositoryHash() =>
|
||||
r'296555a45936d8e43a28bf5add5e7db40495009c';
|
||||
r'35aa21067e77bbb6b91dd29c4772b1c6707be116';
|
||||
|
||||
/// Provider for all price policy documents
|
||||
|
||||
@@ -159,26 +99,18 @@ final class PriceDocumentsProvider
|
||||
}
|
||||
}
|
||||
|
||||
String _$priceDocumentsHash() => r'cf2ccf6bd9aaae0c56ab01529fd034a090d99263';
|
||||
String _$priceDocumentsHash() => r'dffe292742776681c22d0ccdb3e091491290057d';
|
||||
|
||||
/// Provider for filtered documents by category
|
||||
/// Provider for filtered documents by category with file path management
|
||||
|
||||
@ProviderFor(filteredPriceDocuments)
|
||||
@ProviderFor(FilteredPriceDocuments)
|
||||
const filteredPriceDocumentsProvider = FilteredPriceDocumentsFamily._();
|
||||
|
||||
/// Provider for filtered documents by category
|
||||
|
||||
/// Provider for filtered documents by category with file path management
|
||||
final class FilteredPriceDocumentsProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
AsyncValue<List<PriceDocument>>,
|
||||
List<PriceDocument>,
|
||||
FutureOr<List<PriceDocument>>
|
||||
>
|
||||
with
|
||||
$FutureModifier<List<PriceDocument>>,
|
||||
$FutureProvider<List<PriceDocument>> {
|
||||
/// Provider for filtered documents by category
|
||||
$AsyncNotifierProvider<FilteredPriceDocuments, List<PriceDocument>> {
|
||||
/// Provider for filtered documents by category with file path management
|
||||
const FilteredPriceDocumentsProvider._({
|
||||
required FilteredPriceDocumentsFamily super.from,
|
||||
required DocumentCategory super.argument,
|
||||
@@ -202,15 +134,7 @@ final class FilteredPriceDocumentsProvider
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$FutureProviderElement<List<PriceDocument>> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $FutureProviderElement(pointer);
|
||||
|
||||
@override
|
||||
FutureOr<List<PriceDocument>> create(Ref ref) {
|
||||
final argument = this.argument as DocumentCategory;
|
||||
return filteredPriceDocuments(ref, argument);
|
||||
}
|
||||
FilteredPriceDocuments create() => FilteredPriceDocuments();
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
@@ -225,13 +149,16 @@ final class FilteredPriceDocumentsProvider
|
||||
}
|
||||
|
||||
String _$filteredPriceDocumentsHash() =>
|
||||
r'8f5b2ed822694b4dd9523e1a61e202a7ba0c1fbc';
|
||||
r'c06d858ed1027d6408c4b70c29f47a4c4c9eb21c';
|
||||
|
||||
/// Provider for filtered documents by category
|
||||
/// Provider for filtered documents by category with file path management
|
||||
|
||||
final class FilteredPriceDocumentsFamily extends $Family
|
||||
with
|
||||
$FunctionalFamilyOverride<
|
||||
$ClassFamilyOverride<
|
||||
FilteredPriceDocuments,
|
||||
AsyncValue<List<PriceDocument>>,
|
||||
List<PriceDocument>,
|
||||
FutureOr<List<PriceDocument>>,
|
||||
DocumentCategory
|
||||
> {
|
||||
@@ -244,7 +171,7 @@ final class FilteredPriceDocumentsFamily extends $Family
|
||||
isAutoDispose: true,
|
||||
);
|
||||
|
||||
/// Provider for filtered documents by category
|
||||
/// Provider for filtered documents by category with file path management
|
||||
|
||||
FilteredPriceDocumentsProvider call(DocumentCategory category) =>
|
||||
FilteredPriceDocumentsProvider._(argument: category, from: this);
|
||||
@@ -252,3 +179,29 @@ final class FilteredPriceDocumentsFamily extends $Family
|
||||
@override
|
||||
String toString() => r'filteredPriceDocumentsProvider';
|
||||
}
|
||||
|
||||
/// Provider for filtered documents by category with file path management
|
||||
|
||||
abstract class _$FilteredPriceDocuments
|
||||
extends $AsyncNotifier<List<PriceDocument>> {
|
||||
late final _$args = ref.$arg as DocumentCategory;
|
||||
DocumentCategory get category => _$args;
|
||||
|
||||
FutureOr<List<PriceDocument>> build(DocumentCategory category);
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final created = build(_$args);
|
||||
final ref =
|
||||
this.ref as $Ref<AsyncValue<List<PriceDocument>>, List<PriceDocument>>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AsyncValue<List<PriceDocument>>, List<PriceDocument>>,
|
||||
AsyncValue<List<PriceDocument>>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleValue(ref, created);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user