From 1b93af34a52960eb384f43f3bc8d12a319c55f6e Mon Sep 17 00:00:00 2001
From: Joe Leaver <joe@radialbog9.uk>
Date: Fri, 26 May 2023 11:16:31 +0000
Subject: [PATCH] Major restructure... again

---
 README.md                |  7 ++++---
 client/config.py.example |  1 +
 client/pizza_palace.py   | 44 +++++++++++++++++++++++++++++++++++++++-
 server/app.py            | 20 ++++++++++++++++--
 server/config.py.example |  1 +
 server/pizza_types.json  | 32 +++++++++++++++++++++++++++++
 6 files changed, 99 insertions(+), 6 deletions(-)
 create mode 100644 client/config.py.example
 create mode 100644 server/config.py.example
 create mode 100644 server/pizza_types.json

diff --git a/README.md b/README.md
index 6a523ec..67d7d63 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,12 @@
 # PizzaPalace
 GCSE Computer Science Challenge
 
-## Installation
+## Running the Server
 ```
 git clone https://github.com/TheJoeCoder/PizzaPalace
 cd PizzaPalace
 pip install -r requirements.txt
-echo "SECRET_KEY = 'SOME_KEY'" > app/config.py
-python -m flask --app=pizza run
+cd server
+cp config.py.example config.py
+python app.py
 ```
\ No newline at end of file
diff --git a/client/config.py.example b/client/config.py.example
new file mode 100644
index 0000000..fcc88b7
--- /dev/null
+++ b/client/config.py.example
@@ -0,0 +1 @@
+api_url="https://api.example.com/"
\ No newline at end of file
diff --git a/client/pizza_palace.py b/client/pizza_palace.py
index 5da131c..c1f644c 100644
--- a/client/pizza_palace.py
+++ b/client/pizza_palace.py
@@ -1 +1,43 @@
-import tkinter
+import json
+from tkinter import ttk, messagebox
+
+## Init
+root = Tk()
+
+## Global Variables
+name = StringVar()
+age = StringVar()
+
+## Subroutines
+def submit(*args):
+    messagebox.showinfo("Not implemented")
+
+## Main program code
+root.title("Pizza Palace")
+
+mainframe = ttk.Frame(root, padding="3 3 12 12")
+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))
+
+for child in mainframe.winfo_children():
+    child.grid_configure(padx=5, pady=5)
+
+name_entry.focus()
+root.bind("<Return>", submit)
+
+root.mainloop()
diff --git a/server/app.py b/server/app.py
index e110e30..12f6d04 100644
--- a/server/app.py
+++ b/server/app.py
@@ -1,10 +1,26 @@
-from flask import Flask, render_template, url_for
+import json
+from flask import Flask, request, jsonify, Response
 
 app = Flask(__name__)
 
+import config
+
+with open("pizza_types.json","r") as f:
+    pizza_types = json.loads(f.read())
+
+open_carts = {}
+
 @app.route("/")
 def hello_world():
-    return render_template("index.html")
+    return "{\"status\":200, \"message\": \"ok\"}", 200
+
+@app.route("/pizzas", methods=["GET"])
+def get_pizzas():
+    return jsonify(pizza_types), 200
+
+@app.route("/cart/open", methods=["POST"])
+def open_cart():
+    return "{\"status\":404, \"message\": \"not implemented\"}", 404
 
 if __name__ == "__main__":
     app.run()
\ No newline at end of file
diff --git a/server/config.py.example b/server/config.py.example
new file mode 100644
index 0000000..1fed35b
--- /dev/null
+++ b/server/config.py.example
@@ -0,0 +1 @@
+webhook = "https://example.com/webhook"
\ No newline at end of file
diff --git a/server/pizza_types.json b/server/pizza_types.json
new file mode 100644
index 0000000..866ed59
--- /dev/null
+++ b/server/pizza_types.json
@@ -0,0 +1,32 @@
+[
+    {
+        "id": "margherita",
+        "name": "Margherita",
+        "cost_pp": 3,
+        "stuffed_pp": 1
+    },
+    {
+        "id": "pepperoni",
+        "name": "Pepperoni",
+        "cost_pp": 3,
+        "stuffed_pp": 1
+    },
+    {
+        "id": "hawaiian",
+        "name": "Hawaiian",
+        "cost_pp": 4,
+        "stuffed_pp": 1
+    },
+    {
+        "id": "buffalo_chicken",
+        "name": "Buffalo Chicken",
+        "cost_pp": 5,
+        "stuffed_pp": 1
+    },
+    {
+        "id": "veg_feast",
+        "name": "Vegetable Feast",
+        "cost_pp": 4,
+        "stuffed_pp": 1
+    }
+]
\ No newline at end of file
-- 
GitLab