Skip to content

Commit 28083ea

Browse files
feat: Added the Feature to Have Multiple Pizza's in a Singular Order
1 parent f4dadaf commit 28083ea

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

FOS/services/order_service.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from ..models.user import User
2+
from ..models.pizza import Pizza
23
import time
34

45

@@ -8,10 +9,14 @@ def __init__(self, user: User):
89
self.state = None
910
self.observers = []
1011
self.order_id = f"ORD-{hash(user.username)}-{hash(str(time.time()))}"[:10]
12+
self.pizzas = [] # List to store multiple pizzas
1113

1214
def attach(self, observer):
1315
self.observers.append(observer)
1416

1517
def notify_observers(self, message: str):
1618
for observer in self.observers:
1719
observer.update(self.order_id, message, self.state)
20+
21+
def add_pizza(self, pizza: Pizza):
22+
self.pizzas.append(pizza)

FOS/user_interface.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,17 @@ def add_on_decorators(self, pizza_builder):
265265

266266
return pizza_builder
267267

268-
def pay(self, pizza: Pizza, user: User):
269-
if isinstance(pizza, str):
270-
pizza = PizzaBuilder(pizza).build()
268+
def review_order(self):
269+
print(f"\n{Fore.YELLOW}Current Order:{Style.RESET_ALL}")
270+
print(self.MENU_BORDER)
271+
for idx, pizza in enumerate(self.order.pizzas, 1):
272+
print(f"{Fore.GREEN}{idx}.{Style.RESET_ALL} {pizza}")
273+
print(self.MENU_BORDER)
274+
275+
def pay(self, order: Order, user: User):
276+
total_price = sum(pizza.price.price for pizza in order.pizzas)
271277
self.print_header("Payment")
272-
print(f"{Fore.GREEN}Total Amount:{Style.RESET_ALL} ${pizza.price.price:.2f}")
278+
print(f"{Fore.GREEN}Total Amount:{Style.RESET_ALL} ${total_price:.2f}")
273279
print(
274280
f"{Fore.YELLOW}Available Loyalty Points:{Style.RESET_ALL} {user.get_loyalty}"
275281
)
@@ -297,7 +303,7 @@ def pay(self, pizza: Pizza, user: User):
297303
print("Please enter a number between 1-3.")
298304

299305
# Initialize payment with selected strategy
300-
payment = Payment(pizza.price, user, payment_strategies[choice])
306+
payment = Payment(total_price, user, payment_strategies[choice])
301307

302308
use_loyalty = (
303309
input("Do you want to use your loyalty points? (y/n)").lower() == "y"
@@ -410,13 +416,19 @@ async def main(self):
410416
user = self.authentication()
411417
while True:
412418
self.order = Order(user)
413-
pizza = self.add_on_decorators(self.home_page(user)).build()
414-
user.add_order(pizza)
419+
while True:
420+
pizza = self.add_on_decorators(self.home_page(user)).build()
421+
self.order.add_pizza(pizza)
422+
user.add_order(pizza)
423+
self.review_order()
424+
if input("Add another pizza to this order? (y/n): ").lower() == "n":
425+
break
415426
tracker = self.get_tracker()
416-
self.pay(pizza, user)
427+
self.pay(self.order, user)
417428
print(f"\n{Fore.GREEN}Payment successful!{Style.RESET_ALL}")
418429
tracking = asyncio.create_task(self.tracking(self.order, tracker))
419430
tracking = await tracking
420-
self.feedback(pizza)
421-
if input("Order Another Pizza?").lower().lower() == "n":
431+
for pizza in self.order.pizzas:
432+
self.feedback(pizza)
433+
if input("Place another order? (y/n): ").lower() == "n":
422434
break

0 commit comments

Comments
 (0)