add alot
This commit is contained in:
@@ -21,6 +21,9 @@ abstract class ProductService {
|
||||
Future<void> updateProduct(Product product);
|
||||
|
||||
Future<void> deleteProduct(String id);
|
||||
|
||||
Future<void> decreaseStock(String productId, int amount);
|
||||
Future<void> increaseStock(String productId, int amount);
|
||||
}
|
||||
|
||||
class DriftProductService implements ProductService {
|
||||
@@ -118,4 +121,39 @@ class DriftProductService implements ProductService {
|
||||
|
||||
await query.go();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> decreaseStock(String productId, int amount) async {
|
||||
final product = await getProductById(productId);
|
||||
|
||||
if (product == null) {
|
||||
throw Exception('Product not found');
|
||||
}
|
||||
|
||||
if (product.stockQuantity < amount) {
|
||||
throw Exception('Not enough stock');
|
||||
}
|
||||
|
||||
await updateProduct(
|
||||
product.copyWith(
|
||||
stockQuantity: product.stockQuantity - amount,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> increaseStock(String productId, int amount) async {
|
||||
final product = await getProductById(productId);
|
||||
|
||||
if (product == null) {
|
||||
throw Exception('Product not found');
|
||||
}
|
||||
|
||||
await updateProduct(
|
||||
product.copyWith(
|
||||
stockQuantity: product.stockQuantity + amount,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user