Example #1
0
def rating():
    app.logger.debug('Args: {}'.format(request.args))
    cost = float(request.args.get('cost', 0))
    cleanliness = float(request.args.get('cleanliness', 0))
    service = float(request.args.get('service', 0))
    food = float(request.args.get('food', 0))
    user_id = int(request.args.get('user_id', 0))
    restaurant_id = int(request.args.get('restaurant_id', 0))
    r = Restaurant.query.filter_by(id=restaurant_id).first_or_404()
    user = User.query.filter_by(id=user_id).first_or_404()
    if request.method == 'POST':
        rating = Rating.create(cost, food, cleanliness,\
                service, restaurant_id, user_id)
        if rating:
            return json_response({'response': 'Created', 'id': rating.id})
        else:
            return json_response(
                {'response': 'Cannot post within a month for same restaurant'},
                400)
    elif request.method == 'PUT':
        result = Rating.update(cost, food, cleanliness,\
                service, restaurant_id, user_id)
        return json_response({'response': 'Updated', 'id': result.id})