feat: alphabet list, change Layout etc

This commit is contained in:
2026-10-11 20:37:59 +02:00
parent 489896305d
commit 072f560989
31 changed files with 1847 additions and 832 deletions
+23 -15
View File
@@ -21,6 +21,7 @@ class ProductNotFoundException implements Exception {
/// Atomic stock updates shared by the product and tab services, so they can
/// run inside either one's transaction.
extension StockQueries on AppDatabase {
/// Products with infinite stock are only checked for existence.
Future<void> decreaseStock(String productId, int amount) async {
_validateStockAmount(amount);
@@ -28,6 +29,7 @@ extension StockQueries on AppDatabase {
await (update(products)..where(
(row) =>
row.id.equals(productId) &
row.infiniteStock.not() &
row.stockQuantity.isBiggerOrEqualValue(amount),
))
.write(
@@ -38,28 +40,34 @@ extension StockQueries on AppDatabase {
if (updatedRows == 1) return;
final product = await (select(
products,
)..where((row) => row.id.equals(productId))).getSingleOrNull();
if (product == null) throw ProductNotFoundException(productId);
throw const InsufficientStockException();
final product = await _findProduct(productId);
if (!product.infiniteStock) throw const InsufficientStockException();
}
Future<void> increaseStock(String productId, int amount) async {
_validateStockAmount(amount);
final updatedRows =
await (update(
products,
)..where((row) => row.id.equals(productId))).write(
ProductsCompanion.custom(
stockQuantity: products.stockQuantity + Variable(amount),
),
);
await (update(products)..where(
(row) => row.id.equals(productId) & row.infiniteStock.not(),
))
.write(
ProductsCompanion.custom(
stockQuantity: products.stockQuantity + Variable(amount),
),
);
if (updatedRows != 1) throw ProductNotFoundException(productId);
if (updatedRows != 1) await _findProduct(productId);
}
Future<ProductRow> _findProduct(String productId) async {
final product = await (select(
products,
)..where((row) => row.id.equals(productId))).getSingleOrNull();
if (product == null) throw ProductNotFoundException(productId);
return product;
}
void _validateStockAmount(int amount) {