1
|
|
|
<?php |
2
|
|
|
namespace App\Schema; |
3
|
|
|
|
4
|
|
|
use \Carbon\Carbon; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @api {get} /right Список прав |
8
|
|
|
* @apiName GetRights |
9
|
|
|
* @apiGroup Right |
10
|
|
|
* |
11
|
|
|
* @apiDescription Метод для получения списка прав. |
12
|
|
|
* |
13
|
|
|
* @apiPermission user |
14
|
|
|
* |
15
|
|
|
* @apiHeader {String} Authorization Токен. |
16
|
|
|
* |
17
|
|
|
* @apiSuccessExample {json} Успешно (200) |
18
|
|
|
* HTTP/1.1 200 OK |
19
|
|
|
* { |
20
|
|
|
* "data": [ |
21
|
|
|
* { |
22
|
|
|
* "type": "right", |
23
|
|
|
* "id": "1", |
24
|
|
|
* "attributes": { |
25
|
|
|
* "name": "manageUsers", |
26
|
|
|
* "description": "Управление пользователями", |
27
|
|
|
* "created_at": "2016-10-17T07:38:21+0000", |
28
|
|
|
* "updated_at": "2016-10-17T07:38:21+0000", |
29
|
|
|
* "created_by": 0, |
30
|
|
|
* "updated_by": null |
31
|
|
|
* }, |
32
|
|
|
* "links": { |
33
|
|
|
* "self": "http://bootstrapi.dev/api/right/1" |
34
|
|
|
* } |
35
|
|
|
* } |
36
|
|
|
* ] |
37
|
|
|
* } |
38
|
|
|
* |
39
|
|
|
* @apiUse StandardErrors |
40
|
|
|
* @apiUse UnauthorizedError |
41
|
|
|
*/ |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @api {get} /right/:id Получить право |
45
|
|
|
* @apiName GetRight |
46
|
|
|
* @apiGroup Right |
47
|
|
|
* |
48
|
|
|
* @apiDescription Метод для получения права. |
49
|
|
|
* |
50
|
|
|
* @apiPermission user |
51
|
|
|
* |
52
|
|
|
* @apiParam {Number} id Id права |
53
|
|
|
* |
54
|
|
|
* @apiHeader {String} Authorization Токен. |
55
|
|
|
* |
56
|
|
|
* @apiSuccessExample {json} Успешно (200) |
57
|
|
|
* HTTP/1.1 200 OK |
58
|
|
|
* { |
59
|
|
|
* "data": { |
60
|
|
|
* "type": "right", |
61
|
|
|
* "id": "1", |
62
|
|
|
* "attributes": { |
63
|
|
|
* "name": "manageUsers", |
64
|
|
|
* "description": "Управление пользователями", |
65
|
|
|
* "created_at": "2016-10-17T07:38:21+0000", |
66
|
|
|
* "updated_at": "2016-10-17T07:38:21+0000", |
67
|
|
|
* "created_by": 0, |
68
|
|
|
* "updated_by": null |
69
|
|
|
* }, |
70
|
|
|
* "links": { |
71
|
|
|
* "self": "http://bootstrapi.dev/api/right/1" |
72
|
|
|
* } |
73
|
|
|
* } |
74
|
|
|
* } |
75
|
|
|
* |
76
|
|
|
* @apiUse StandardErrors |
77
|
|
|
* @apiUse UnauthorizedError |
78
|
|
|
* @apiUse NotFoundError |
79
|
|
|
*/ |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @api {post} /right Создание права |
83
|
|
|
* @apiName CreateRight |
84
|
|
|
* @apiGroup Right |
85
|
|
|
* |
86
|
|
|
* @apiDescription Метод для создания нового права. |
87
|
|
|
* |
88
|
|
|
* @apiPermission admin |
89
|
|
|
* |
90
|
|
|
* @apiParam {String} name Имя права (уникальный) |
91
|
|
|
* @apiParam {String} description Человекопонятное описание |
92
|
|
|
* |
93
|
|
|
* @apiParamExample {json} Пример запроса: |
94
|
|
|
* { |
95
|
|
|
* "data": { |
96
|
|
|
* "attributes": { |
97
|
|
|
* "name": "manageUsers", |
98
|
|
|
* "description": "Управление пользователями" |
99
|
|
|
* } |
100
|
|
|
* } |
101
|
|
|
* } |
102
|
|
|
* |
103
|
|
|
* @apiHeader {String} Authorization Токен. |
104
|
|
|
* |
105
|
|
|
* @apiSuccessExample {json} Успешно (200) |
106
|
|
|
* HTTP/1.1 200 OK |
107
|
|
|
* { |
108
|
|
|
* "data": { |
109
|
|
|
* "type": "right", |
110
|
|
|
* "id": "1", |
111
|
|
|
* "attributes": { |
112
|
|
|
* "name": "manageUsers", |
113
|
|
|
* "description": "Управление пользователями", |
114
|
|
|
* "created_at": "2016-10-17T07:38:21+0000", |
115
|
|
|
* "updated_at": "2016-10-17T07:38:21+0000", |
116
|
|
|
* "created_by": 1, |
117
|
|
|
* "updated_by": null |
118
|
|
|
* }, |
119
|
|
|
* "links": { |
120
|
|
|
* "self": "http://bootstrapi.dev/api/right/1" |
121
|
|
|
* } |
122
|
|
|
* } |
123
|
|
|
* } |
124
|
|
|
* |
125
|
|
|
* @apiUse StandardErrors |
126
|
|
|
* @apiUse UnauthorizedError |
127
|
|
|
*/ |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @api {patch} /right/:id Изменение права |
131
|
|
|
* @apiName UpdateRight |
132
|
|
|
* @apiGroup Right |
133
|
|
|
* |
134
|
|
|
* @apiDescription Метод для изменения права. |
135
|
|
|
* |
136
|
|
|
* @apiPermission admin |
137
|
|
|
* |
138
|
|
|
* @apiParam {String} name Имя права (уникальный) |
139
|
|
|
* @apiParam {String} description Человекопонятное описание |
140
|
|
|
* |
141
|
|
|
* @apiParamExample {json} Пример запроса: |
142
|
|
|
* { |
143
|
|
|
* "data": { |
144
|
|
|
* "attributes": { |
145
|
|
|
* "name": "manageUsers", |
146
|
|
|
* "description": "Управление пользователями" |
147
|
|
|
* } |
148
|
|
|
* } |
149
|
|
|
* } |
150
|
|
|
* |
151
|
|
|
* @apiHeader {String} Authorization Токен. |
152
|
|
|
* |
153
|
|
|
* @apiSuccessExample {json} Успешно (200) |
154
|
|
|
* HTTP/1.1 200 OK |
155
|
|
|
* { |
156
|
|
|
* "data": { |
157
|
|
|
* "type": "right", |
158
|
|
|
* "id": "1", |
159
|
|
|
* "attributes": { |
160
|
|
|
* "name": "manageUsers", |
161
|
|
|
* "description": "Управление пользователями", |
162
|
|
|
* "created_at": "2016-10-17T07:38:21+0000", |
163
|
|
|
* "updated_at": "2016-10-17T07:38:21+0000", |
164
|
|
|
* "created_by": 1, |
165
|
|
|
* "updated_by": 1 |
166
|
|
|
* }, |
167
|
|
|
* "links": { |
168
|
|
|
* "self": "http://bootstrapi.dev/api/right/1" |
169
|
|
|
* } |
170
|
|
|
* } |
171
|
|
|
* } |
172
|
|
|
* |
173
|
|
|
* @apiUse StandardErrors |
174
|
|
|
* @apiUse UnauthorizedError |
175
|
|
|
* @apiUse NotFoundError |
176
|
|
|
*/ |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @api {delete} /right/:id Удаление права |
180
|
|
|
* @apiName DeleteRight |
181
|
|
|
* @apiGroup Right |
182
|
|
|
* |
183
|
|
|
* @apiDescription Метод для удаления права. |
184
|
|
|
* |
185
|
|
|
* @apiPermission admin |
186
|
|
|
* |
187
|
|
|
* @apiParam {Number} id Id права |
188
|
|
|
* |
189
|
|
|
* @apiHeader {String} Authorization Токен. |
190
|
|
|
* |
191
|
|
|
* @apiSuccessExample {json} Успешно (204) |
192
|
|
|
* HTTP/1.1 204 OK |
193
|
|
|
* |
194
|
|
|
* @apiUse UnauthorizedError |
195
|
|
|
* @apiUse StandardErrors |
196
|
|
|
* @apiUse NotFoundError |
197
|
|
|
*/ |
198
|
|
|
|
199
|
|
|
final class RightSchema extends BaseSchema |
200
|
|
|
{ |
201
|
|
|
protected $resourceType = 'right'; |
202
|
|
|
|
203
|
|
|
public function getId($right) |
204
|
|
|
{ |
205
|
|
|
return $right->id; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
View Code Duplication |
public function getAttributes($right) |
|
|
|
|
209
|
|
|
{ |
210
|
|
|
return [ |
211
|
|
|
'name' => $right->name, |
212
|
|
|
'description' => $right->description, |
213
|
|
|
'created_at' => Carbon::parse($right->created_at)->setTimezone('UTC')->format(Carbon::ISO8601), |
214
|
|
|
'updated_at' => Carbon::parse($right->updated_at)->setTimezone('UTC')->format(Carbon::ISO8601), |
215
|
|
|
'created_by' => $right->created_by, |
216
|
|
|
'updated_by' => $right->updated_by, |
217
|
|
|
]; |
218
|
|
|
} |
219
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.