Construa uma API REST simples para uma pizzaria, a linguagem da API é livre, a aplicação que consumir a sua API deve ser capaz de incluir, alterar ou excluir pizzas com tamanhos e sabores variados, também deve ser capaz de criar pedidos para os clientes. Dica: utilize o número do telefone do cliente para identifica-lo e não se esqueça de armazenar o endereço de entrega.
Renomear .env.example para .env e configuere o banco de dados
Config Data Base
DB_CONNECTION=mysql
DB_HOST=
DB_PORT=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
Run
composer install
Run
php artisan migrate
- Criar categoria | POST |
/category |
- Listar todas categorias | GET |
/category |
- Exibir uma categoria especifica | GET |
/category/{id} |
- Atualiar uma categoria | PUT |
/category/{id} |
- Remover uma categoria | DELETE |
/category/{id} |
- Criar produto | POST |
/product |
- Listar todos produtos | GET |
/product |
- Exibir um produto especifico | GET |
/product/{id} |
- Atualiar um produto | PUT |
/product/{id} |
- Remover um produto | DELETE |
/product/{id} |
- Criar sabor | POST |
/flavor |
- Listar todos sabores | GET |
/flavor |
- Exibir um sabor especifico | GET |
/flavor/{id} |
- Atualiar um sabor | PUT |
/flavor/{id} |
- Remover um sabor | DELETE |
/flavor/{id} |
- Criar cliente | POST |
/client |
- Listar todos clientes | GET |
/client |
- Exibir um cliente especifico | GET |
/client/{telephone} |
- Atualiar um cliente | PUT |
/client/{telephone} |
- Remover um cliente | DELETE |
/client/{telephone} |
- Criar pedido | POST |
/order |
- Listar todos pedidos | GET |
/order |
- Exibir um pedido especifico | GET |
/order/{id} |
- Remover um pedido | DELETE |
/order/{id} |
-
Criar categoria
- Example: http://localhost:8000/api/category
Request:
{
"name" : "Pizza"
}
-
Listar todas categorias
- Example: http://localhost:8000/api/category
Response:
[
{
"id":1,
"name":"Pizza",
"created_at":"2019-06-27 18:31:00",
"updated_at":"2019-06-27 18:31:00"
},
{
"id":2,
"name":"Bebidas",
"created_at":"2019-06-27 19:51:10",
"updated_at":"2019-06-27 19:51:10"
}
]
-
Exibir uma categoria especifica
- Example: http://localhost:8000/api/category/2
Response:
{
"id":2,
"name":"Bebidas",
"created_at":"2019-06-27 19:51:10",
"updated_at":"2019-06-27 19:51:10"
}
-
Atualizar uma categoria
- Example: http://localhost:8000/api/category/2
Response:
{
"name":"Bebidas"
}
-
Remover uma categoria
- Example: http://localhost:8000/api/category/2
Response:
status code 200
-
Criar produto
- Example: http://localhost:8000/api/product
Request:
{
"name":"Pizza Grande",
"price":19.99,
"category_id":1
}
-
Listar todos produtos
- Example: http://localhost:8000/api/product
Response:
[
{
"id": 1,
"name": "Pizza Grande",
"price": 19.99,
"category_id": 1,
"created_at": "2019-06-28 00:17:52",
"updated_at": "2019-06-28 00:17:52",
"flavor": [
{
"id": 1,
"name": "mussarela",
"category_id": 1,
"created_at": "2019-06-27 19:37:22",
"updated_at": "2019-06-27 19:37:22"
},
{
"id": 2,
"name": "napolitana",
"category_id": 1,
"created_at": "2019-06-27 20:37:35",
"updated_at": "2019-06-27 20:37:39"
},
{
"id": 3,
"name": "portuguesa",
"category_id": 1,
"created_at": "2019-06-27 20:37:50",
"updated_at": "2019-06-27 21:37:50"
}
],
"category": {
"id": 1,
"name": "Pizza",
"created_at": "2019-06-27 18:31:00",
"updated_at": "2019-06-27 18:31:00"
}
},
{
"id": 2,
"name": "Pizza Media",
"price": 15.99,
"category_id": 1,
"created_at": "2019-06-28 00:21:02",
"updated_at": "2019-06-28 00:21:02",
"flavor": [
{
"id": 1,
"name": "mussarela",
"category_id": 1,
"created_at": "2019-06-27 19:37:22",
"updated_at": "2019-06-27 19:37:22"
},
{
"id": 2,
"name": "napolitana",
"category_id": 1,
"created_at": "2019-06-27 20:37:35",
"updated_at": "2019-06-27 20:37:39"
},
{
"id": 3,
"name": "portuguesa",
"category_id": 1,
"created_at": "2019-06-27 20:37:50",
"updated_at": "2019-06-27 21:37:50"
}
],
"category": {
"id": 1,
"name": "Pizza",
"created_at": "2019-06-27 18:31:00",
"updated_at": "2019-06-27 18:31:00"
}
},
{
"id": 4,
"name": "Coca Cola 2L",
"price": 9.99,
"category_id": 2,
"created_at": "2019-06-28 00:23:37",
"updated_at": "2019-06-28 00:23:37",
"flavor": [],
"category": {
"id": 2,
"name": "Bebida",
"created_at": "2019-06-28 00:22:16",
"updated_at": "2019-06-28 00:22:16"
}
}
]
-
Exibir um produto especifico
- Example: http://localhost:8000/api/product/2
Response:
{
"id": 2,
"name": "Pizza Media",
"price": 15.99,
"category_id": 1,
"created_at": "2019-06-28 00:21:02",
"updated_at": "2019-06-28 00:21:02",
"category": {
"id": 1,
"name": "Pizza",
"created_at": "2019-06-27 18:31:00",
"updated_at": "2019-06-27 18:31:00"
},
"flavor": [
{
"id": 1,
"name": "mussarela",
"category_id": 1,
"created_at": "2019-06-27 19:37:22",
"updated_at": "2019-06-27 19:37:22"
},
{
"id": 2,
"name": "napolitana",
"category_id": 1,
"created_at": "2019-06-27 20:37:35",
"updated_at": "2019-06-27 20:37:39"
},
{
"id": 3,
"name": "portuguesa",
"category_id": 1,
"created_at": "2019-06-27 20:37:50",
"updated_at": "2019-06-27 21:37:50"
}
]
}
-
Atualizar um produto
- Example: http://localhost:8000/api/product/1
Response:
{
"price":29.99
}
-
Remover um produto
- Example: http://localhost:8000/api/product/1
Response:
status code 200
-
Criar sabor
- Example: http://localhost:8000/api/flavor
Request:
{
"name":"mussarela",
"category_id":1
}
-
Listar todos sabores
- Example: http://localhost:8000/api/flavor
Response:
[
{
"id": 1,
"name": "mussarela",
"category_id": 1,
"created_at": "2019-06-27 19:37:22",
"updated_at": "2019-06-27 19:37:22"
},
{
"id": 2,
"name": "napolitana",
"category_id": 1,
"created_at": "2019-06-27 20:37:35",
"updated_at": "2019-06-27 20:37:39"
},
{
"id": 3,
"name": "portuguesa",
"category_id": 1,
"created_at": "2019-06-27 20:37:50",
"updated_at": "2019-06-27 21:37:50"
}
]
-
Exibir um sabor especifico
- Example: http://localhost:8000/api/flavor/2
Response:
{
"id": 2,
"name": "napolitana",
"category_id": 1,
"created_at": "2019-06-27 20:37:35",
"updated_at": "2019-06-27 20:37:39"
}
-
Atualizar um sabor
- Example: http://localhost:8000/api/flavor/2
Response:
{
"name":"mussarela ouro"
}
-
Remover um sabor
- Example: http://localhost:8000/api/flavor/1
Response:
status code 200
-
Criar
- Example: http://localhost:8000/api/client
Request:
{
"name":"Anthony Edward Stark Jr.",
"telephone":31994726273
}
-
Listar todos
- Example: http://localhost:8000/api/client
Response:
[
{
"telephone": 31994726273,
"name": "Anthony Edward Stark Jr.",
"created_at": "2019-06-28 01:33:13",
"updated_at": "2019-06-28 01:33:13"
},
{
"telephone": 99314726273,
"name": "Wade Winston Wilson",
"created_at": "2019-06-28 01:36:11",
"updated_at": "2019-06-28 01:36:11"
}
]
-
Exibir
Response:
{
"telephone": 31994726273,
"name": "Anthony Edward Stark Jr.",
"created_at": "2019-06-28 01:33:13",
"updated_at": "2019-06-28 01:33:13"
}
-
Atualizar
Response:
{
"name":"Tony Stark"
}
-
Remover
Response:
status code 200
-
Criar
- Example: http://localhost:8000/api/order
Request:
{
"client_telephone":"99314726273",
"addresses":"10880, Malibu Point, 90265, Malibu , LA , Califórnia",
"items":[
{
"product_id":1,
"quantity":1,
"flavors_id":1
},
{
"product_id":1,
"quantity":1,
"flavors_id":3
},
{
"product_id":4,
"quantity":1
}
]
}
-
Listar todos
- Example: http://localhost:8000/api/order
Response:
[
{
"id": 1,
"client_telephone": 31994726273,
"addresses": "10880, Malibu Point, 90265, Malibu , LA , Califórnia",
"total_price": 30,
"created_at": "2019-06-28 02:05:27",
"updated_at": "2019-06-28 02:05:27"
},
{
"id": 2,
"client_telephone": 99314726273,
"addresses": "200 Park Avenue, Manhattan , NY,
"total_price": 40,
"created_at": "2019-06-28 02:09:27",
"updated_at": "2019-06-28 02:09:27"
},
]
-
Exibir
- Example: http://localhost:8000/api/order/1
Response:
{
"order_id": 1,
"client_id": 99314726273,
"total_price": 30,
"items": [
{
"name": "Pizza Grande",
"flavor": "mussarela",
"price": 10,
"quantity": 1
},
{
"name": "Pizza Grande",
"flavor": "portuguesa",
"price": 10,
"quantity": 1
},
{
"name": "Coca Cola 2L",
"flavor": null,
"price": 10,
"quantity": 1
}
]
}
-
Remover
- Example: http://localhost:8000/api/order/id
Response:
status code 200