a Laravel application that helps a user understand how much quantity of a product is available for use.
- The application displays an interface with a button and a single input that represents the requested quantity of a product.
- When the button is clicked, the interface shows either the $ value of the quantity of that product that will be applied, or an error message if the quantity to be applied exceeds the quantity on hand.
- Note
- that product purchased first will be used first, therefore the quantity on hand should be the most recently purchased.
- this means we need to track the date of purchase
- Note
- laravel has a weird convension where the app and interface are tightly coupled with a lot of convensions; hence I decided to create both an api and a web controller.
- I had to reuse some consolidate a number of functionalities used in multiple controllers in the model.
- Naming:
- API
- I looked at the app itself like a product ledger
- the model became a ledger entry:
ledgerEntry
- the controllers are activities toward the ledger
- currently there is only a need for a product application activity
ApplicationController
- I also created a DTO - data transfer object for validation
ApplyRequest
- WEBAPP
- I create a web controller for just handling all the web app control.
WebController
- I create a web controller for just handling all the web app control.
- API
- Improvements:
- the app may be improved by caching since most of it needs to track a running value and a queue of available products.
- note: I used a queue since a part of the requirement is to use the product in order of which was purchased first.
- install php 8
sudo add-apt-repository ppa:ondrej/php
sudo apt install php8.1 php8.1-cli php8.1-common php8.1-mbstring php8.1-gd php8.1-intl php8.1-xml php8.1-mysql php8.1-zip php8.1-xsl php8.1-curl
- check php version with:
php -v
- install composer
sudo apt install curl git unzip
curl –sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
- test if your composer works with
composer -V
- migration
- before migration setup the values for your db in your
.env
file - run migration to create the tables
php artisan migrate
- note: I left the default tables of laravel
- run seeder to seed the db
php artisan db:seed
- note: if you check the seeding file I manually seed the db and did not use a factory. The reason for this is that the entries are order and value specific.
- before migration setup the values for your db in your
- run tests:
php artisan test
- currently there are just a couple of test to demonstrate the base uses of the app
- (optional) install some dev tools
- install clockwork
- there is a clockwork plugin for chrome and firefox
- install clockwork to your laravel project
composer require itsgoingd/clockwork
- install clockwork
- use proper commit messages: https://www.freecodecamp.org/news/how-to-write-better-git-commit-messages/
- laravel naming conventions:
- API
- there is an api for creating product consumption
curl --location --request POST 'http://localhost:8000/api/product/apply' \ --header 'Content-Type: application/json' \ --data-raw '{ "quantity": 10 }'
- the routes are visible via
php artisan route:list
- so far the consumption is the only route that is implemented
- there is an api for creating product consumption
- Web
- product consumption page is the main application
http://localhost:8000/ledger/create
- other test routes for checking other laravel options -> ledger listing and specific item
- product consumption page is the main application