def users_admin_delete(): try: form = request.form db_session = DBSession() user_id = form['id'] user = db_session.query(User).filter_by(id=user_id).first() db_session.delete(user) db_session.commit() db_session.close() return jsonify({'status': 0, 'message': '删除成功'}) except Exception as e: return jsonify({ 'status': 1, 'message': '获取失败', 'error_message': str(e) })
def channel_like(): user = get_login_user() channel_id = request.values.get('id', default=0, type=int) if channel_id == 0: return jsonify({'status': 1, 'message': '错误的id'}) db = DBSession() try: channel = db.query(Channel).filter(Channel.id == channel_id).first() if channel is not None: liked = db.query(Like).filter(Like.user_id == user.id, Like.channel_id == channel_id).first() if liked is not None: db.delete(liked) db.commit() like_count = db.query(Like).filter(Like.channel_id == channel_id).count() return jsonify({ 'status': -1, 'message': 'ok', 'data': {'like_count': int(like_count)} }) else: like = Like(user_id=user.id, status=1, channel_id=channel_id) db.add(like) db.commit() like_count = db.query(Like).filter(Like.channel_id == channel_id).count() return jsonify({ 'status': 0, 'message': 'ok', 'data': {'like_count': int(like_count)} }) else: return jsonify({ 'status': 1, 'message': '消息可能已被删除' }) except Exception as e: db.close() return jsonify({ 'status': 1, 'message': str(e), 'error_message': str(e) })
def follow(): user = get_login_user() channel_user_id = request.values.get('id', default=0, type=int) if channel_user_id == 0: return jsonify({'status': 1, 'message': '错误的id'}) db = DBSession() try: user = db.query(User).filter(User.id == channel_user_id).first() if user is not None: followed = db.query(Follow).filter(user_id=user.id, channel_user_id=channel_user_id).first() if followed is None: db.add(Follow(user_id=user.id, channel_user_id=channel_user_id, status=1)) db.commit() return jsonify({ 'status': 0, 'message': '关注成功' }) else: db.delete(followed) db.commit() return jsonify({ 'status': 0, 'message': '取关成功' }) else: return jsonify({ 'status': 1, 'message': '该用户不存在' }) except Exception as e: db.close() return jsonify({ 'status': 1, 'message': str(e), 'error_message': str(e) })