Commit 134fe888 authored by Willard's avatar Willard

Stall favorite improvements

parent f52be04e
...@@ -169,13 +169,16 @@ def dish_review(dish_id, review_id): ...@@ -169,13 +169,16 @@ def dish_review(dish_id, review_id):
def stall_favorite(stall_id): def stall_favorite(stall_id):
stall = Stall.query.get(stall_id) stall = Stall.query.get(stall_id)
if request.method == 'POST': if request.method == 'POST':
favorited = request.form['favorited'] == u'1' favorited = request.form['favorited'] == 'true'
if stall not in g.user.stall_favorites and favorited: if stall not in g.user.stall_favorites and favorited:
g.user.stall_favorites.append(stall) g.user.stall_favorites.append(stall)
elif stall in g.user.stall_favorites and not favorited: elif stall in g.user.stall_favorites and not favorited:
g.user.stall_favorites.remove(stall) g.user.stall_favorites.remove(stall)
db.session.commit() db.session.commit()
return str(stall in g.user.stall_favorites) return jsonify({
'count': len(stall.favorites),
'favorited': stall in g.user.stall_favorites
})
@app.route('/api/stalls/<int:stall_id>/reviews', methods=['POST']) @app.route('/api/stalls/<int:stall_id>/reviews', 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