- Docker as the container service to isolate the environment.
- Php to develop backend support.
- Laravel as the server framework / controller layer
- MySQL as the database layer
- NGINX as a proxy / content-caching layer
- Clone the repo
- Set Google Distance API key in environment file located in ./code .env file
- Run
./start.sh
to build docker containers, executing migration and PHPunit test cases - After starting container following will be executed automatically:
- Table migrations using artisan migrate command.
- Dummy Data imports using artisan db:seed command.
- To run migrations manually use this command
docker exec order_app_php php artisan migrate
- To run data import manually use this command
docker exec order_app_php php artisan db:seed
- You can run
docker-compose up
from terminal - Server is accessible at
http://localhost:8080
- Run manual testcase suite:
- Integration Tests:
docker exec order_app_php php ./vendor/phpunit/phpunit/phpunit /var/www/html/tests/Feature/OrderIntegrationTest.php
& - Unit Tests:
docker exec order_app_php php ./vendor/phpunit/phpunit/phpunit /var/www/html/tests/Unit
- Integration Tests:
Test Cases can be executed by:
- Integration Tests:
docker exec order_app_php php ./vendor/phpunit/phpunit/phpunit /var/www/html/tests/Feature/OrderIntegrationTest.php
& - Unit Tests:
docker exec order_app_php php ./vendor/phpunit/phpunit/phpunit /var/www/html/tests/Unit
-
localhost:8080/orders?page=:page&limit=:limit
:GET Method - to fetch orders with page number and limit
-
Header :
- GET /orders?page=0&limit=5 HTTP/1.1
- Host: localhost:8080
- Content-Type: application/json
-
Responses :
- Response [ { "id": 1, "distance": 46732, "status": "TAKEN" }, { "id": 2, "distance": 46731, "status": "UNASSIGNED" }, { "id": 3, "distance": 56908, "status": "UNASSIGNED" }, { "id": 4, "distance": 49132, "status": "UNASSIGNED" }, { "id": 5, "distance": 46732, "status": "UNASSIGNED" } ]
Code Description - 200 successful operation - 422 Invalid Request Parameter - 500 Internal Server Error
-
-
localhost:8080/orders
:POST Method - to create new order with origin and distination
-
Header :
- POST /orders HTTP/1.1
- Host: localhost:8080
- Content-Type: application/json
-
Post-Data :
{ "origin" :["28.704060", "77.102493"], "destination" :["28.535517", "77.391029"] }
- Responses :
- Response { "id": 44, "distance": 46732, "status": "UNASSIGNED" }
Code Description - 200 successful operation - 400 Api request denied or not responding - 422 Invalid Request Parameter
-
-
localhost:8080/orders/:id
:PATCH method to update status for taken.(Handled simultaneous update request from multiple users at the same time with response status 409)
- Header :
- PATCH /orders/44 HTTP/1.1
- Host: localhost:8080
- Content-Type: application/json
- Post-Data :
{ "status" : "TAKEN" }
- Responses :
- Response { "status": "SUCCESS" }
Code Description - 200 successful operation - 422 Invalid Request Parameter - 409 Order already taken - 417 Invalid Order Id
- Header :
./tests
- this folder contains test cases written under /tests/Feature/OrderIntegrationTest.php
./app
- contains all the server configuration file and controllers and models
- migration files are written under database folder in migrations directory
- To run manually migrations use this command
docker exec order_app_php php artisan migrate
- To run manually migrations use this command
- Dummy data seeding is performed using faker under database seeds folder
- To run manually data import use this command
docker exec order_app_php php artisan db:seed
- To run manually data import use this command
OrderController
contains all the api's methods :- localhost:8080/orders?page=1&limit=4 - GET url to fetch orders with page and limit
- localhost:8080/orders - POST method to insert new order with origin and distination
- localhost:8080/orders - PATCH method to update status for taken.(Handled simultaneous update request from multiple users at the same time with response status 409)
- PHPUnit.xml provides the unit test case and code coverage
.env
-
config contains all project configuration like it provides app configs, Google API Key, database connection
-
Set Google Distance API key