Commit 44616206 authored by Willard's avatar Willard

Minor api tweaks, default value to search filters

parent 3aacfcdf
......@@ -23,9 +23,13 @@ def cuisines():
@app.route('/api/search/dish')
def search():
name = request.args.get('name')
types = [int(s) for s in request.args.get('type_filters')]
cuisines = [int(s) for s in request.args.get('cuisine_filters')]
locations = [int(s) for s in request.args.get('location_filters')]
type_filters = request.args.get('type_filters') or [i for i in range(1, len(DishType.query.all()) + 1)]
cuisine_filters = request.args.get('cuisine_filters') or [i for i in range(1, len(DishCuisine.query.all()) + 1)]
location_filters = request.args.get('location_filters') or [i for i in range(1, len(Location.query.all()) + 1)]
types = [int(s) for s in type_filters]
cuisines = [int(s) for s in cuisine_filters]
locations = [int(s) for s in location_filters]
result = Dish.query.filter(
Dish.name.like('%' + name + '%'),
......@@ -33,13 +37,7 @@ def search():
).join(Dish.stall).filter(Stall.location_id.in_(locations)).all()
data = []
for dish in result:
data.append({
'id': dish.id,
'name': dish.name,
'price': dish.price,
'stall_name': dish.stall.name,
'image_path': dish.image_path
})
data.append(dish_obj(dish))
return jsonify(data)
......@@ -169,14 +167,24 @@ def stall_review(stall_id, review_id):
review = Stall.query.get(stall_id).reviews.filter_by(id=review_id).first()
return jsonify(review_obj(review))
def dish_obj(dish):
if dish is None:
return None
return {
'id': dish.id,
'name': dish.name,
'price': dish.price,
'stall_name': dish.stall.name,
'image_path': dish.image_path
}
def review_obj(review):
if review is None:
return ''
review = {
return None
return {
'title': review.title,
'body': review.body,
'rating': review.rating,
'user_id': review.user_id,
'dish_id': review.dish_id
}
\ No newline at end of file
return review
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment