Skip to content

Commit

Permalink
Added dealership table
Browse files Browse the repository at this point in the history
  • Loading branch information
cnscwong committed Jan 11, 2024
1 parent 0ad6799 commit 72cd522
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
20 changes: 20 additions & 0 deletions server/djangoapp/restapis.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ def get_dealers_from_cf(url, **kwargs):

return results

def get_dealers_by_state(url, state):
results = []
# Call get_request with a URL parameter
json_result = get_request(url, state=state)
if json_result:
# Get the row list in JSON as dealers
dealers = json_result
# For each dealer object
for dealer in dealers:
# Get its content in `doc` object
dealer_doc = dealer
# Create a CarDealer object with values in `doc` object
dealer_obj = CarDealer(address=dealer_doc["address"], city=dealer_doc["city"], full_name=dealer_doc["full_name"],
id=dealer_doc["id"], lat=dealer_doc["lat"], long=dealer_doc["long"],
short_name=dealer_doc["short_name"],
st=dealer_doc["st"], zip=dealer_doc["zip"])
results.append(dealer_obj)

return results


# 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):
Expand Down
30 changes: 28 additions & 2 deletions server/djangoapp/templates/djangoapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,34 @@
{% endif %}
</ul>
</nav>
{{ dealer_names }}
<!--Add a dealer table here -->
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">ID</th>
<th scope="col">Dealer Name</th>
<th scope="col">City</th>
<th scope="col">Address</th>
<th scope="col">Zip</th>
<th scope="col">State</th>
</tr>
</thead>
<tbody>
{% if dealers %}
{% for dealer in dealers %}
<tr>
<th scope="row">{{dealer.id}}</th>
<td>{{dealer.short_name}}</td>
<td>{{dealer.city}}</td>
<td>{{dealer.address}}</td>
<td>{{dealer.zip}}</td>
<td>{{dealer.st}}</td>
</tr>
{% endfor %}
{% else %}
No dealers found
{% endif %}
</tbody>
</table>

</body>

Expand Down
6 changes: 1 addition & 5 deletions server/djangoapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,8 @@ def get_dealerships(request):
context = {}
if request.method == "GET":
url = "https://cncw18-3000.theiadockernext-0-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai/dealerships/get"
# Get dealers from the URL
dealerships = get_dealers_from_cf(url)
# Concat all dealer's short name
dealer_names = ' '.join([dealer.short_name for dealer in dealerships])
context["dealer_names"] = dealer_names
# Return a list of dealer short name
context["dealers"] = dealerships
return render(request, 'djangoapp/index.html', context)


Expand Down

0 comments on commit 72cd522

Please sign in to comment.