auto-claude: subtask-4-2 - Create gRPC-based delivery routes provider

Add grpcDeliveryRoutesProvider to providers.dart that uses GrpcCqrsApiClient
for fetching delivery routes. Follows the same pattern as the HTTP-based
deliveryRoutesProvider: checks authentication, uses grpcClientProvider,
and handles Result<T> responses with proper error logging.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Mathias Beaulieu-Duncan 2026-01-20 13:08:49 -05:00
parent 8ea186ef4a
commit 1d3c06bc4c
2 changed files with 42 additions and 5 deletions

View File

@ -3,23 +3,23 @@
"spec": "002-migrate-api-routes-from-http-to-grpc",
"state": "building",
"subtasks": {
"completed": 6,
"completed": 9,
"total": 13,
"in_progress": 1,
"failed": 0
},
"phase": {
"current": "gRPC Client Implementation",
"current": "Provider Integration",
"id": null,
"total": 4
"total": 3
},
"workers": {
"active": 0,
"max": 1
},
"session": {
"number": 7,
"number": 10,
"started_at": "2026-01-20T12:45:59.858836"
},
"last_update": "2026-01-20T13:03:21.219002"
"last_update": "2026-01-20T13:08:01.853317"
}

View File

@ -95,6 +95,43 @@ final deliveryRoutesProvider = FutureProvider<List<DeliveryRoute>>((ref) async {
return result.whenSuccess((routes) => routes) ?? [];
});
/// Provider for delivery routes using gRPC.
///
/// This is the gRPC-based alternative to [deliveryRoutesProvider].
/// Uses [GrpcCqrsApiClient] for improved performance and type safety.
///
/// Example usage:
/// ```dart
/// final routes = ref.watch(grpcDeliveryRoutesProvider);
/// routes.when(
/// data: (data) => displayRoutes(data),
/// loading: () => showLoading(),
/// error: (error, stack) => showError(error),
/// );
/// ```
final grpcDeliveryRoutesProvider = FutureProvider<List<DeliveryRoute>>((ref) async {
final authService = ref.watch(authServiceProvider);
final isAuthenticated = await authService.isAuthenticated();
if (!isAuthenticated) {
throw Exception('User not authenticated');
}
final grpcClient = ref.watch(grpcClientProvider);
final result = await grpcClient.getDeliveryRoutes();
return result.when(
success: (routes) => routes,
onError: (error) {
debugPrint('ERROR fetching delivery routes via gRPC: ${error.message}');
if (error.originalException != null) {
debugPrint('Original exception: ${error.originalException}');
}
throw Exception(error.message);
},
);
});
final deliveriesProvider = FutureProvider.family<List<Delivery>, int>((ref, routeFragmentId) async {
final authService = ref.watch(authServiceProvider);
final isAuthenticated = await authService.isAuthenticated();