This commit is contained in:
2026-07-27 21:32:03 +02:00
parent 160b4e4cda
commit 77c1747b40
23 changed files with 1392 additions and 87 deletions
+38
View File
@@ -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,
),
);
}
}