auto-claude: subtask-3-2 - Implement getDeliveryRoutes query method
This commit is contained in:
parent
f6ecc8b1ae
commit
66d337315b
@ -3,6 +3,7 @@ import 'dart:async';
|
|||||||
import 'package:grpc/grpc.dart';
|
import 'package:grpc/grpc.dart';
|
||||||
|
|
||||||
import '../generated/delivery_service.pbgrpc.dart';
|
import '../generated/delivery_service.pbgrpc.dart';
|
||||||
|
import '../models/delivery_route.dart';
|
||||||
import '../services/auth_service.dart';
|
import '../services/auth_service.dart';
|
||||||
import 'grpc_config.dart';
|
import 'grpc_config.dart';
|
||||||
import 'types.dart';
|
import 'types.dart';
|
||||||
@ -241,6 +242,51 @@ class GrpcCqrsApiClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Query Methods
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
/// Gets all delivery routes.
|
||||||
|
///
|
||||||
|
/// Returns a [Result] containing a list of [DeliveryRoute] objects.
|
||||||
|
/// Maps the gRPC [DeliveryRoutesResponse] to domain models.
|
||||||
|
///
|
||||||
|
/// Example:
|
||||||
|
/// ```dart
|
||||||
|
/// final result = await client.getDeliveryRoutes();
|
||||||
|
/// result.when(
|
||||||
|
/// success: (routes) => displayRoutes(routes),
|
||||||
|
/// onError: (error) => showError(error.message),
|
||||||
|
/// );
|
||||||
|
/// ```
|
||||||
|
Future<Result<List<DeliveryRoute>>> getDeliveryRoutes() async {
|
||||||
|
final result = await _executeWithAuth<DeliveryRoutesResponse>(
|
||||||
|
(options) => deliveryClient.getDeliveryRoutes(Empty(), options: options),
|
||||||
|
);
|
||||||
|
|
||||||
|
return result.when(
|
||||||
|
success: (response) {
|
||||||
|
final routes = response.routes.map(_mapDeliveryRouteProto).toList();
|
||||||
|
return Result.success(routes);
|
||||||
|
},
|
||||||
|
onError: (error) => Result.error(error),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Maps a [DeliveryRouteProto] to a [DeliveryRoute] domain model.
|
||||||
|
DeliveryRoute _mapDeliveryRouteProto(DeliveryRouteProto proto) {
|
||||||
|
return DeliveryRoute(
|
||||||
|
id: proto.id,
|
||||||
|
routeId: proto.routeId,
|
||||||
|
name: proto.name,
|
||||||
|
routeName: proto.routeName,
|
||||||
|
deliveriesCount: proto.deliveriesCount,
|
||||||
|
deliveredCount: proto.deliveredCount,
|
||||||
|
completed: proto.completed,
|
||||||
|
createdAt: proto.createdAt,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Shuts down the gRPC channel and releases resources.
|
/// Shuts down the gRPC channel and releases resources.
|
||||||
///
|
///
|
||||||
/// Should be called when the client is no longer needed to properly
|
/// Should be called when the client is no longer needed to properly
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user