#Problem 1: Discounts
The App is written in Laravel 5.5. It has API methods to import data and calculate discounts on orders.
- Download and install Laravel here
- Download and install The v6.2.2 Homestead environment
- Follow the above instructions for Homestead and run Vagrant up
- Map this directory to Homestead like this
- Go to the folder via SSH
- Get needed files via composer:
$ composer update
You can test the use Cases as well as the API calls.
- Migrate the database:
$ php artisan migrate:refresh
- Run tests:
$ phpunit
- Find your test method at:
tests/Unit
for Discounts andtests/Feature
for API tests - Run
$ phpunit --filter <methodNameThatStartsWithTest>
Currently there are two methods accessible: Importing products:
POST: /products/mass
Example:
{
"id": "A101",
"description": "Screwdriver",
"category": "1",
"price": "9.75"
},
{
"id": "A102",
"description": "Electric screwdriver",
"category": "1",
"price": "49.50"
},
{
"id": "B101",
"description": "Basic on-off switchs",
"category": "2",
"price": "4.99"
},
{
"id": "B102",
"description": "Press button",
"category": "2",
"price": "4.99"
},
{
"id": "B103",
"description": "Switch with motion detector",
"category": "2",
"price": "12.95"
}
]
Importing an order:
POST: /orders
Example:
{
"id": "2",
"customer-id": "1",
"items": [
{
"product-id": "A102",
"quantity": "10",
"unit-price": "49.50",
"total": "495.90"
},
{
"product-id": "A101",
"quantity": "1",
"unit-price": "9.75",
"total": "9.75"
},
{
"product-id": "B102",
"quantity": "10",
"unit-price": "4.99",
"total": "49.90"
}
],
"total": "495.90"
}
Note: The Product and Customer must first been inserted to insert an order. To seed the database with Products and Customers simply run:
$ php artisan db:seed