Skip to content

Commit

Permalink
Merge pull request #13 from pulkitsapra/pulkit_try
Browse files Browse the repository at this point in the history
Fixed order input to accept quantity along with item name
  • Loading branch information
DiptoChakrabarty authored Oct 5, 2020
2 parents ed1a8a5 + 03a84ff commit 2a67eff
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions resource/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ class Order(Resource):
def post(cls):
data= request.get_json()
items=[]
item_quantity = Counter(data["items"])
ordered_list = data['items'] # list of dictionaries

for name,count in item_quantity.most_common():
for ordered_item in data['items']:
name = ordered_item['name']
count = ordered_item['qty']
res = ItemModel.find_by_name(name)
if not res:
return {"msg": "Item not present {}".format(name)},404
items.append(ItemsInOrder(item_id=ItemModel.find_id(name),quantity=count))
print(items)



order = OrderModel(items=items,status="pending")
order.save_to_db() #save orders to database

Expand Down

0 comments on commit 2a67eff

Please sign in to comment.