Update routes/purchase.py
Browse files- routes/purchase.py +9 -9
routes/purchase.py
CHANGED
@@ -6,13 +6,13 @@ router = APIRouter()
|
|
6 |
|
7 |
|
8 |
@router.post("/add-to-cart")
|
9 |
-
def handle_add_to_cart(
|
10 |
customer_id = next(
|
11 |
-
(entity['value'] for entity in
|
12 |
product_id = next(
|
13 |
-
(entity['value'] for entity in
|
14 |
quantity = next(
|
15 |
-
(entity['value'] for entity in
|
16 |
if customer_id and product_id:
|
17 |
cart = add_to_cart(customer_id, product_id, int(quantity))
|
18 |
return cart
|
@@ -30,11 +30,11 @@ def handle_view_cart(customer_id: str):
|
|
30 |
|
31 |
|
32 |
@router.post("/remove-from-cart")
|
33 |
-
def handle_remove_from_cart(
|
34 |
customer_id = next(
|
35 |
-
(entity['value'] for entity in
|
36 |
product_id = next(
|
37 |
-
(entity['value'] for entity in
|
38 |
if customer_id and product_id:
|
39 |
cart = remove_from_cart(customer_id, product_id)
|
40 |
return cart
|
@@ -44,9 +44,9 @@ def handle_remove_from_cart(query: Query):
|
|
44 |
|
45 |
|
46 |
@router.post("/checkout")
|
47 |
-
def handle_checkout(
|
48 |
customer_id = next(
|
49 |
-
(entity['value'] for entity in
|
50 |
if customer_id:
|
51 |
order = checkout(customer_id)
|
52 |
return order
|
|
|
6 |
|
7 |
|
8 |
@router.post("/add-to-cart")
|
9 |
+
def handle_add_to_cart(input: Input):
|
10 |
customer_id = next(
|
11 |
+
(entity['value'] for entity in input.entities if entity['entity'] == 'customer_id'), None)
|
12 |
product_id = next(
|
13 |
+
(entity['value'] for entity in input.entities if entity['entity'] == 'product_id'), None)
|
14 |
quantity = next(
|
15 |
+
(entity['value'] for entity in input.entities if entity['entity'] == 'quantity'), 1)
|
16 |
if customer_id and product_id:
|
17 |
cart = add_to_cart(customer_id, product_id, int(quantity))
|
18 |
return cart
|
|
|
30 |
|
31 |
|
32 |
@router.post("/remove-from-cart")
|
33 |
+
def handle_remove_from_cart(input: Input):
|
34 |
customer_id = next(
|
35 |
+
(entity['value'] for entity in input.entities if entity['entity'] == 'customer_id'), None)
|
36 |
product_id = next(
|
37 |
+
(entity['value'] for entity in input.entities if entity['entity'] == 'product_id'), None)
|
38 |
if customer_id and product_id:
|
39 |
cart = remove_from_cart(customer_id, product_id)
|
40 |
return cart
|
|
|
44 |
|
45 |
|
46 |
@router.post("/checkout")
|
47 |
+
def handle_checkout(input: Input):
|
48 |
customer_id = next(
|
49 |
+
(entity['value'] for entity in input.entities if entity['entity'] == 'customer_id'), None)
|
50 |
if customer_id:
|
51 |
order = checkout(customer_id)
|
52 |
return order
|