Пример #1
0
def restore():

    validated = validate_jwt(request)
    if (validated):
        return validated
    else:
        return jsonify({'validated': False})
Пример #2
0
def restore():
    auth_header = request.headers['Authorization']
    validated = validate_jwt(request)
    # print(validated,"THIS IS VALLEYDATED")
    if (validated):
        return jsonify(validated)
    else:
        return jsonify(None)
Пример #3
0
def user_follows(user_id):
    validated = validate_jwt(request)
    jwt_user_id = validated['user']['id']
    if (jwt_user_id != int(user_id)):
        return jsonify(False)
    follows = Follow.query.filter(Follow.user_id == int(user_id)).all()
    follows_dict = [follow.wine.to_dict() for follow in follows]

    return jsonify(follows_dict)
Пример #4
0
def wine_details(id):
    wine = Wine.query.get(id).to_dict()
    if not wine:
        pass

    # Next part is to see if the user follows the wine
    validated = validate_jwt(request)
    user_id = validated['user']['id']
    user_follows = None
    follow = Follow.query.filter(Follow.user_id == user_id,
                                 Follow.wine_id == wine['id']).first()
    if follow:
        user_follows = True
    else:
        user_follows = False

    wine['user_follows'] = user_follows

    return jsonify(wine)
Пример #5
0
def toggle_follow():
    data = request.json
    wine_id = data

    validated = validate_jwt(request)
    user_id = validated['user']['id']

    # Check to see if the user follows already or not
    follow = Follow.query.filter(Follow.wine_id == wine_id,
                                 Follow.user_id == user_id).first()

    following = None
    if not follow:
        new_follow = Follow(user_id=user_id, wine_id=wine_id)
        db.session.add(new_follow)
        following = True
    else:
        db.session.delete(follow)
        following = False
    db.session.commit()

    return jsonify(following)
Пример #6
0
def restore():
    validated = validate_jwt(request)
    if (validated):
        return validated
    else:
        return jsonify(None)