This API can :
- Accepts the order details from the request payload.
- Persists the Order in the database.
- Updates the stock of the ingredients.
- Implement an email notification system that triggers an email once the stock level of any ingredient falls below 50%.
- PHP 8.1 or greater
- Composer 2.2 or greater
- MySQL 5.7 or greater
- Docker Desktop
- Any web server such as Apache, Nginx, or IIS
To serve this API run :
./vendor/bin/sail up
Show API Documentation
Challenge : Effectively create a new order record in the database and simultaneously update the stock levels of the corresponding ingredients while ensuring data consistency and preventing race conditions
.
Soluation:
- Implement database transactions
- Utilize optimistic locking mechanism to prevent concurrent orders
- Handled within a single atomic transaction
- Implement a retry mechanism using a loop and exception handling.
Challenge: Monitoring ingredient stock levels, triggering email notifications when any ingredient's stock falls below 50%, and preventing duplicate notifications
for the same ingredient.
Soluation:
- Use the
amount_in_stock
andnotified_amount
fields to monitor ingredient stock levels - Use the
low_amount_notified_at
field to prevent duplicate email notifications
Challenge: Writing thorough test cases to validate order persistence, ingredient stock updates, and email notification behavior.
Soluation: Covering various order scenarios with different quantities and ingredients using Pest. Verifying accurate ingredient stock level updates. Asserting that email notifications are sent only when necessary.
Note This repository is an practice workspace and is not meant to be used for any development purposes.