Giter Club home page Giter Club logo

salah3id / order-processing-flow Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 528 KB

Controller action plays a central role in handling order processing and ingredient stock updates. It receives order details from the request payload, persists the order in the database, and updates the stock of the corresponding ingredients. This repository is an practice workspace and is not meant to be used for any development purposes.

PHP 79.24% JavaScript 0.20% Blade 20.56%

order-processing-flow's Introduction

Order processing workflow - API

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%.

Installation

Requirements

  • 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

Run Using Sail

To serve this API run :

  ./vendor/bin/sail up

Show API Documentation

Problems and Challenges

Problem 1: Handling order persistence and ingredient stock updates

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.

Problem 2: Implementing email notifications for low ingredient stock

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 and notified_amount fields to monitor ingredient stock levels
  • Use the low_amount_notified_at field to prevent duplicate email notifications

Problem 3: Writing comprehensive test cases

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.


Database ERD

J


Note This repository is an practice workspace and is not meant to be used for any development purposes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.