Commit 6c93b87c authored by Willard's avatar Willard

Add favorite toggle for dish and stall

parent fec6a8dc
...@@ -93,20 +93,32 @@ def get_auth_token(): ...@@ -93,20 +93,32 @@ def get_auth_token():
token = generate_token(g.user) token = generate_token(g.user)
return jsonify({'token': token.decode('ascii'), 'duration': 600}) return jsonify({'token': token.decode('ascii'), 'duration': 600})
@app.route('/api/dish/<int:dish_id>/favorite', methods=['POST']) @app.route('/api/dish/<int:dish_id>/favorite', methods=['GET'])
@auth.login_required @auth.login_required
def favorite_dish(dish_id): def favorite_dish(dish_id):
pass dish = Dish.query.get(dish_id)
if dish not in g.user.dish_favorites:
g.user.dish_favorites.append(dish)
else:
g.user.dish_favorites.remove(dish)
db.session.commit()
return str(dish in g.user.dish_favorites)
@app.route('/api/dish/<int:dish_id>/review', methods=['POST']) @app.route('/api/dish/<int:dish_id>/review', methods=['POST'])
@auth.login_required @auth.login_required
def review_dish(dish_id): def review_dish(dish_id):
pass pass
@app.route('/api/stall/<int:stall_id>/favorite', methods=['POST']) @app.route('/api/stall/<int:stall_id>/favorite', methods=['GET'])
@auth.login_required @auth.login_required
def favorite_stall(stall_id): def favorite_stall(stall_id):
pass stall = Stall.query.get(stall_id)
if stall not in g.user.stall_favorites:
g.user.stall_favorites.append(stall)
else:
g.user.stall_favorites.remove(stall)
db.session.commit()
return str(stall in g.user.stall_favorites)
@app.route('/api/stall/<int:stall_id>/review', methods=['POST']) @app.route('/api/stall/<int:stall_id>/review', methods=['POST'])
@auth.login_required @auth.login_required
......
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