Exemplo n.º 1
0
 def get_reviews(id):
     businesses = Business.check_business_exists(id)
     all_business = []
     for business in businesses:
         obj = {
             "name": business.name
         }
         all_business.append(obj)
     if not all_business:
         message = "cannot get review business that does not exist"
         response = jsonify({"message": message, "status_code": 404})
         # 404 if business does not exist
         response.status_code = 404
         return response    
     reviews = Review.get_business_review(id)
     all_reviews = []
     for review in reviews:
         obj = {
             
             "opinion": review.opinion,
             "rating": review.rating
         }
         all_reviews.append(obj)
     if not all_reviews:
         message = "no reviews available"
         response = jsonify({"message": message, "status_code": 404})
         # 404 if business does not exist
         response.status_code = 404
         return response
     response = jsonify(all_reviews)
     response.status_code = 200
     return response    
Exemplo n.º 2
0
 def add_review(id):
     businesses = Business.check_business_exists(id)
     all_business = []
     for business in businesses:
         obj = {
             "name": business.name
         }
         all_business.append(obj)
     if not all_business:
         message = "cannot add review business that does not exist"
         response = jsonify({"message": message, "status_code": 404})
         # 404 if business does not exist
         response.status_code = 404
         return response
     opinion = str(request.data.get('opinion', ''))
     rating = int(request.data.get('rating', ''))
     if rating and opinion:
         new_review = Review(opinion=opinion, rating=rating, business_main=id)
         new_review.save()
         message = "succesfully added the review"
         response = jsonify({"message": message})
         response.status_code = 201
         return response
     message = "make sure the opinion and rating are included"
     response = jsonify({"message": message, "status_code": 400})
     response.status_code = 400
     return response