This project provides a reliable backend system to clients. Three endpoints have been implemented to list/place/take orders.
- A clean, simple working solution.
- A
start.sh
bash script at the root of the project, which should setup all relevant applications. It works on Ubuntu. - Unit/integration tests.
- Production ready.
-
A RESTful HTTP API listening to port
8080
-
The API has 3 endpoints with path, method, request and response body as specified
-
One endpoint to create an order (see sample)
- To create an order, the API client must provide an origin and a destination (see sample)
- The API responds an object containing the distance and the order ID (see sample)
-
One endpoint to take an order (see sample)
- An order must not be takable multiple time.
- An error response should be sent if a client tries to take an order already taken.
-
One endpoint to list orders (see sample)
-
-
Google maps API to get the distance for the order: https://cloud.google.com/maps-platform/routes/
-
MySQL is used. The DB installation & initialisation is done in
start.sh
.
-
Method:
POST
-
URL path:
/order
-
Request body:
{ "origin": ["START_LATITUDE", "START_LONGITUDE" ], "destination": ["END_LATITUDE", "END_LONGITUDE"] }
-
Response:
Header:
HTTP 200
Body:{ "id": <order_id>, "distance": <total_distance>, "status": "UNASSIGN" }
or
Header:
HTTP 500
Body:{ "error": "ERROR_DESCRIPTION" }
-
Method:
PUT
-
URL path:
/order/:id
-
Request body:
{ "status":"taken" }
-
Response: Header:
HTTP 200
Body:{ "status": "SUCCESS" }
or
Header:
HTTP 409
Body:{ "error": "ORDER_ALREADY_BEEN_TAKEN" }
-
Method:
GET
-
Url path:
/orders?page=:page&limit=:limit
-
Response:
[ { "id": <order_id>, "distance": <total_distance>, "status": <ORDER_STATUS> }, ... ]
- Git clone the project
git clone git@github.com:cliffordchan/order_management.git demo
- Change directory into the demo folder
cd demo
- Copy .env.example to .env
cp .env.example .env
- Generate a new application key with the following command
php artisan key:generate
- Replace GOOGLE_DISTANCE_MATRIX_API_KEY key with the actual Google API key in .env of the root directory
- Execute ./start.sh
- Endpoint will be available at http://localhost:8080
- UnitTests will be available by executing at the root directory of the project
./vendor/bin/phpunit