1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace RestTemplate\Rest; |
4
|
|
|
|
5
|
|
|
use ByJG\MicroOrm\Literal; |
6
|
|
|
use ByJG\RestServer\Exception\Error401Exception; |
7
|
|
|
use ByJG\RestServer\Exception\Error404Exception; |
8
|
|
|
use ByJG\RestServer\HttpRequest; |
9
|
|
|
use ByJG\RestServer\HttpResponse; |
10
|
|
|
use ByJG\Serializer\BinderObject; |
11
|
|
|
use RestTemplate\Psr11; |
12
|
|
|
use RestTemplate\Model\DummyHex; |
13
|
|
|
use RestTemplate\Repository\DummyHexRepository; |
14
|
|
|
use OpenApi\Annotations as OA; |
15
|
|
|
use RestTemplate\Util\HexUuidLiteral; |
16
|
|
|
|
17
|
|
|
class DummyHexRest extends ServiceAbstractBase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Get the DummyHex by id |
21
|
|
|
* @OA\Get( |
22
|
|
|
* path="/dummyhex/{id}", |
23
|
|
|
* tags={"Dummyhex"}, |
24
|
|
|
* security={{ |
25
|
|
|
* "jwt-token":{} |
26
|
|
|
* }}, |
27
|
|
|
* @OA\Parameter( |
28
|
|
|
* name="id", |
29
|
|
|
* description="", |
30
|
|
|
* in="path", |
31
|
|
|
* required=true, |
32
|
|
|
* @OA\Schema( |
33
|
|
|
* type="string", |
34
|
|
|
* format="string" |
35
|
|
|
* ) |
36
|
|
|
* ), |
37
|
|
|
* @OA\Response( |
38
|
|
|
* response=200, |
39
|
|
|
* description="The object DummyHex", |
40
|
|
|
* @OA\JsonContent(ref="#/components/schemas/DummyHex") |
41
|
|
|
* ), |
42
|
|
|
* @OA\Response( |
43
|
|
|
* response=401, |
44
|
|
|
* description="Not Authorized", |
45
|
|
|
* @OA\JsonContent(ref="#/components/schemas/error") |
46
|
|
|
* ) |
47
|
|
|
* ) |
48
|
|
|
* |
49
|
|
|
* @param HttpResponse $response |
50
|
|
|
* @param HttpRequest $request |
51
|
|
|
* @throws Error401Exception |
52
|
|
|
* @throws InvalidArgumentException |
53
|
|
|
*/ |
54
|
|
|
public function getDummyHex($response, $request) |
55
|
|
|
{ |
56
|
|
|
$data = $this->requireAuthenticated(); |
|
|
|
|
57
|
|
|
|
58
|
|
|
$dummyHexRepo = Psr11::container()->get(DummyHexRepository::class); |
59
|
|
|
$id = $request->param('id'); |
60
|
|
|
|
61
|
|
|
$result = $dummyHexRepo->get($id); |
62
|
|
|
if (empty($result)) { |
63
|
|
|
throw new Error404Exception('Id not found'); |
64
|
|
|
} |
65
|
|
|
$response->write( |
66
|
|
|
$result |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* List DummyHex |
72
|
|
|
* @OA\Get( |
73
|
|
|
* path="/dummyhex", |
74
|
|
|
* tags={"Dummyhex"}, |
75
|
|
|
* security={{ |
76
|
|
|
* "jwt-token":{} |
77
|
|
|
* }}, |
78
|
|
|
* @OA\Parameter( |
79
|
|
|
* name="page", |
80
|
|
|
* description="Page number", |
81
|
|
|
* in="query", |
82
|
|
|
* required=false, |
83
|
|
|
* @OA\Schema( |
84
|
|
|
* type="integer" |
85
|
|
|
* ) |
86
|
|
|
* ), |
87
|
|
|
* @OA\Parameter( |
88
|
|
|
* name="size", |
89
|
|
|
* description="Page size", |
90
|
|
|
* in="query", |
91
|
|
|
* required=false, |
92
|
|
|
* @OA\Schema( |
93
|
|
|
* type="integer" |
94
|
|
|
* ) |
95
|
|
|
* ), |
96
|
|
|
* @OA\Parameter( |
97
|
|
|
* name="orderBy", |
98
|
|
|
* description="Order by", |
99
|
|
|
* in="query", |
100
|
|
|
* required=false, |
101
|
|
|
* @OA\Schema( |
102
|
|
|
* type="string" |
103
|
|
|
* ) |
104
|
|
|
* ), |
105
|
|
|
* @OA\Parameter( |
106
|
|
|
* name="filter", |
107
|
|
|
* description="Filter", |
108
|
|
|
* in="query", |
109
|
|
|
* required=false, |
110
|
|
|
* @OA\Schema( |
111
|
|
|
* type="string" |
112
|
|
|
* ) |
113
|
|
|
* ), |
114
|
|
|
* @OA\Response( |
115
|
|
|
* response=200, |
116
|
|
|
* description="The list of DummyHex", |
117
|
|
|
* @OA\JsonContent( |
118
|
|
|
* type="array", |
119
|
|
|
* @OA\Items(ref="#/components/schemas/DummyHex") |
120
|
|
|
* ) |
121
|
|
|
* ), |
122
|
|
|
* @OA\Response( |
123
|
|
|
* response=401, |
124
|
|
|
* description="Not Authorized", |
125
|
|
|
* @OA\JsonContent(ref="#/components/schemas/error") |
126
|
|
|
* ) |
127
|
|
|
* ) |
128
|
|
|
* |
129
|
|
|
* @param mixed $response |
130
|
|
|
* @param mixed $request |
131
|
|
|
* @return void |
132
|
|
|
*/ |
133
|
|
|
public function listDummyHex($response, $request) |
134
|
|
|
{ |
135
|
|
|
$data = $this->requireAuthenticated(); |
|
|
|
|
136
|
|
|
|
137
|
|
|
$repo = Psr11::container()->get(DummyHexRepository::class); |
138
|
|
|
|
139
|
|
|
$page = $request->get('page'); |
140
|
|
|
$size = $request->get('size'); |
141
|
|
|
// $orderBy = $request->get('orderBy'); |
142
|
|
|
// $filter = $request->get('filter'); |
143
|
|
|
|
144
|
|
|
$result = $repo->list($page, $size); |
145
|
|
|
$response->write( |
146
|
|
|
$result |
147
|
|
|
); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Create a new DummyHex |
153
|
|
|
* @OA\Post( |
154
|
|
|
* path="/dummyhex", |
155
|
|
|
* tags={"Dummyhex"}, |
156
|
|
|
* security={{ |
157
|
|
|
* "jwt-token":{} |
158
|
|
|
* }}, |
159
|
|
|
* @OA\RequestBody( |
160
|
|
|
* description="The object DummyHex to be created", |
161
|
|
|
* required=true, |
162
|
|
|
* @OA\MediaType( |
163
|
|
|
* mediaType="application/json", |
164
|
|
|
* @OA\Schema( |
165
|
|
|
* |
166
|
|
|
|
167
|
|
|
* @OA\Property(property="field", type="string", format="string", nullable=true) |
168
|
|
|
* ) |
169
|
|
|
* ) |
170
|
|
|
* ), |
171
|
|
|
* @OA\Response( |
172
|
|
|
* response=200, |
173
|
|
|
* description="The id of the object created", |
174
|
|
|
* @OA\MediaType( |
175
|
|
|
* mediaType="application/json", |
176
|
|
|
* @OA\Schema( |
177
|
|
|
* required={ "id" }, |
178
|
|
|
|
179
|
|
|
* @OA\Property(property="id", type="string", format="string") |
180
|
|
|
* ) |
181
|
|
|
* ) |
182
|
|
|
* ), |
183
|
|
|
* @OA\Response( |
184
|
|
|
* response=401, |
185
|
|
|
* description="Not Authorized", |
186
|
|
|
* @OA\JsonContent(ref="#/components/schemas/error") |
187
|
|
|
* ) |
188
|
|
|
* ) |
189
|
|
|
* |
190
|
|
|
* @param HttpResponse $response |
191
|
|
|
* @param HttpRequest $request |
192
|
|
|
* @throws Error401Exception |
193
|
|
|
* @throws InvalidArgumentException |
194
|
|
|
*/ |
195
|
|
|
public function postDummyHex($response, $request) |
196
|
|
|
{ |
197
|
|
|
$data = $this->requireRole("admin"); |
|
|
|
|
198
|
|
|
|
199
|
|
|
$payload = $this->validateRequest($request); |
200
|
|
|
|
201
|
|
|
$model = new DummyHex(); |
202
|
|
|
BinderObject::bind($payload, $model); |
203
|
|
|
|
204
|
|
|
$dummyHexRepo = Psr11::container()->get(DummyHexRepository::class); |
205
|
|
|
$dummyHexRepo->save($model); |
206
|
|
|
|
207
|
|
|
$response->write([ "id" => $model->getId()]); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Update an existing DummyHex |
213
|
|
|
* @OA\Put( |
214
|
|
|
* path="/dummyhex", |
215
|
|
|
* tags={"Dummyhex"}, |
216
|
|
|
* security={{ |
217
|
|
|
* "jwt-token":{} |
218
|
|
|
* }}, |
219
|
|
|
* @OA\RequestBody( |
220
|
|
|
* description="The object DummyHex to be updated", |
221
|
|
|
* required=true, |
222
|
|
|
* @OA\JsonContent(ref="#/components/schemas/DummyHex") |
223
|
|
|
* ), |
224
|
|
|
* @OA\Response( |
225
|
|
|
* response=200, |
226
|
|
|
* description="Nothing to return" |
227
|
|
|
* ), |
228
|
|
|
* @OA\Response( |
229
|
|
|
* response=401, |
230
|
|
|
* description="Not Authorized", |
231
|
|
|
* @OA\JsonContent(ref="#/components/schemas/error") |
232
|
|
|
* ) |
233
|
|
|
* ) |
234
|
|
|
* |
235
|
|
|
* @param HttpResponse $response |
236
|
|
|
* @param HttpRequest $request |
237
|
|
|
* @throws Error401Exception |
238
|
|
|
* @throws InvalidArgumentException |
239
|
|
|
*/ |
240
|
|
|
public function putDummyHex($response, $request) |
|
|
|
|
241
|
|
|
{ |
242
|
|
|
$data = $this->requireRole("admin"); |
|
|
|
|
243
|
|
|
|
244
|
|
|
$payload = $this->validateRequest($request); |
245
|
|
|
|
246
|
|
|
$dummyHexRepo = Psr11::container()->get(DummyHexRepository::class); |
247
|
|
|
$model = $dummyHexRepo->get($payload['id']); |
248
|
|
|
if (empty($model)) { |
249
|
|
|
throw new Error404Exception('Id not found'); |
250
|
|
|
} |
251
|
|
|
BinderObject::bind($payload, $model); |
252
|
|
|
|
253
|
|
|
$dummyHexRepo->save($model); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
} |
257
|
|
|
|