|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Bundle\Example\Controller; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Import classes |
|
7
|
|
|
*/ |
|
8
|
|
|
use App\ContainerAwareTrait; |
|
9
|
|
|
use Arus\Http\Response\ResponseFactoryAwareTrait; |
|
10
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
11
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
12
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @Route( |
|
16
|
|
|
* name="api_v1_entry_create", |
|
17
|
|
|
* path="/api/v1/entry", |
|
18
|
|
|
* methods={"POST"}, |
|
19
|
|
|
* summary="Creates a new entry", |
|
20
|
|
|
* tags={"entry"}, |
|
21
|
|
|
* middlewares={ |
|
22
|
|
|
* "App\Middleware\RequestBodyValidationMiddleware", |
|
23
|
|
|
* }, |
|
24
|
|
|
* ) |
|
25
|
|
|
* |
|
26
|
|
|
* @OpenApi\Operation( |
|
27
|
|
|
* requestBody=@OpenApi\RequestBody( |
|
28
|
|
|
* content={ |
|
29
|
|
|
* "application/json": @OpenApi\MediaType( |
|
30
|
|
|
* schema=@OpenApi\Schema( |
|
31
|
|
|
* type="object", |
|
32
|
|
|
* properties={ |
|
33
|
|
|
* "name": @OpenApi\SchemaReference( |
|
34
|
|
|
* class="App\Bundle\Example\Entity\Entry", |
|
35
|
|
|
* property="name", |
|
36
|
|
|
* ), |
|
37
|
|
|
* "slug": @OpenApi\SchemaReference( |
|
38
|
|
|
* class="App\Bundle\Example\Entity\Entry", |
|
39
|
|
|
* property="slug", |
|
40
|
|
|
* ), |
|
41
|
|
|
* }, |
|
42
|
|
|
* required={ |
|
43
|
|
|
* "name", |
|
44
|
|
|
* "slug", |
|
45
|
|
|
* }, |
|
46
|
|
|
* allowAdditionalProperties=false, |
|
47
|
|
|
* ), |
|
48
|
|
|
* ), |
|
49
|
|
|
* }, |
|
50
|
|
|
* ), |
|
51
|
|
|
* responses={ |
|
52
|
|
|
* 201: @OpenApi\Response( |
|
53
|
|
|
* description="OK", |
|
54
|
|
|
* content={ |
|
55
|
|
|
* "application/json": @OpenApi\MediaType( |
|
56
|
|
|
* schema=@OpenApi\Schema( |
|
57
|
|
|
* type="object", |
|
58
|
|
|
* properties={ |
|
59
|
|
|
* "data": @OpenApi\SchemaReference( |
|
60
|
|
|
* class="App\Bundle\Example\Service\EntrySerializer", |
|
61
|
|
|
* method="serialize", |
|
62
|
|
|
* ), |
|
63
|
|
|
* }, |
|
64
|
|
|
* ), |
|
65
|
|
|
* ), |
|
66
|
|
|
* }, |
|
67
|
|
|
* ), |
|
68
|
|
|
* }, |
|
69
|
|
|
* ) |
|
70
|
|
|
*/ |
|
71
|
|
|
final class EntryCreateController implements RequestHandlerInterface |
|
72
|
|
|
{ |
|
73
|
|
|
use ContainerAwareTrait; |
|
74
|
|
|
use ResponseFactoryAwareTrait; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* {@inheritDoc} |
|
78
|
|
|
* |
|
79
|
|
|
* @param ServerRequestInterface $request |
|
80
|
|
|
* |
|
81
|
|
|
* @return ResponseInterface |
|
82
|
|
|
*/ |
|
83
|
|
|
public function handle(ServerRequestInterface $request) : ResponseInterface |
|
84
|
|
|
{ |
|
85
|
|
|
$entry = $this->container->get('entryManager')->create($request->getParsedBody()); |
|
86
|
|
|
|
|
87
|
|
|
return $this->ok($this->container->get('entrySerializer')->serialize($entry), [], 201); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|