Commit 44616206 authored by Willard's avatar Willard

Minor api tweaks, default value to search filters

parent 3aacfcdf
...@@ -23,9 +23,13 @@ def cuisines(): ...@@ -23,9 +23,13 @@ def cuisines():
@app.route('/api/search/dish') @app.route('/api/search/dish')
def search(): def search():
name = request.args.get('name') name = request.args.get('name')
types = [int(s) for s in request.args.get('type_filters')] type_filters = request.args.get('type_filters') or [i for i in range(1, len(DishType.query.all()) + 1)]
cuisines = [int(s) for s in request.args.get('cuisine_filters')] cuisine_filters = request.args.get('cuisine_filters') or [i for i in range(1, len(DishCuisine.query.all()) + 1)]
locations = [int(s) for s in request.args.get('location_filters')] 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( result = Dish.query.filter(
Dish.name.like('%' + name + '%'), Dish.name.like('%' + name + '%'),
...@@ -33,13 +37,7 @@ def search(): ...@@ -33,13 +37,7 @@ def search():
).join(Dish.stall).filter(Stall.location_id.in_(locations)).all() ).join(Dish.stall).filter(Stall.location_id.in_(locations)).all()
data = [] data = []
for dish in result: for dish in result:
data.append({ data.append(dish_obj(dish))
'id': dish.id,
'name': dish.name,
'price': dish.price,
'stall_name': dish.stall.name,
'image_path': dish.image_path
})
return jsonify(data) return jsonify(data)
...@@ -169,14 +167,24 @@ def stall_review(stall_id, review_id): ...@@ -169,14 +167,24 @@ def stall_review(stall_id, review_id):
review = Stall.query.get(stall_id).reviews.filter_by(id=review_id).first() review = Stall.query.get(stall_id).reviews.filter_by(id=review_id).first()
return jsonify(review_obj(review)) 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): def review_obj(review):
if review is None: if review is None:
return '' return None
review = { return {
'title': review.title, 'title': review.title,
'body': review.body, 'body': review.body,
'rating': review.rating, 'rating': review.rating,
'user_id': review.user_id, 'user_id': review.user_id,
'dish_id': review.dish_id 'dish_id': review.dish_id
} }
return review \ No newline at end of file
\ 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