From fd317caffa1b215553d98c545331d5001dbe3117 Mon Sep 17 00:00:00 2001 From: Joe Leaver <joe@radialbog9.uk> Date: Fri, 26 May 2023 11:23:30 +0000 Subject: [PATCH] Make open cart function actually work in backend --- client/pizza_palace.py | 11 ----------- server/app.py | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/client/pizza_palace.py b/client/pizza_palace.py index c1f644c..bc1247f 100644 --- a/client/pizza_palace.py +++ b/client/pizza_palace.py @@ -20,17 +20,6 @@ mainframe.grid(column=0, row=0, sticky=(N, W, E, S)) root.columnconfigure(0, weight=1) root.rowconfigure(0, weight=1) - -name_label = ttk.Label(mainframe, text="Pizza Type: ") -name_label.grid(column=1, row=1, sticky=(W, E)) -name_entry = ttk.Entry(mainframe, width=10, textvariable=name) -name_entry.grid(column=2, row=1, sticky=(W, E)) - -age_label = ttk.Label(mainframe, text="Age: ") -age_label.grid(column=1, row=2, sticky=(W, E)) -age_entry = ttk.Entry(mainframe, width=10, textvariable=age) -age_entry.grid(column=2, row=2, sticky=(W, E)) - submit_button = ttk.Button(mainframe, text="Go!", command=submit) submit_button.grid(column=2, row=3, sticky=(W, E)) diff --git a/server/app.py b/server/app.py index 12f6d04..12e0acd 100644 --- a/server/app.py +++ b/server/app.py @@ -1,6 +1,8 @@ -import json +import json, uuid, logging from flask import Flask, request, jsonify, Response +logger = logging.Logger(__name__) + app = Flask(__name__) import config @@ -12,15 +14,25 @@ open_carts = {} @app.route("/") def hello_world(): + # Return OK message return "{\"status\":200, \"message\": \"ok\"}", 200 @app.route("/pizzas", methods=["GET"]) def get_pizzas(): + # Return pizza types return jsonify(pizza_types), 200 @app.route("/cart/open", methods=["POST"]) def open_cart(): - return "{\"status\":404, \"message\": \"not implemented\"}", 404 + # Generate cart id and ensure it is unique + foundunique = False + while not foundunique: + cart_id = str(uuid.uuid4()) + if cart_id in open_carts: + logger.warn("Regenerating UUID for new cart - prev " + cart_id) + cart_key = str(uuid.uuid4()) + # TODO append cart to list and send to user + return "{\"status\":200, \"id\": \"not implemented\", \"key\": \"not implemented\"}", 200 if __name__ == "__main__": app.run() \ No newline at end of file -- GitLab