Add JSON representation for dish
This commit is contained in:
parent
f60c1d180c
commit
b8eb40e448
1 changed files with 33 additions and 1 deletions
|
@ -3,7 +3,7 @@ import os
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
import typing
|
from typing import Optional
|
||||||
|
|
||||||
from flask import Flask, render_template, make_response
|
from flask import Flask, render_template, make_response
|
||||||
from flask import request, jsonify
|
from flask import request, jsonify
|
||||||
|
@ -19,6 +19,9 @@ from models import Order
|
||||||
# import views
|
# import views
|
||||||
from views.order import get_orders
|
from views.order import get_orders
|
||||||
|
|
||||||
|
import json
|
||||||
|
from flask import jsonify
|
||||||
|
|
||||||
general_bp = Blueprint("general_bp", __name__)
|
general_bp = Blueprint("general_bp", __name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,6 +134,35 @@ def location(location_id) -> str:
|
||||||
return render_template("location.html", location=loc, title=loc.name)
|
return render_template("location.html", location=loc, title=loc.name)
|
||||||
|
|
||||||
|
|
||||||
|
@general_bp.route("/location/<location_id>/<dish_id>")
|
||||||
|
def location_dish(location_id, dish_id) -> str:
|
||||||
|
loc: Optional[Location] = first(filter(lambda l: l.id == location_id, location_definitions))
|
||||||
|
if loc is None:
|
||||||
|
abort(404)
|
||||||
|
dish = loc.dish_by_id(dish_id)
|
||||||
|
if dish is None:
|
||||||
|
abort(404)
|
||||||
|
return jsonify([
|
||||||
|
{
|
||||||
|
"type": c[0],
|
||||||
|
"id": c[1].id,
|
||||||
|
"name": c[1].name,
|
||||||
|
"description": c[1].description,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"id": o.id,
|
||||||
|
"name": o.name,
|
||||||
|
"description": o.description,
|
||||||
|
"price": o.price,
|
||||||
|
"tags": o.tags
|
||||||
|
}
|
||||||
|
for o in c[1].options
|
||||||
|
]
|
||||||
|
}
|
||||||
|
for c in dish.choices
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
@general_bp.route("/about/")
|
@general_bp.route("/about/")
|
||||||
def about() -> str:
|
def about() -> str:
|
||||||
"Generate the about view"
|
"Generate the about view"
|
||||||
|
|
Loading…
Reference in a new issue