blob: 105c7c273a957fa5ff787c29c11d3c2947df0490 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<?php
namespace Api\Posts\Controllers;
use Illuminate\Http\Request;
use Infrastructure\Http\Controller;
use Api\Posts\Requests\CreatePostRequest;
use Api\Posts\Services\PostService;
class PostController extends Controller
{
private $postService;
public function __construct(PostService $postService)
{
$this->postService = $postService;
}
public function getAll()
{
$resourceOptions = $this->parseResourceOptions();
$data = $this->postService->getAll($resourceOptions);
$parsedData = $this->parseData($data, $resourceOptions, 'posts');
return $this->response($parsedData);
}
public function getById($postId)
{
$resourceOptions = $this->parseResourceOptions();
$data = $this->postService->getById($postId, $resourceOptions);
$parsedData = $this->parseData($data, $resourceOptions, 'post');
return $this->response($parsedData);
}
public function create(CreatePostRequest $request)
{
$data = $request->get('post', []);
return $this->response($this->postService->create($data), 201);
}
public function update($postId, Request $request)
{
$data = $request->get('post', []);
return $this->response($this->postService->update($postId, $data));
}
public function delete($postId)
{
return $this->response($this->postService->delete($postId));
}
}
|