fix: formatting

This commit is contained in:
2026-07-29 01:42:34 +02:00
parent 521c8f8c4e
commit 50e6fca9d1
32 changed files with 501 additions and 575 deletions
+66 -78
View File
@@ -13,9 +13,7 @@ abstract class BarTabService {
Future<BarTab?> getTabById(String id);
Future<BarTab> createTab({
required String customerName,
});
Future<BarTab> createTab({required String customerName});
Future<void> addProductToTab({
required String tabId,
@@ -38,9 +36,7 @@ class DriftBarTabService implements BarTabService {
final AppDatabase database;
final _uuid = const Uuid();
DriftBarTabService({
required this.database,
});
DriftBarTabService({required this.database});
TabItem _mapItemRow(TabItemRow row) {
return TabItem(
@@ -53,10 +49,7 @@ class DriftBarTabService implements BarTabService {
);
}
BarTab _mapTabRow(
BarTabRow row,
List<TabItem> items,
) {
BarTab _mapTabRow(BarTabRow row, List<TabItem> items) {
return BarTab(
id: row.id,
customerName: row.customerName,
@@ -81,9 +74,7 @@ class DriftBarTabService implements BarTabService {
Future<List<TabItem>> _getItemsForTab(String tabId) async {
final query = database.select(database.tabItems)
..where((item) => item.tabId.equals(tabId))
..orderBy([
(item) => OrderingTerm.asc(item.createdAt),
]);
..orderBy([(item) => OrderingTerm.asc(item.createdAt)]);
final rows = await query.get();
@@ -94,9 +85,7 @@ class DriftBarTabService implements BarTabService {
Future<List<BarTab>> getOpenTabs() async {
final query = database.select(database.barTabs)
..where((tab) => tab.status.equals('open'))
..orderBy([
(tab) => OrderingTerm.desc(tab.openedAt),
]);
..orderBy([(tab) => OrderingTerm.desc(tab.openedAt)]);
final tabRows = await query.get();
@@ -128,19 +117,19 @@ class DriftBarTabService implements BarTabService {
}
@override
Future<BarTab> createTab({
required String customerName,
}) async {
Future<BarTab> createTab({required String customerName}) async {
final id = _uuid.v4();
await database.into(database.barTabs).insert(
BarTabsCompanion.insert(
id: id,
customerName: customerName,
status: const Value('open'),
openedAt: DateTime.now(),
),
);
await database
.into(database.barTabs)
.insert(
BarTabsCompanion.insert(
id: id,
customerName: customerName,
status: const Value('open'),
openedAt: DateTime.now(),
),
);
final tab = await getTabById(id);
@@ -159,9 +148,8 @@ class DriftBarTabService implements BarTabService {
await database.transaction(() async {
final existingItemQuery = database.select(database.tabItems)
..where(
(item) =>
item.tabId.equals(tabId) &
item.productId.equals(product.id),
(item) =>
item.tabId.equals(tabId) & item.productId.equals(product.id),
);
final existingItem = await existingItemQuery.getSingleOrNull();
@@ -171,25 +159,25 @@ class DriftBarTabService implements BarTabService {
..where((item) => item.id.equals(existingItem.id));
await updateQuery.write(
TabItemsCompanion(
quantity: Value(existingItem.quantity + 1),
),
TabItemsCompanion(quantity: Value(existingItem.quantity + 1)),
);
return;
}
await database.into(database.tabItems).insert(
TabItemsCompanion.insert(
id: _uuid.v4(),
tabId: tabId,
productId: product.id,
productName: product.name,
quantity: 1,
unitPriceInCents: product.priceInCents,
createdAt: DateTime.now(),
),
);
await database
.into(database.tabItems)
.insert(
TabItemsCompanion.insert(
id: _uuid.v4(),
tabId: tabId,
productId: product.id,
productName: product.name,
quantity: 1,
unitPriceInCents: product.priceInCents,
createdAt: DateTime.now(),
),
);
});
}
@@ -209,11 +197,7 @@ class DriftBarTabService implements BarTabService {
final updateQuery = database.update(database.tabItems)
..where((item) => item.id.equals(tabItemId));
await updateQuery.write(
TabItemsCompanion(
quantity: Value(quantity),
),
);
await updateQuery.write(TabItemsCompanion(quantity: Value(quantity)));
}
@override
@@ -236,26 +220,30 @@ class DriftBarTabService implements BarTabService {
final closedTabId = _uuid.v4();
await database.into(database.closedTabs).insert(
ClosedTabsCompanion.insert(
id: closedTabId,
originalTabId: tabId,
customerName: tabRow.customerName,
closedAt: DateTime.now(),
),
);
await database
.into(database.closedTabs)
.insert(
ClosedTabsCompanion.insert(
id: closedTabId,
originalTabId: tabId,
customerName: tabRow.customerName,
closedAt: DateTime.now(),
),
);
for (final item in items) {
await database.into(database.closedTabItems).insert(
ClosedTabItemsCompanion.insert(
id: _uuid.v4(),
closedTabId: closedTabId,
productId: item.productId,
productName: item.productName,
quantity: item.quantity,
unitPriceInCents: item.unitPriceInCents,
),
);
await database
.into(database.closedTabItems)
.insert(
ClosedTabItemsCompanion.insert(
id: _uuid.v4(),
closedTabId: closedTabId,
productId: item.productId,
productName: item.productName,
quantity: item.quantity,
unitPriceInCents: item.unitPriceInCents,
),
);
}
final deleteQuery = database.delete(database.tabItems)
@@ -268,9 +256,7 @@ class DriftBarTabService implements BarTabService {
@override
Future<List<ClosedTab>> getClosedTabs() async {
final query = database.select(database.closedTabs)
..orderBy([
(tab) => OrderingTerm.desc(tab.closedAt),
]);
..orderBy([(tab) => OrderingTerm.desc(tab.closedAt)]);
final closedTabRows = await query.get();
@@ -282,15 +268,17 @@ class DriftBarTabService implements BarTabService {
final itemRows = await itemsQuery.get();
closedTabs.add(ClosedTab(
id: row.id,
originalTabId: row.originalTabId,
customerName: row.customerName,
closedAt: row.closedAt,
items: itemRows.map<ClosedTabItem>(_mapClosedItemRow).toList(),
));
closedTabs.add(
ClosedTab(
id: row.id,
originalTabId: row.originalTabId,
customerName: row.customerName,
closedAt: row.closedAt,
items: itemRows.map<ClosedTabItem>(_mapClosedItemRow).toList(),
),
);
}
return closedTabs;
}
}
}
+19 -25
View File
@@ -23,6 +23,7 @@ abstract class ProductService {
Future<void> deleteProduct(String id);
Future<void> decreaseStock(String productId, int amount);
Future<void> increaseStock(String productId, int amount);
}
@@ -30,9 +31,7 @@ class DriftProductService implements ProductService {
final AppDatabase database;
final _uuid = const Uuid();
DriftProductService({
required this.database,
});
DriftProductService({required this.database});
Product _mapRowToProduct(ProductRow row) {
return Product(
@@ -51,9 +50,7 @@ class DriftProductService implements ProductService {
Future<List<Product>> getProducts() async {
final query = database.select(database.products)
..where((product) => product.active.equals(true))
..orderBy([
(product) => OrderingTerm.asc(product.name),
]);
..orderBy([(product) => OrderingTerm.asc(product.name)]);
final rows = await query.get();
@@ -83,17 +80,19 @@ class DriftProductService implements ProductService {
required int priceInCents,
required String? imagePath,
}) async {
await database.into(database.products).insert(
ProductsCompanion.insert(
id: _uuid.v4(),
name: name,
category: category,
stockQuantity: stockQuantity,
lowStockThreshold: lowStockThreshold,
priceInCents: priceInCents,
imagePath: Value(imagePath),
),
);
await database
.into(database.products)
.insert(
ProductsCompanion.insert(
id: _uuid.v4(),
name: name,
category: category,
stockQuantity: stockQuantity,
lowStockThreshold: lowStockThreshold,
priceInCents: priceInCents,
imagePath: Value(imagePath),
),
);
}
@override
@@ -135,9 +134,7 @@ class DriftProductService implements ProductService {
}
await updateProduct(
product.copyWith(
stockQuantity: product.stockQuantity - amount,
),
product.copyWith(stockQuantity: product.stockQuantity - amount),
);
}
@@ -150,10 +147,7 @@ class DriftProductService implements ProductService {
}
await updateProduct(
product.copyWith(
stockQuantity: product.stockQuantity + amount,
),
product.copyWith(stockQuantity: product.stockQuantity + amount),
);
}
}
}
+11 -9
View File
@@ -19,7 +19,7 @@ class DriftSettingsService implements SettingsService {
return AppSettings(
pinRequired: row.pinRequired,
themeMode: AppThemeMode.values.firstWhere(
(mode) => mode.name == row.themeMode,
(mode) => mode.name == row.themeMode,
orElse: () => AppThemeMode.system,
),
);
@@ -39,12 +39,14 @@ class DriftSettingsService implements SettingsService {
@override
Future<void> saveSettings(AppSettings settings) async {
await database.into(database.appSettingsTable).insertOnConflictUpdate(
AppSettingsTableCompanion.insert(
id: _settingsId,
pinRequired: Value(settings.pinRequired),
themeMode: Value(settings.themeMode.name),
),
);
await database
.into(database.appSettingsTable)
.insertOnConflictUpdate(
AppSettingsTableCompanion.insert(
id: _settingsId,
pinRequired: Value(settings.pinRequired),
themeMode: Value(settings.themeMode.name),
),
);
}
}
}