Skip to content

Feat: Update stock quanitity when chocolate order is created#10

Closed
keshavgoel787 wants to merge 3 commits intomainfrom
feat/update-stock-keshav
Closed

Feat: Update stock quanitity when chocolate order is created#10
keshavgoel787 wants to merge 3 commits intomainfrom
feat/update-stock-keshav

Conversation

@keshavgoel787
Copy link
Copy Markdown
Collaborator

Description

What does this PR do?

Updates chocolate db when valid order is created

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.

Updated current order test to check if db is updated before and after changes

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Copy link
Copy Markdown
Collaborator

@BeWelsh BeWelsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keshavgoel787 Good job! Just remember to request Jerome + myself upon opening a PR. We would like a little more testing (if order doesn't go through, check if stock remains the same). 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

chocolate["stock_quantity"] -= item["quantity"]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keshavgoel787 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.

@BeWelsh BeWelsh closed this Feb 2, 2026
@BeWelsh BeWelsh deleted the feat/update-stock-keshav branch February 3, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants