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
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