diff --git a/app.py b/app.py index e464c03..efd3556 100644 --- a/app.py +++ b/app.py @@ -42,16 +42,17 @@ def serve_monster_sprite(selected_monster): def serve_favicon(): return send_from_directory( '','static/img/favicon.ico') -@app.route("/get_families") -def get_families(): +#API Calls + +@app.route("/api/families") +def json_families(): cursor = g.db.cursor() cursor.execute("SELECT DISTINCT name FROM families") families = [row[0] for row in cursor.fetchall()] return jsonify(families) - -@app.route("/get_monsters") -def get_monsters(): +@app.route("/api/monsters") +def json_monsters(): selected_family = request.args.get("family") cursor = g.db.cursor() @@ -69,6 +70,7 @@ def get_monsters(): monsters = [row[0] for row in cursor.fetchall()] return jsonify(monsters) +# Render HTML Templates @app.route("/monster/") def monster_stats(monster_name): diff --git a/static/js/indexListener.js b/static/js/indexListener.js index 948f598..148091c 100644 --- a/static/js/indexListener.js +++ b/static/js/indexListener.js @@ -6,7 +6,7 @@ document.addEventListener("DOMContentLoaded", function () { updateMonsterDropdownByFamily(); // Fetch families data from the server and populate families dropdown - fetch("/get_families") + fetch("/api/families") .then(response => response.json()) .then(data => { populateDropdown(familyDropdown, data); diff --git a/static/js/updateMonsterDropdownByFamily.js b/static/js/updateMonsterDropdownByFamily.js index effe0ec..b580854 100644 --- a/static/js/updateMonsterDropdownByFamily.js +++ b/static/js/updateMonsterDropdownByFamily.js @@ -2,7 +2,7 @@ function updateMonsterDropdownByFamily() { const selectedFamily = familyDropdown.value; // Fetch monsters data from the server based on the selected family - fetch(`/get_monsters?family=${selectedFamily}`) + fetch(`/api/monsters?family=${selectedFamily}`) .then(response => response.json()) .then(data => populateDropdown(monsterDropdown, data)) .catch(error => console.error("Error fetching monsters:", error));