Ejemplo n.º 1
0
def get_business_reviews(business_id):
    '''
        Business reviews
    '''
    business = Business.get(business_id)
    if business is not None:
        reviews = Review.query.order_by(desc(Review.created_at)).filter_by(
            business_id=Business.get(business_id).id).all()
        if len(reviews) is not 0:
            response = jsonify({
                'status': 'ok',
                'message': str(len(reviews)) + " reviews found",
                'business': Business.serialize_obj(business),
                'reviews': Review.serializer(reviews)
            })
            response.status_code = 200
            return response
        response = jsonify({
            'status': 'ok',
            'message': "No business review yet",
            'business': Business.serialize_obj(business),
            'reviews': []
        })
        response.status_code = 200
        return response
    response = jsonify({
        'status': 'error',
        'message': "This business doesn't exist"
    })
    response.status_code = 404
    return response
Ejemplo n.º 2
0
def add_business_review(business_id):
    '''
        Add Review
    '''
    user_id = token_id(request.headers.get('Authorization'))
    business = Business.get(business_id)
    if business is not None:
        sent_data = request.get_json(force=True)
        valid = validate(sent_data, REVIEW_RULES)
        if valid is not True:
            response = jsonify(status='error',
                               message='Please provide valid details',
                               errors=valid)
            response.status_code = 400
            return response
        review = Review.save({
            'user_id': user_id,
            'description': sent_data['review'],
            'business_id': business.id
        })
        response = jsonify({
            'status': 'ok',
            'message': 'Your review has been sent',
            'review': review.serialize_one,
        })
        response.status_code = 201
        return response
    response = jsonify({
        'status': 'error',
        'message': 'This business doesn\'t exist'
    })
    response.status_code = 400
    return response
Ejemplo n.º 3
0
def get_business(business_id):
    '''
        Get business
    '''
    business = Business.get(business_id)
    if business is not None:
        response = jsonify({
            'status': 'ok',
            'message': 'Business found',
            'business': Business.serialize_obj(business),
        })
        response.status_code = 200
        return response
    response = jsonify({'status': 'error', 'message': "Business not found"})
    response.status_code = 400
    return response