From 3a013c829fa0773fe2e8199f9ebc842969416493 Mon Sep 17 00:00:00 2001 From: alzalia1 Date: Fri, 15 Aug 2025 11:46:09 +0200 Subject: [PATCH] merge ?3 --- .../sell_page/view_model/sell_view_model.dart | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/lib/ui/sell_page/view_model/sell_view_model.dart b/lib/ui/sell_page/view_model/sell_view_model.dart index b130a32..b07ba9a 100644 --- a/lib/ui/sell_page/view_model/sell_view_model.dart +++ b/lib/ui/sell_page/view_model/sell_view_model.dart @@ -52,6 +52,47 @@ class SellViewModel extends ChangeNotifier { notifyListeners(); } + Future scanBook(BarcodeCapture barcode) async { + int ean = int.parse(barcode.barcodes.first.rawValue!); + Bal? bal = await _balRepository.ongoingBal(); + _scannedBooks.clear(); + + final result = await _bookInstanceRepository.getByEan(bal!.id, ean); + switch (result) { + case Ok(): + for (BookInstance instance in result.value) { + Book book; + final result2 = await _bookRepository.getBookById(instance.bookId); + switch (result2) { + case Ok(): + book = result2.value; + break; + case Error(): + continue; + } + Owner owner; + final result3 = await _ownerRepository.getOwnerById(instance.ownerId); + switch (result3) { + case Ok(): + owner = result3.value; + break; + case Error(): + continue; + } + _scannedBooks.add( + BookStack(instance: instance, book: book, owner: owner), + ); + } + break; + case Error(): + break; + } + + isScanLoaded = true; + notifyListeners(); + return; + } + /* * ================= * =====[ BAL ]=====