update cart

This commit is contained in:
Phuoc Nguyen
2025-11-14 16:19:25 +07:00
parent 4738553d2e
commit aae3c9d080
30 changed files with 5954 additions and 758 deletions

View File

@@ -0,0 +1,83 @@
/// Domain Repository Interface: Cart Repository
///
/// Defines the contract for cart data operations.
/// Implementation in data layer handles API and local storage.
library;
import 'package:worker/features/cart/domain/entities/cart_item.dart';
/// Cart Repository Interface
///
/// Provides methods for managing shopping cart items:
/// - Add items to cart
/// - Remove items from cart
/// - Get cart items
/// - Update item quantities
/// - Clear cart
///
/// Implementations should handle:
/// - API-first strategy with local fallback
/// - Offline queue for failed requests
/// - Automatic sync when connection restored
abstract class CartRepository {
/// Add items to cart
///
/// [items] - List of cart items to add
/// [itemIds] - Product ERPNext item codes
/// [quantities] - Quantities for each item
/// [prices] - Unit prices for each item
///
/// Returns list of cart items on success.
/// Throws exceptions on failure.
Future<List<CartItem>> addToCart({
required List<String> itemIds,
required List<double> quantities,
required List<double> prices,
});
/// Remove items from cart
///
/// [itemIds] - Product ERPNext item codes to remove
///
/// Returns true if successful, false otherwise.
/// Throws exceptions on failure.
Future<bool> removeFromCart({
required List<String> itemIds,
});
/// Get all cart items
///
/// Returns list of cart items.
/// Throws exceptions on failure.
Future<List<CartItem>> getCartItems();
/// Update item quantity
///
/// [itemId] - Product ERPNext item code
/// [quantity] - New quantity
/// [price] - Unit price
///
/// Returns updated cart item list.
/// Throws exceptions on failure.
Future<List<CartItem>> updateQuantity({
required String itemId,
required double quantity,
required double price,
});
/// Clear all items from cart
///
/// Returns true if successful, false otherwise.
/// Throws exceptions on failure.
Future<bool> clearCart();
/// Get total cart value
///
/// Returns total amount of all items in cart.
Future<double> getCartTotal();
/// Get total cart item count
///
/// Returns total number of items (sum of quantities).
Future<int> getCartItemCount();
}