diff --git a/functions/reviews.py b/functions/reviews.py index 9653033e3c..8194a7121e 100644 --- a/functions/reviews.py +++ b/functions/reviews.py @@ -1,6 +1,6 @@ from cloudant.client import Cloudant from cloudant.query import Query -from flask import Flask, jsonify, request +from flask import Flask, jsonify, request, abort import atexit #Add your Cloudant service credentials here @@ -56,6 +56,7 @@ def post_review(): # Extract review data from the request JSON review_data = request.json + print(review_data) # Validate that the required fields are present in the review data required_fields = ['id', 'name', 'dealership', 'review', 'purchase', 'purchase_date', 'car_make', 'car_model', 'car_year'] diff --git a/server/db.sqlite3 b/server/db.sqlite3 index 1d34d38a3b..f9855cc1fb 100644 Binary files a/server/db.sqlite3 and b/server/db.sqlite3 differ diff --git a/server/djangoapp/restapis.py b/server/djangoapp/restapis.py index 87f212a385..acab121efc 100644 --- a/server/djangoapp/restapis.py +++ b/server/djangoapp/restapis.py @@ -39,6 +39,26 @@ def get_request(url, api_key=None, **kwargs): # Create a `post_request` to make HTTP POST requests # e.g., response = requests.post(url, params=kwargs, json=payload) +def post_request(url, json_payload, **kwargs): + print("POST to {} ".format(url)) + response = requests.post( + url, + params=kwargs, + data=json.dumps(json_payload), + headers={'Content-Type': 'application/json'}, + ) + + status_code = response.status_code + print("With status {} ".format(status_code)) + print("Response text: ", response.text) + + try: + json_data = json.loads(response.text) + return json_data + except json.JSONDecodeError: + print("Error decoding JSON response") + return None + # Create a get_dealers_from_cf method to get dealers from a cloud function @@ -70,23 +90,41 @@ def get_dealers_from_cf(url, **kwargs): return results +# def get_dealer_by_id_from_cf(url, dealerId): +def get_dealer_by_id_from_cf(url, dealer_id): + json_result = get_request(url, id=dealer_id) + if json_result: + print(json_result,'dealer_get') + dealer = json_result[0] + + dealer_obj = CarDealer( + address=dealer["address"], + city=dealer["city"], + full_name=dealer["full_name"], + id=dealer["id"], + lat=dealer["lat"], + long=dealer["long"], + short_name=dealer["short_name"], + st=dealer["st"], + zip=dealer["zip"] + ) + return dealer_obj + # Create a get_dealer_reviews_from_cf method to get reviews by dealer id from a cloud function -# def get_dealer_by_id_from_cf(url, dealerId): # - Call get_request() with specified arguments # - Parse JSON results into a DealerView object list def get_dealer_reviews_from_cf(url, dealer_id): results = [] # Call get_request with a URL parameter - json_result = get_request(url, api_key=None, id=dealer_id) - print("IT IS IN GET DEALER REVIEWS FROM CF") + json_result = get_request(url, api_key=None, dealer_id=dealer_id) if isinstance(json_result, list): reviews = json_result # Print or log the reviews for debugging print(reviews) # For each dealer object for review in reviews: - # Get its content in `doc` object + # Get its content review_obj = DealerReview( dealership=review.get("dealership", ""), name=review.get("name", ""), diff --git a/server/djangoapp/templates/djangoapp/add_review.html b/server/djangoapp/templates/djangoapp/add_review.html index 768ddf508c..f8e2da696e 100644 --- a/server/djangoapp/templates/djangoapp/add_review.html +++ b/server/djangoapp/templates/djangoapp/add_review.html @@ -10,7 +10,48 @@ -
- - + + +