A RESTful API for Pizza Delivery
Imagine a pizza ordering services with the following functionality:
- Order a pizza:
- Specify the desired pizza type (margarita, marinara, salami), the number of pizza items and their size (small, medium, large).
- An order should contain information about the customer: name, address.
- It should be possible to track the status of order delivery. (new, preparing, delivering, delivered)
- Update an order:
- There should be a possibility to update the order details (pizzas/number of pizzas/size).
- There should be a possibility to change the status of order delivery. Please, pay attention, that order in some delivery statuses (e.g. delivered) could not be updated;
- Remove an order.
- Retrieve an order.
- List orders.
- Provide filtering by status/customer.
- Clone this repository
cd pizza-delivery-api
npm install
npm test //for running test cases
npm start //for starting the appication
Make sure you have a postgres database setup and credentials are given in a .env
file.
docker-compose up --build
Endpoint /api/user/add
Body
{
"first_name": "Rifat Bin",
"last_name": "Reza",
"address": "House 13, Road 8/A, Uttara, Dhaka 1230",
"email": "[email protected]"
}
Response
{
"status": "success",
"message": "Successfully saved customer",
"data": {
"id": 1,
"first_name": "Rifat Bin",
"last_name": "Reza",
"address": "House 13, Road 8/A, Uttara, Dhaka 1230",
"email": "[email protected]"
}
}
Endpoint /api/order/add
Body
{
"type": "margarita",
"size": "large",
"quantity": 600,
"customer_id": 1
}
Response
{
"status": "success",
"message": "Successfully saved data",
"data": {
"id": 8,
"type": "margarita",
"size": "large",
"quantity": 600,
"customer_id": 1,
"delivery_status": "new",
"updatedAt": "2019-12-07T20:34:44.523Z",
"createdAt": "2019-12-07T20:34:44.523Z"
}
}
Endpoint /api/order/1/update
Body
{
"quantity": 60
}
Response
{
"status": "success",
"message": "Successfully updated the order",
"data": null
}
Endpoint /api/order/1/status
Body
{
"delivery_status":"delivered"
}
Response
{
"status": "success",
"message": "Successfully updated delivery status",
"data": null
}
Endpoint /api/order/1
Response
{
"status": "success",
"message": "Found the order",
"data": {
"order": {
"id": 8,
"type": "margarita",
"size": "large",
"quantity": 600,
"customer_id": 1,
"delivery_status": "new",
"createdAt": "2019-12-07T20:34:44.523Z",
"updatedAt": "2019-12-07T20:34:44.523Z"
},
"customer": {
"first_name": "Rifat Bin",
"last_name": "Reza",
"address": "House 131, Road 8, Uttara, Dhaka 1230"
}
}
}
Endpoint /api/orders/filter?delivery_status=delivered&userId=1
Response
{
"status": "success",
"message": "Found orders",
"data": [
{
"id": 1,
"type": "margarita",
"size": "small",
"quantity": 60,
"customer_id": 1,
"delivery_status": "delivered",
"createdAt": "2019-12-07T13:31:33.961Z",
"updatedAt": "2019-12-07T20:36:39.630Z",
"customer": {
"first_name": "Rifat Bin",
"last_name": "Reza",
"address": "House 131, Road 8, Uttara, Dhaka 1230"
}
}
]
}
Endpoint /api/order/1/remove
Response
{
"status": "success",
"message": "Successfully removed the order",
"data": null
}