Skip to content

Commit

Permalink
Implement basket_modify
Browse files Browse the repository at this point in the history
  • Loading branch information
noahpistilli committed Feb 19, 2024
1 parent 1e17183 commit 82c8e60
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 deletions.
1 change: 1 addition & 0 deletions food.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def initialize_server():
"webApi_order_done": responses.order_done,
"webApi_inquiry_done": responses.inquiry_done,
"webApi_basket_delete": responses.basket_delete,
"webApi_basket_modify": responses.basket_modify
}


Expand Down
68 changes: 42 additions & 26 deletions responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ def basket_reset(request):
return {"spot": True}


@multiple_root_nodes()
def basket_modify(request):
num = request.form.get("basketNo")
zip_code = request.form.get("areaCode")

query = UserOrders.query.filter_by(zip_code=zip_code).first()
basket = query.basket
basket[int(num)]["qty"] = request.form.get("quantity")

query.basket = []
db.session.commit()

query.basket = query.basket + basket
db.session.commit()

return {"food": True}


@multiple_root_nodes()
def basket_delete(request):
num = request.args.get("basketNo")
Expand All @@ -62,11 +80,6 @@ def basket_delete(request):
def basket_list(request):
zip_code = request.args.get("areaCode")
query = UserOrders.query.filter_by(zip_code=zip_code).first()

# Since basketReset sends the authKey instead of the areaCode, we will append the authKey to the database.
# This is the only request in the channel that does this, which is very very annoying but oh well
query.auth_key = request.args.get("authKey")
db.session.commit()
price = 0

# Subtract the amount of indices in the list by 2 to get the amount we have to range over
Expand Down Expand Up @@ -306,13 +319,13 @@ def shop_one(request):
"amenity": query.amenity,
"menuListCode": 1,
"activate": "on",
"waitTime": 1,
"waitTime": 10,
"timeorder": "y",
"tel": query.phone,
"yoyakuMinDate": 1,
"yoyakuMaxDate": 2,
"yoyakuMaxDate": 30,
"paymentList": {"athing": "Fox Card"},
"interval": 5,
"interval": 30,
"shopStatus": {
"hours": {
"all": {
Expand All @@ -321,7 +334,7 @@ def shop_one(request):
"today": {
"values": {
"hours": {
"start": "01:01:01",
"start": "00:00:00",
"end": "24:59:59",
"holiday": "n",
}
Expand All @@ -330,20 +343,15 @@ def shop_one(request):
"delivery": {
"values": {
"hours": {
"start": "01:01:01",
"start": "00:00:00",
"end": "24:59:59",
"holiday": "n",
}
}
},
},
# Setting values to null will trigger the confirmation screen
"selList": {
"values": {
"option": {
"id": 1,
"name": "Today",
}
}
},
"holiday": "We're on holiday. Back soon!",
"status": {
Expand Down Expand Up @@ -492,16 +500,16 @@ def category_list(request):
return {
"response": {
"Pizza": formulate_restaurant(CategoryTypes.Pizza),
"Bento": formulate_restaurant(CategoryTypes.Bento_Box),
"Sushi": formulate_restaurant(CategoryTypes.Sushi),
"Fish": formulate_restaurant(CategoryTypes.Fish),
"Seafood": formulate_restaurant(CategoryTypes.Seafood),
"American": formulate_restaurant(CategoryTypes.Western),
"Fast": formulate_restaurant(CategoryTypes.Fast_Food),
"Indian": formulate_restaurant(CategoryTypes.Curry),
"Party": formulate_restaurant(CategoryTypes.Party_Food),
"Drinks": formulate_restaurant(CategoryTypes.Drinks),
"Other": formulate_restaurant(CategoryTypes.Others),
# "Bento": formulate_restaurant(CategoryTypes.Bento_Box),
# "Sushi": formulate_restaurant(CategoryTypes.Sushi),
# "Fish": formulate_restaurant(CategoryTypes.Fish),
#"Seafood": formulate_restaurant(CategoryTypes.Seafood),
#"American": formulate_restaurant(CategoryTypes.Western),
#"Fast": formulate_restaurant(CategoryTypes.Fast_Food),
#"Indian": formulate_restaurant(CategoryTypes.Curry),
#"Party": formulate_restaurant(CategoryTypes.Party_Food),
"Drinks": formulate_restaurant(CategoryTypes.Others),
"Other": formulate_restaurant(CategoryTypes.Test),
"Placeholder": formulate_restaurant(CategoryTypes.Others),
}
}
Expand All @@ -512,10 +520,17 @@ def basket_add(request):
zip_code = request.form.get("areaCode")
item_code = request.form.get("itemCode")
qty = request.form.get("quantity")
auth_key = request.form.get("authKey")

query = UserOrders.query.filter_by(zip_code=zip_code).first()
queried_food = ItemList.query.filter_by(item_code=item_code).first()

# Check if the user has a stale basket
if query.auth_key != auth_key:
query.auth_key = auth_key
query.basket = []
db.session.commit()

# Append data to the database
# Temporary hack to allow basket migration.
order: list = query.basket or []
Expand Down Expand Up @@ -546,6 +561,7 @@ def order_done(request):
current_time = datetime.utcnow().strftime("%Y%m%d%H%S")

query.basket = []
query.auth_key = None
db.session.commit()
return {
"Message": {"contents": "Thank you! Your order has been placed."},
Expand Down

0 comments on commit 82c8e60

Please sign in to comment.