lundi 31 août 2015

Multiple Entity update in a single PUT method in Rest Service

order item table

order_item_id
order_id
quantity
unit_price
shipping_price
business_id
workflow_id
delivery_id
item_id

Orders table

billing_address_id
shipping_address_id
payment_mode
total_price
shipping_price
customer_id 
order_id

Logistics

   `id` 
  `tracking_id` 
  `partner_id`  
  `tracking_status` 
  `create_TS`  
  `update_TS`  
  `order_item_id` 

order status history

 `order_item_id` 
  `workflow_id`  
  `partner_status` 
  `create_TS`  
  `update_TS` 

There are 3 types of users in my system. Admin, Merchant and Customer. Each one of them can update the status of an item in a order. Each status update triggers updates to multiple tables and different logic.

Eg: Order life cycle is as follows pending -> approved -> cancel/shipped -> Delivered -> returned/exchanged

When the admin approves an order( after stock verification as our inventory is not yet real time) I will have to update the above 4 tables.

In some scenarios , I don't have to update one or two tables. eg, If the customer cancels the order before the admin can approve, then nothing to update in the logistics table.

In some scenarios, eg: if the admin approves one item in the order and cancels the other item, then the update logic varies.

Currently I have a method called updateOrder for all the three roles in their corresponding implementation classes.

But the logic makes me to put a lot of if..else conditions and loops. Is there a design pattern I can follow?

Or how in general are the PUT methods handled involving update to multiple tables

Aucun commentaire:

Enregistrer un commentaire