Skip to content

Commit 65f5682

Browse files
committed
Order now assigns a driver that works in the same area where the customer ordered from
1 parent b99f204 commit 65f5682

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

client/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ def setup():
5353
dwight_schrute = save_new_driver("Dwight", "Schrute", "Sphinx quarter")
5454
jim_halpert = save_new_driver("Jim", "Halpert", "Céramique")
5555
victor_htema = save_new_driver("Victor", "Htema", "Jeker quarter")
56-
francisca_van_dijk = save_new_driver("Britt", "Van Dijk", "Sint Pieter")
56+
francisca_van_dijk = save_new_driver("Francisca", "Van Dijk", "Sint Pieter")

models/mysql_model.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ def show_ingredients(name):
9898

9999
def save_new_order(customer, order_items):
100100
new_order_items = []
101-
driver = get_first_available_driver()
101+
customer_address = customer["address"]
102+
customer_area = customer_address["area"]
103+
driver = get_first_available_driver(customer_area)
102104
driver_id = driver.id
103105
driver.available = False
104106
address = customer["address"]
@@ -188,6 +190,11 @@ def find_order(order_id):
188190
return order
189191

190192

193+
def find_address(address_id):
194+
address = Address.query.filter_by(id=address_id).first_or_404(description='There is no address with id {}'.format(address_id))
195+
return address
196+
197+
191198
def find_driver(driver_id):
192199
driver = Driver.query.filter_by(id=driver_id) \
193200
.first_or_404(description='There is no driver with id {}'.format(driver_id))
@@ -225,12 +232,13 @@ def are_there_available_drivers():
225232
return False
226233

227234

228-
def get_first_available_driver():
235+
def get_first_available_driver(area):
229236
if are_there_available_drivers():
230237
drivers = db.session.query(Driver)
231238
for driver in drivers:
232-
if driver.available:
239+
if driver.available and driver.working_area == area:
233240
return driver
241+
raise Exception("There are no available drivers for your area.")
234242
else:
235243
raise Exception("There are no available drivers.")
236244

0 commit comments

Comments
 (0)