fix: continuing error managment and documentation

This commit is contained in:
alzalia1 2025-08-23 12:35:36 +02:00
parent 59e1c2558c
commit dad000a1b9
24 changed files with 389 additions and 182 deletions

View file

@ -38,18 +38,29 @@ class AddViewModel extends ChangeNotifier {
* ====================
*/
/// Owner currently selected in the ui
Owner? _currentOwner;
/// Owner currently selected in the ui
Owner? get currentOwner => _currentOwner;
set currentOwner(Owner? owner) {
_currentOwner = owner;
notifyListeners();
}
Owner? _sectionOwner;
Owner? get sectionOwner => _sectionOwner;
/// Owner of the current user
Owner? _ownerOfUser;
/// Owner of the current user
Owner? get ownerOfUser => _ownerOfUser;
/// All the [Owner]
List<Owner> _owners = [];
/// All the [Owner]
List<Owner>? get owners => _owners;
/// Adds an owner from it's [firstName], [lastName] and [contact]
Future<Result<Owner>> addOwner(
String firstName,
String lastName,
@ -85,8 +96,11 @@ class AddViewModel extends ChangeNotifier {
* =================
*/
Bal? _currentBal;
Bal? get currentBal => _currentBal;
/// Ongoing [Bal]
Bal? _ongoingBal;
/// Ongoing [Bal]
Bal? get ongoingBal => _ongoingBal;
/*
* ===================
@ -94,7 +108,10 @@ class AddViewModel extends ChangeNotifier {
* ===================
*/
/// Wether to ask for a price
bool _askPrice = true;
/// Wether to ask for a price
bool get askPrice => _askPrice;
set askPrice(bool newValue) {
_askPrice = newValue;
@ -107,21 +124,26 @@ class AddViewModel extends ChangeNotifier {
* =================================
*/
/// Sends an api request with a [bacorde], then gets the [Book] that was
/// either created or retrieved. Sens the [Book] back wrapped in a [Result].
/// Retrieves the book associated with an ean through a [barcode]
Future<Result<Book>> scanBook(BarcodeCapture barcode) async {
var ean = barcode.barcodes.first.rawValue!;
var result = await _bookRepository.getBookByEAN(ean);
return result;
}
Future<Result<BookInstance>> sendBook(
/// Creates a new Book Instance from its [book], [owner], [bal] and [price]
Future<Result<BookInstance>> sendNewBookInstance(
Book book,
Owner owner,
Bal bal,
double price,
) async {
return await _bookInstanceRepository.sendBook(book, owner, bal, price);
return await _bookInstanceRepository.sendNewBookInstance(
book,
owner,
bal,
price,
);
}
/*
@ -130,9 +152,11 @@ class AddViewModel extends ChangeNotifier {
* =================================
*/
/// Command to load the view model
late final Command0 load;
bool isLoaded = false;
/// Manages the loaders
Future<Result<void>> _load() async {
final result1 = await _loadOwners();
switch (result1) {
@ -153,11 +177,12 @@ class AddViewModel extends ChangeNotifier {
return result2;
}
/// Loads all necessary data about [Bal]s
Future<Result<void>> _loadBal() async {
final result = await _balRepository.getBals();
switch (result) {
case Ok():
_currentBal = result.value
_ongoingBal = result.value
.where((bal) => bal.state == BalState.ongoing)
.firstOrNull;
break;
@ -168,6 +193,7 @@ class AddViewModel extends ChangeNotifier {
return result;
}
/// Loads all the necessary data about [Owner]s
Future<Result<void>> _loadOwners() async {
final result = await _ownerRepository.getOwners();
switch (result) {
@ -182,10 +208,10 @@ class AddViewModel extends ChangeNotifier {
return result;
}
final result2 = await _ownerRepository.sectionOwner;
final result2 = await _ownerRepository.ownerOfUser;
switch (result2) {
case Ok():
_sectionOwner = result2.value;
_ownerOfUser = result2.value;
break;
default:
}