update invoice
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
/// Invoices Provider
|
||||
///
|
||||
/// Riverpod providers for managing invoices state.
|
||||
library;
|
||||
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:worker/core/network/dio_client.dart';
|
||||
import 'package:worker/features/invoices/data/datasources/invoice_remote_datasource.dart';
|
||||
import 'package:worker/features/invoices/data/repositories/invoice_repository_impl.dart';
|
||||
import 'package:worker/features/invoices/domain/entities/invoice.dart';
|
||||
import 'package:worker/features/invoices/domain/repositories/invoice_repository.dart';
|
||||
|
||||
part 'invoices_provider.g.dart';
|
||||
|
||||
/// Invoice Repository Provider
|
||||
@riverpod
|
||||
Future<InvoiceRepository> invoiceRepository(Ref ref) async {
|
||||
final dioClient = await ref.watch(dioClientProvider.future);
|
||||
final remoteDataSource = InvoiceRemoteDataSource(dioClient);
|
||||
return InvoiceRepositoryImpl(remoteDataSource);
|
||||
}
|
||||
|
||||
/// Invoices Provider
|
||||
///
|
||||
/// Provides list of all invoices from repository.
|
||||
@riverpod
|
||||
class Invoices extends _$Invoices {
|
||||
@override
|
||||
Future<List<Invoice>> build() async {
|
||||
try {
|
||||
final repository = await ref.read(invoiceRepositoryProvider.future);
|
||||
final invoices = await repository.getInvoicesList(
|
||||
limitStart: 0,
|
||||
limitPageLength: 0, // 0 = get all
|
||||
);
|
||||
// Sort by posting date (newest first)
|
||||
invoices.sort((a, b) => b.postingDate.compareTo(a.postingDate));
|
||||
return invoices;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to load invoices: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Refresh invoices
|
||||
Future<void> refresh() async {
|
||||
state = const AsyncValue.loading();
|
||||
state = await AsyncValue.guard(() async {
|
||||
final repository = await ref.read(invoiceRepositoryProvider.future);
|
||||
final invoices = await repository.getInvoicesList(
|
||||
limitStart: 0,
|
||||
limitPageLength: 0,
|
||||
);
|
||||
// Sort by posting date (newest first)
|
||||
invoices.sort((a, b) => b.postingDate.compareTo(a.postingDate));
|
||||
return invoices;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Invoice Detail Provider
|
||||
///
|
||||
/// Provides invoice detail by ID.
|
||||
@riverpod
|
||||
Future<Invoice> invoiceDetail(Ref ref, String name) async {
|
||||
final repository = await ref.watch(invoiceRepositoryProvider.future);
|
||||
return await repository.getInvoiceDetail(name);
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'invoices_provider.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
/// Invoice Repository Provider
|
||||
|
||||
@ProviderFor(invoiceRepository)
|
||||
const invoiceRepositoryProvider = InvoiceRepositoryProvider._();
|
||||
|
||||
/// Invoice Repository Provider
|
||||
|
||||
final class InvoiceRepositoryProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
AsyncValue<InvoiceRepository>,
|
||||
InvoiceRepository,
|
||||
FutureOr<InvoiceRepository>
|
||||
>
|
||||
with
|
||||
$FutureModifier<InvoiceRepository>,
|
||||
$FutureProvider<InvoiceRepository> {
|
||||
/// Invoice Repository Provider
|
||||
const InvoiceRepositoryProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'invoiceRepositoryProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$invoiceRepositoryHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$FutureProviderElement<InvoiceRepository> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $FutureProviderElement(pointer);
|
||||
|
||||
@override
|
||||
FutureOr<InvoiceRepository> create(Ref ref) {
|
||||
return invoiceRepository(ref);
|
||||
}
|
||||
}
|
||||
|
||||
String _$invoiceRepositoryHash() => r'16ac0418e4a5522544346b8af22d3fcf33071016';
|
||||
|
||||
/// Invoices Provider
|
||||
///
|
||||
/// Provides list of all invoices from repository.
|
||||
|
||||
@ProviderFor(Invoices)
|
||||
const invoicesProvider = InvoicesProvider._();
|
||||
|
||||
/// Invoices Provider
|
||||
///
|
||||
/// Provides list of all invoices from repository.
|
||||
final class InvoicesProvider
|
||||
extends $AsyncNotifierProvider<Invoices, List<Invoice>> {
|
||||
/// Invoices Provider
|
||||
///
|
||||
/// Provides list of all invoices from repository.
|
||||
const InvoicesProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'invoicesProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$invoicesHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
Invoices create() => Invoices();
|
||||
}
|
||||
|
||||
String _$invoicesHash() => r'fa724059f84f945c52bb7b8508e768d1980e8fe3';
|
||||
|
||||
/// Invoices Provider
|
||||
///
|
||||
/// Provides list of all invoices from repository.
|
||||
|
||||
abstract class _$Invoices extends $AsyncNotifier<List<Invoice>> {
|
||||
FutureOr<List<Invoice>> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final created = build();
|
||||
final ref = this.ref as $Ref<AsyncValue<List<Invoice>>, List<Invoice>>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AsyncValue<List<Invoice>>, List<Invoice>>,
|
||||
AsyncValue<List<Invoice>>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleValue(ref, created);
|
||||
}
|
||||
}
|
||||
|
||||
/// Invoice Detail Provider
|
||||
///
|
||||
/// Provides invoice detail by ID.
|
||||
|
||||
@ProviderFor(invoiceDetail)
|
||||
const invoiceDetailProvider = InvoiceDetailFamily._();
|
||||
|
||||
/// Invoice Detail Provider
|
||||
///
|
||||
/// Provides invoice detail by ID.
|
||||
|
||||
final class InvoiceDetailProvider
|
||||
extends $FunctionalProvider<AsyncValue<Invoice>, Invoice, FutureOr<Invoice>>
|
||||
with $FutureModifier<Invoice>, $FutureProvider<Invoice> {
|
||||
/// Invoice Detail Provider
|
||||
///
|
||||
/// Provides invoice detail by ID.
|
||||
const InvoiceDetailProvider._({
|
||||
required InvoiceDetailFamily super.from,
|
||||
required String super.argument,
|
||||
}) : super(
|
||||
retry: null,
|
||||
name: r'invoiceDetailProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$invoiceDetailHash();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return r'invoiceDetailProvider'
|
||||
''
|
||||
'($argument)';
|
||||
}
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$FutureProviderElement<Invoice> $createElement($ProviderPointer pointer) =>
|
||||
$FutureProviderElement(pointer);
|
||||
|
||||
@override
|
||||
FutureOr<Invoice> create(Ref ref) {
|
||||
final argument = this.argument as String;
|
||||
return invoiceDetail(ref, argument);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is InvoiceDetailProvider && other.argument == argument;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return argument.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
String _$invoiceDetailHash() => r'ca2993098ab182836a9c0272ae785eba87b83c83';
|
||||
|
||||
/// Invoice Detail Provider
|
||||
///
|
||||
/// Provides invoice detail by ID.
|
||||
|
||||
final class InvoiceDetailFamily extends $Family
|
||||
with $FunctionalFamilyOverride<FutureOr<Invoice>, String> {
|
||||
const InvoiceDetailFamily._()
|
||||
: super(
|
||||
retry: null,
|
||||
name: r'invoiceDetailProvider',
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
isAutoDispose: true,
|
||||
);
|
||||
|
||||
/// Invoice Detail Provider
|
||||
///
|
||||
/// Provides invoice detail by ID.
|
||||
|
||||
InvoiceDetailProvider call(String name) =>
|
||||
InvoiceDetailProvider._(argument: name, from: this);
|
||||
|
||||
@override
|
||||
String toString() => r'invoiceDetailProvider';
|
||||
}
|
||||
Reference in New Issue
Block a user