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