-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
food_delivery_service_demo.py
64 lines (54 loc) · 2.43 KB
/
food_delivery_service_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from food_delivery_service import FoodDeliveryService
from customer import Customer
from restaurant import Restaurant
from menu_item import MenuItem
from order_item import OrderItem
from delivery_agent import DeliveryAgent
from order import OrderStatus
class FoodDeliveryServiceDemo:
@staticmethod
def run():
service = FoodDeliveryService.get_instance()
# Register customers
customer1 = Customer("C001", "Alice Johnson", "[email protected]", "555-1234")
customer2 = Customer("C002", "Bob Smith", "[email protected]", "555-5678")
service.register_customer(customer1)
service.register_customer(customer2)
# Register restaurants
menu1 = [
MenuItem("M001", "Pizza", "Cheese Pizza", 10.0),
MenuItem("M002", "Burger", "Beef Burger", 8.0),
]
menu2 = [
MenuItem("M003", "Sushi", "Salmon Sushi", 12.0),
MenuItem("M004", "Ramen", "Tonkotsu Ramen", 15.0),
]
restaurant1 = Restaurant("R001", "Pizza Place", "123 Main St", menu1)
restaurant2 = Restaurant("R002", "Sushi House", "456 Oak St", menu2)
service.register_restaurant(restaurant1)
service.register_restaurant(restaurant2)
# Register delivery agents
agent1 = DeliveryAgent("D001", "Charlie Brown", "555-8765")
agent2 = DeliveryAgent("D002", "Daisy Duck", "555-4321")
service.register_delivery_agent(agent1)
service.register_delivery_agent(agent2)
# Place an order
items = [OrderItem(menu1[0], 2), OrderItem(menu1[1], 1)]
order = service.place_order(customer1.id, restaurant1.id, items)
if order:
print(f"Order placed: {order.id}")
# Update order status
service.update_order_status(order.id, OrderStatus.CONFIRMED)
print(f"Order status updated to {OrderStatus.CONFIRMED}")
# Check order details
print(f"Order details: {order.id}, status: {order.status}, items: {[(item.item.name, item.quantity) for item in order._items]}")
# Check available restaurants
available_restaurants = service.get_available_restaurants()
print("Available restaurants:")
for restaurant in available_restaurants:
print(f"- {restaurant.name}")
# Cancel an order
service.cancel_order(order.id)
print(f"Order cancelled: {order.id}")
if __name__ == "__main__":
FoodDeliveryServiceDemo.run()