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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Created by PhpStorm.
# User: mauricioschmitz
# Date: 6/5/17
# Time: 20:59
144 changes: 144 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,147 @@
# Descrição do projeto
Usei o framework Silex para desenvolver a api em conjunto com o ORM Eloquent.
A api possui autenticação por chave de usuário chamada de `apikey`.<br>

Portanto o Header deve conter os seguintes parametros incluindo o `Content-type` devido a api aceitar apenas entradas e saídas em `json`

```
Authorization: 356a192b7913b04c54574d18c28d46e6395428ab
Content-Type: application/json
```

##Banco de dados
No banco de dados foi usado MySQL, e também foi implementado controle de versão da base atreavés do liquibase.
Para fins de teste está disponível o script de criação da base na pasta `resources`.

#ENDPOINTS
###Lista de todos os recursos
```
GET /api/v1/messages
```
Resposta:
```
[
{
"id": 4,
"user_id": 1,
"title": "Title 2",
"body": "Body 2",
"image_url": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_116x41dp.png",
"source": "Google",
"active": 1,
"created_at": "2017-07-05 17:38:30",
"updated_at": "2017-07-05 17:38:30",
"user": {
"id": 1,
"name": "User 1",
"email": "user1@user.com.br"
}
}
]
```

###Criar recurso
```
POST /api/v1/message
```
Body
```
{
"title":"Title 2",
"body":"Body 2",
"image_url":"https:\/\/www.google.com\/images\/branding\/googlelogo\/1x\/googlelogo_color_116x41dp.png",
"source":"Google"
}
```
Resposta
```
{
"title": "Title 2",
"body": "Body 2",
"image_url": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_116x41dp.png",
"source": "Google",
"user_id": 1,
"updated_at": "2017-07-07 12:57:00",
"created_at": "2017-07-07 12:57:00",
"id": 5,
"user": {
"id": 1,
"name": "User 1",
"email": "user1@user.com.br"
}
}
```

###Buscar recurso por id
```
GET /api/v1/message/{id}
```

Resposta
```
[
{
"id": 1,
"user_id": 1,
"title": "Title 2",
"body": "Body 2",
"image_url": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_116x41dp.png",
"source": "Google",
"active": 1,
"created_at": "2017-07-05 17:38:30",
"updated_at": "2017-07-05 17:38:30",
"user": {
"id": 1,
"name": "User 1",
"email": "user1@user.com.br"
}
}
]
```

###Editar recurso
```
PUT /api/v1/message
```
Body
```
{
"title":"Title 2",
"body":"Body 2",
"image_url":"https:\/\/www.google.com\/images\/branding\/googlelogo\/1x\/googlelogo_color_116x41dp.png",
"source":"Google"
}
```

Resposta
```
{
"title": "Title 2",
"body": "Body 2",
"image_url": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_116x41dp.png",
"source": "Google",
"user_id": 1,
"updated_at": "2017-07-07 12:57:00",
"created_at": "2017-07-07 12:57:00",
"id": 5,
"user": {
"id": 1,
"name": "User 1",
"email": "user1@user.com.br"
}
}
```

###Remover recurso
```
DELETE /api/v1/message/{id}
```

Resposta
```
{"success":"Deleted"}
```

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

Expand Down
25 changes: 25 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Created by PhpStorm.
* User: mauricioschmitz
* Date: 6/5/17
* Time: 20:15
*/
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->bootEloquent();

?>
21 changes: 21 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "mauriciofastman/teste",
"description": "Teste para vaga programador PHP Serasa",
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"silex/silex": "~2.0",
"illuminate/database": "5.2"
},
"autoload": {
"psr-0": { "App\\": "src/" },
"psr-4": {"App\\": "src/"}
},
"scripts": {
"run": [
"echo 'Started web server on http://localhost:8888'",
"php -S localhost:8888 -t web"
]
}
}
Loading