views:

153

answers:

2

Example: an Order object (aggregate root) has a collection of OrderLine objects (child entities). What's the URL add an OrderLine to an Order? Take into consideration the difference between using the aggregate roots' controller and having a separate controller for the child entity.

1: http://example.com/orders/add-orderline?order-id=42&product-id=12&quantity=2

or

2: http://example.com/order-lines/add?order-id=42&product-id=12&quantity=2

Thanks!

+1  A: 

Can an order line exist independently of an order? Probably not, therefore, I would make an action on the order controller.

I would prefer the following:

http://example.com/orders/addline?order-id=42&product-id=12&quantity=2

or even addproduct if a product can only exist on one line in an order.

Presumably, this would render a view of the entire order on success, which is another reason to have it on the order controller.

tvanfosson
+1  A: 

Follow your domain model.

Does an Orderline object exist, and can actions be taken with it? (Not object in code, object in real-life according to the domain.) Most likely not, or it would be the aggregate root.

The Order object exists, and you are adding an Orderline to it. So the root object is the Order, with the action of adding an Orderline.

Your URL route would follow that, with a controller for the object, and an action of adding an Orderline.

From your examples this is the one that follows that logic:

http://example.com/orders/add-orderline?order-id=42&product-id=12&quantity=2
Carlton Jenke