Conversation
There was a problem hiding this comment.
@melinayg Good job! The commit history is clean, the PR description is great, and you clearly have a good grasp on API development. Make sure to read the comment below for other changes.
Additionally, it is important to update docstrings! Sorry but this was slightly evil of me, since I didn't mention it explicilty in the ticket, but updating docstrings to reflect changes in functionality (in this case, service + router for create_order) is very important!
Overall great job - once you make these changes request another review!
| item_total = chocolate["price"] * item["quantity"] | ||
| total_price += item_total | ||
| # Deduct stock | ||
| chocolate["stock_quantity"] -= item["quantity"] |
There was a problem hiding this comment.
@melinayg There is a slight issue in subtracting from stock quantity while still iteratively checking if there is sufficient stock. Just to clarify, if an order is not valid (there is a specific chocolate with too little stock fulfill the order), the order will not be placed and all stock will remain the same. If you now notice the issue, add a new commit with the changes + a test covering the edge case.
Description
What does this PR do?
The create_order() function is updated to have the stock quantities reflect the new amount of stock after an order is placed. Inventory is now updated real-time after orders are placed.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.
Tested within test_create_order_success that the inventory stock decreases by the amount of chocolate orders placed per order ID. Also created test_stock_not_updated_with_failed_order to check that the stock inventory doesn't change if the order is greater than the current stock inventory value.
Checklist: