Complete the code to define an aggregate root in a microservice.
class Order([1]): def __init__(self, order_id): self.order_id = order_id self.items = []
The aggregate root controls the lifecycle of entities within it. Here, AggregateRoot is the correct base class.
Complete the code to add an entity inside an aggregate.
class OrderItem: def __init__(self, product_id, quantity): self.product_id = product_id self.quantity = [1]
The quantity attribute stores how many units of the product are ordered.
Fix the error in the method that adds an entity to the aggregate.
class Order: def __init__(self): self.items = [] def add_item(self, item): if item.product_id not in [i.product_id for i in self.items]: self.items.[1](item)
The append method adds a single item to the list. Using 'extend' or 'insert' is incorrect here.
Fill both blanks to correctly check entity existence and update quantity.
def update_item_quantity(self, product_id, quantity): for item in self.items: if item.[1] == product_id: item.[2] = quantity return True return False
We compare product_id to find the item, then update its quantity.
Fill all three blanks to create a dictionary of product IDs and quantities from entities.
def get_items_summary(self): return {item.[1]: item.[2] for item in self.items if item.[3] > 0}
The dictionary maps product_id to quantity, filtering items with quantity > 0.