feat: start working on sell
This commit is contained in:
parent
f378c8c0be
commit
1803a2b119
8 changed files with 94 additions and 31 deletions
|
|
@ -16,6 +16,22 @@ class OwnerRepository {
|
|||
final WebsocketClient _wsClient;
|
||||
late final StreamSubscription sub;
|
||||
List<Owner>? _cachedOwners;
|
||||
Owner? _sectionOwner;
|
||||
|
||||
Future<Result<Owner>> get sectionOwner async {
|
||||
if (_sectionOwner != null) {
|
||||
return Result.ok(_sectionOwner!);
|
||||
}
|
||||
final result = await _apiClient.getSectionOwner();
|
||||
switch (result) {
|
||||
case Ok():
|
||||
_sectionOwner = result.value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Adds an [Owner] to the database, and gets the resulting [Owner].
|
||||
Future<Result<Owner>> addOwner(
|
||||
|
|
|
|||
|
|
@ -304,6 +304,27 @@ class ApiClient {
|
|||
* ====================
|
||||
*/
|
||||
|
||||
Future<Result<Owner>> getSectionOwner() async {
|
||||
final client = Client();
|
||||
try {
|
||||
final headers = await _getHeaders();
|
||||
final response = await client.get(
|
||||
Uri.parse("https://$apiBasePath/owner/self"),
|
||||
headers: headers,
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final json = jsonDecode(response.body);
|
||||
return Result.ok(Owner.fromJSON(json));
|
||||
} else {
|
||||
throw "Unknown error";
|
||||
}
|
||||
} catch (e) {
|
||||
return Result.error(Exception(e));
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
/// Call on `/owners` to get a list of all [Owner]s
|
||||
Future<Result<List<Owner>>> getOwners() async {
|
||||
final client = Client();
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ abstract final class Routes {
|
|||
|
||||
// ==[ SELL ]==
|
||||
static const sell = '/sell';
|
||||
static const sellScan = '/sell/scan';
|
||||
|
||||
// ==[ AUTH ]==
|
||||
static const login = '/login';
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ class AddViewModel extends ChangeNotifier {
|
|||
notifyListeners();
|
||||
}
|
||||
|
||||
Owner? _sectionOwner;
|
||||
Owner? get sectionOwner => _sectionOwner;
|
||||
|
||||
List<Owner> _owners = [];
|
||||
List<Owner>? get owners => _owners;
|
||||
Future<Result<Owner>> addOwner(
|
||||
|
|
@ -176,9 +179,17 @@ class AddViewModel extends ChangeNotifier {
|
|||
),
|
||||
);
|
||||
case Error():
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
final result2 = await _ownerRepository.sectionOwner;
|
||||
switch (result2) {
|
||||
case Ok():
|
||||
_sectionOwner = result2.value;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return result2;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,15 +129,17 @@ class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
|||
case Ok():
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(
|
||||
"ID : ${widget.viewModel.currentOwner!.firstName[0]}${widget.viewModel.currentOwner!.lastName[0]}${(price == 0) ? "PL" : price.toString()}",
|
||||
"ID : ${widget.viewModel.currentOwner!.firstName[0].toUpperCase()}${widget.viewModel.currentOwner!.lastName[0].toUpperCase()}${(price == 0) ? "PL" : price.toString()}",
|
||||
),
|
||||
content: Text(
|
||||
"Identifiant propriétaire de ce livre. Pensez à l'écrire pour retrouver lae propriétaire du livre lors de la vente ou du retour !",
|
||||
(widget.viewModel.currentOwner!.id ==
|
||||
widget.viewModel.sectionOwner!.id)
|
||||
? "Ce livre appartient à la section. Vous pouvez mettre le code, ou poser une gomette, ..."
|
||||
: "Identifiant propriétaire de ce livre. Pensez à l'écrire pour retrouver lae propriétaire du livre lors de la vente ou du retour !",
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
|
|
@ -145,7 +147,9 @@ class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
|||
widget.exitPopup(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Enregistré: ${widget.book.title}"),
|
||||
content: Text(
|
||||
"Enregistré: ${widget.book.title}",
|
||||
),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
|
|
@ -155,6 +159,7 @@ class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
|||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
break;
|
||||
case Error():
|
||||
if (context.mounted) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
import 'package:seshat/ui/sell_page/view_model/sell_view_model.dart';
|
||||
|
||||
class ManualScanPopup extends StatelessWidget {
|
||||
ManualScanPopup({required this.viewModel});
|
||||
const ManualScanPopup({
|
||||
super.key,
|
||||
required this.viewModel,
|
||||
required this.controller,
|
||||
});
|
||||
|
||||
final SellViewModel viewModel;
|
||||
final MobileScannerController controller;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
@ -29,6 +35,7 @@ class ManualScanPopup extends StatelessWidget {
|
|||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
controller.start();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text("Annuler"),
|
||||
|
|
|
|||
|
|
@ -61,11 +61,14 @@ class _ScanScreenState extends State<ScanScreen> {
|
|||
backgroundColor: WidgetStatePropertyAll(theme.cardColor),
|
||||
),
|
||||
onPressed: () {
|
||||
controller.stop();
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) =>
|
||||
ManualScanPopup(viewModel: widget.viewModel),
|
||||
builder: (context) => ManualScanPopup(
|
||||
viewModel: widget.viewModel,
|
||||
controller: controller,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Text("Vendre un livre sans scanner"),
|
||||
|
|
|
|||
|
|
@ -154,7 +154,6 @@ class _SellPageState extends State<SellPage> {
|
|||
],
|
||||
),
|
||||
),
|
||||
|
||||
(widget.viewModel.showScan)
|
||||
? ScanScreen(viewModel: widget.viewModel)
|
||||
: SizedBox(),
|
||||
|
|
|
|||
Reference in a new issue