Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2010-2017 Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
118 changes: 118 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,121 @@
# Descrição
Foi utilizado o framwork Silex para desenvolver uma api, foi utilizado também o Eloquent ORM para controle do banco de dados.
Para a autenticação foi utilizado autenticação Basic.<br>

Com esta autenticação, deve-se contonter os parametros `Authorization` e o `Content-Type`, no parametro `Authorization` deve conter uma autenticação `Basic` e o parametro `Content-Type` deve ser `application/json`.
A Autenticação é `admin:foo` utilizando a base64, tendo como resultado `Basic YWRtaW46Zm9`.
```
Authorization: Basic YWRtaW46Zm9v
Content-Type: application/json
```
## Banco de dados
O banco de dados utilizado foi `MySql`, para a criação do banco foi criado um comando `db:create` para o console do `Silex`, é possivel rodar o comando com `php bin/console db:create`.
Foi desenvolvido o comando `db:seed` para semear o bando para desenvolvimento, que pode ser usando como `php bin/console db:seed`.

## EndPoints

### Listagem de todos os recursos
```
GET /api/v1/person
```
Retorno:
```
[
{
"id": 1,
"name": "Sra. Mariana Tessália Rocha",
"email": "inacio69@dominato.org",
"date_birth": "1993-04-24",
"address": "R. Antônio, 938",
"created_at": "2017-07-12 21:34:28",
"updated_at": "2017-07-12 21:34:28"
},
{
"id": 2,
"name": "Sra. Natália Ferraz",
"email": "laura06@terra.com.br",
"date_birth": "1928-09-20",
"address": "Travessa Hernani Martines, 123. Apto 90",
"created_at": "2017-07-12 21:34:28",
"updated_at": "2017-07-12 21:34:28"
}
]
```
### Busca de um recurso pelo ID
```
GET /api/v1/person/{id}
```
Retorno:
```
{
"id": 1,
"name": "Sra. Mariana Tessália Rocha",
"email": "inacio69@dominato.org",
"date_birth": "1993-04-24",
"address": "R. Antônio, 938",
"created_at": "2017-07-12 21:34:28",
"updated_at": "2017-07-12 21:34:28"
}
```
### Criação de um novo recurso
```
PUT /api/v1/person/
```
Body:
```
{
"name": "Antônio Marco da Silva",
"email": "antomarsi@hotmail.com",
"date_birth": "1993-03-25",
"address": "R. Antônio, 123"
}
```
Retorno:
```
{
"name": "Antônio Marco da Silva",
"email": "antomarsi@hotmail.com",
"date_birth": "1993-03-25",
"address": "R. Antônio, 123",
"updated_at": "2017-07-12 22:06:14",
"created_at": "2017-07-12 22:06:14",
"id": 11
}
```
### Alteração de um recurso existente
```
PUT /api/v1/person/{id}
Body:
```
{
"address": "R. Antônio Marco da Silva, 123"
}
```

```
Retorno:
```
{
"id": 11,
"name": "Antônio Marco da Silva",
"email": "antomarsi@hotmail.com",
"date_birth": "1993-03-25",
"address": "R. Antônio Marco da Silva, 123",
"created_at": "2017-07-12 22:06:14",
"updated_at": "2017-07-12 22:07:26"
}
```
### Exclusão de um recurso
```
DELETE /api/v1/person/{id}
```
Retorno:
```
{
"message": "Person was deleted successfully"
}
```

# A tarefa
Sua tarefa consiste em desenvolver uma API RESTful para manipular um determinado recurso. Deverá ser utilizado o framework Silex.

Expand Down
21 changes: 21 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php
require_once __DIR__.'/../vendor/autoload.php';

set_time_limit(0);

use Symfony\Component\Console\Input\ArgvInput;

$input = new ArgvInput();

$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');

$app = require __DIR__.'/../src/app.php';

require __DIR__.'/../config/'.$env.'.php';

require __DIR__.'/../bootstrap.php';

$console = require __DIR__.'/../src/console.php';

$console->run();
20 changes: 20 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
require 'vendor/autoload.php';

use Illuminate\Database\Capsule\Manager as Capsule;

$capsule = new Capsule();

$capsule->addConnection([
"driver" => $app['driver'],
"host" => $app['host'],
"database" => $app['database'],
"username" => $app['username'],
"password" => $app['password'],
"charset" => $app['charset'],
"collation" => $app['collation'],
]);

$capsule->setAsGlobal();

$capsule->bootEloquent();
40 changes: 40 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "fabpot/silex-skeleton",
"description": "A pre-configured skeleton for the Silex microframework",
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"silex/silex": "~2.0",
"symfony/asset": "~2.8|^3.0",
"symfony/browser-kit": "~2.8|^3.0",
"symfony/class-loader": "~2.8|^3.0",
"symfony/config": "~2.8|^3.0",
"symfony/console": "~2.8|^3.0",
"symfony/debug": "~2.8|^3.0",
"symfony/monolog-bridge": "~2.8|^3.0",
"symfony/process": "~2.8|^3.0",
"symfony/security": "~2.8|^3.0",
"fzaninotto/faker": "^1.6",
"twig/twig": "^2.4",
"illuminate/database": "5.2"
},
"autoload": {
"psr-0": { "": "src/" },
"psr-4": {
"App\\Model\\": "src/Model",
"App\\Security\\": "src/Security"
}
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"scripts": {
"run": [
"echo 'Started web server on http://localhost:8888'",
"php -S localhost:8888 -t web"
]
}
}
Loading