mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-27 16:24:07 +02:00
fix purchase
This commit is contained in:
parent
690d030a14
commit
20076fc11c
@ -59,7 +59,8 @@ class FinishShoppingPage extends StatelessWidget {
|
||||
onPressed: () async {
|
||||
payingStateRepo.next();
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
if (cartController.purchase() is Err) {
|
||||
if (await cartController.purchase()
|
||||
is Err<Null, String>) {
|
||||
if (context.mounted) {
|
||||
showDialog<String>(
|
||||
context: context,
|
||||
|
@ -102,6 +102,13 @@ class BackendServer implements Server {
|
||||
@override
|
||||
Future<Result<Null, String>> purchaseCart(
|
||||
String token, List<CartItem> cartItems) async {
|
||||
final items = json.encode({
|
||||
"items": cartItems
|
||||
.map((cartItem) =>
|
||||
{"product_id": cartItem.product.id, "amount": cartItem.amount})
|
||||
.toList()
|
||||
});
|
||||
print(items);
|
||||
final res = await http
|
||||
.post(Uri.parse("$_apiUrl/carts/purchase"),
|
||||
headers: {
|
||||
@ -109,7 +116,7 @@ class BackendServer implements Server {
|
||||
"Session-Token": token
|
||||
},
|
||||
body: json.encode({
|
||||
"cart_items": cartItems
|
||||
"items": cartItems
|
||||
.map((cartItem) => {
|
||||
"product_id": cartItem.product.id,
|
||||
"amount": cartItem.amount
|
||||
@ -119,7 +126,7 @@ class BackendServer implements Server {
|
||||
.then((res) => json.decode(res.body));
|
||||
|
||||
if (res["ok"]) {
|
||||
return Ok(null);
|
||||
return const Ok(null);
|
||||
} else {
|
||||
return Err(res["msg"]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user