@bp.route('/<int:uid>/like', methods=('POST',))
@require_user
def like(uid):
 like = LikeTopic.query.filter_by(account_id=g.user.id, topic_id=uid).first()
 if like:
  db.session.delete(like)
  db.session.commit()
  return jsonify(status='ok', action='cancel')
 like = LikeTopic(account_id=g.user.id, topic_id=uid)
 db.session.add(like)
 db.session.commit()
 return jsonify(status='ok', action='like')

@ bp . route ( '/<int:uid>/like' , methods = ( 'POST' , ) ) @ require_user def like ( uid ) : like = LikeTopic . query . filter_by ( account_id = g . user . id , topic_id = uid ) . first ( ) if like : db . session . delete ( like ) db . session . commit ( ) return jsonify ( status = 'ok' , action = 'cancel' ) like = LikeTopic ( account_id = g . user . id , topic_id = uid ) db . session . add ( like ) db . session . commit ( ) return jsonify ( status = 'ok' , action = 'like' )
like a topic .