To read this document in Brazilian Portuguese, access the README.pt-br.md file.
REST API to manage a restaurant with local and online orders (delivery).
- Orders made at the restaurant.
- Orders made online for delivery (partners).
- As a cook I should be able to view all orders placed (on site / delivery) in the order of arrival.
- As a cook I should be able to change the order status to indicate that the order is being prepared.
- As a cook I should be able to change the order status to indicate that the order is ready.
- As a waiter I should be able to change the order status to indicate that the order has been delivered.
- As a customer I must be able to place an order, choosing a burger and a drink.
- As a customer I must be able to check the order status, to see if it is already being prepared.
- As a customer I must be able to check the value of the bill at any moment.
- A partner must be able to send an order through the API, stating the order items and the delivery address.
- A partner should be able to check the order status.
Learn new technologies, libraries and ensure good coverage tests.
- [RESTEasy] (http://resteasy.jboss.org/) - Build a REST webservice, the choice was RESTEasy.
- [REST-assured] (https://code.google.com/p/rest-assured/) - This library was chosen due to its simplicity to test and validate REST services.
- [MongoDB] (http://www.mongodb.org/) - As a document database, it was chosen to best represent the structure of an order (products, quantity and delivery data) and also the excellent reading performance.
- [Jongo] (http://www.jongo.org/) - This library was chosen to allow the use of MongoDB in Java and also its great performance.
-
Cache
-
Authentication
Implement OAuth2.
-
Dependency Injection
Spring.
- Java 7
- Jetty 9
- MongoDB 2.6.4
1 - [Download] (http://www.mongodb.org/downloads) MongoDB 2.6.4 for the version of your operating system.
2 - Follow the installation recommendations and start the server
Html $ mongod
`
With the Web server and the MongoDB started and running, perform the following requests to consume the API:
Example request:
- GET /products
- Accept: application/json
- Content-Type: application/json
Example response:
[
{
"id": "5403d655c19e51e2ea3c02c0",
"type": "HAMBURGUER",
"description": "X-EGG",
"price": 10.5
},
{
"id": "5403d7e6c19e51e2ea3c02c2",
"type": "DRINK",
"description": "Coca-Cola",
"price": 4
},
{
"id": "5403dddd9386acbf5d3f6055",
"type": "DESSERT",
"description": "Sorvete",
"price": 8.5
}
]
- 200 OK
Example request:
- GET /products/{id}
- Accept: application/json
- Content-Type: application/json
Example response:
{
"id": "5403d655c19e51e2ea3c02c0",
"type": "HAMBURGUER",
"description": "X-EGG",
"price": 10.5
}
- 200 OK
Example request:
- POST /orders
- Accept: application/json
- Content-Type: application/json
{
"id": "5403d7f7c19e51e2ea3c02c3",
"table": 5,
"total": 21.0,
"status": "WAITING",
"items":[
{
"product": {
"id": "5403d655c19e51e2ea3c02c0",
"type": "HAMBURGUER",
"description": "X-EGG",
"price": 10.5
},
"quantity": 2
}
],
"delivery": null
}
Example response:
- 201 CREATED
Example request:
- POST /orders
- Accept: application/json
- Content-Type: application/json
{
"id": "5203f2f7c11e54e2eb2c12e5",
"table": null,
"total": 21.0,
"status": "WAITING",
"items": [
{
"product": {
"id": "5403d655c19e51e2ea3c02c0",
"type": "HAMBURGUER",
"price" :10.5,
"description" :"X-EGG"
},
"quantity": 2
}
],
"delivery": {
"address": {
"state": "SP",
"number": "100",
"street": "Rua Guararapes",
"complement": "APTO 302",
"city": "São Paulo",
"zip": "04561-000"
},
"fullname": "Lucas Michelini Reis de Oliveira",
"email": "lucasmro@gmail.com",
"phone": "11986115678"
}
}
Example response:
- 201 CREATED
Example request:
- GET /orders/{id}
- Accept: application/json
- Content-Type: application/json
Example response:
{
"id": "5604d7f8c19e51e2ea3c01d5",
"table": 5,
"total": 4,
"status": "WAITING",
"items": [
{
"product": {
"id": "5403d7e6c19e51e2ea3c02c2",
"type": "DRINK",
"price": 4,
"description": "Coca-Cola"
},
"quantity": 1
}
],
"delivery": null
}
- 200 OK
Example request:
- GET /orders/table/{table}
- Accept: application/json
- Content-Type: application/json
Example response:
[
{
"id": "5403d7f7c19e51e2ea3c02c3",
"table": 5,
"total": 21,
"status": "WAITING",
"items": [
{
"product": {
"id": "5403d655c19e51e2ea3c02c0",
"type": "HAMBURGUER",
"price": 10.5,
"description": "X-EGG"
},
"quantity": 2
}
],
"delivery": null
},
{
"id": "5604d7f8c19e51e2ea3c01d5",
"table": 5,
"total": 4,
"status": "WAITING",
"items": [
{
"product": {
"id": "5403d7e6c19e51e2ea3c02c2",
"type": "DRINK",
"price": 4,
"description": "Coca-Cola"
},
"quantity": 1
}
],
"delivery": null
}
]
- 200 OK
Example request:
- PUT /orders/{id}/{status}
- Accept: application/json
- Content-Type: application/json
Example response:
- 204 NO CONTENT
Code | Description | Reason |
---|---|---|
400 | Bad Request | Missing parameters or invalid parameters. |
404 | Not Found | Value not found in the database. |