Completed
Push — master ( f65d8f...4f3de5 )
by Pavel
04:14 queued 01:54
created

RoleSchema::getRelationships()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace App\Schema;
3
4
use \Carbon\Carbon;
5
6
/**
7
 * @api {get} /role Список ролей
8
 * @apiName GetRoles
9
 * @apiGroup Role
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": "role",
23
 *           "id": "1",
24
 *           "attributes": {
25
 *             "name": "admin",
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
 *           "relationships": {
33
 *             "rights": {
34
 *               "data": []
35
 *             }
36
 *           },
37
 *           "links": {
38
 *             "self": "http://bootstrapi.dev/api/role/1"
39
 *           }
40
 *         }
41
 *       ]
42
 *     }
43
 *
44
 * @apiUse StandardErrors
45
 * @apiUse UnauthorizedError
46
 */
47
48
/**
49
 * @api {get} /role/:id?include=rights&fields[right]=name Получить роль
50
 * @apiName GetRole
51
 * @apiGroup Role
52
 *
53
 * @apiDescription Метод для получения роли.
54
 *
55
 * @apiPermission user
56
 *
57
 * @apiParam {Number} id Id роли
58
 *
59
 * @apiHeader {String} Authorization Токен.
60
 *
61
 * @apiSuccessExample {json} Успешно (200)
62
 *     HTTP/1.1 200 OK
63
 *     {
64
 *       "data": {
65
 *         "type": "role",
66
 *         "id": "1",
67
 *         "attributes": {
68
 *           "name": "admin",
69
 *           "description": "Администратор",
70
 *           "created_at": "2016-10-17T07:38:21+0000",
71
 *           "updated_at": "2016-10-17T07:38:21+0000",
72
 *           "created_by": 0,
73
 *           "updated_by": null
74
 *         },
75
 *         "relationships": {
76
 *           "rights": {
77
 *             "data": []
78
 *           }
79
 *         },
80
 *         "links": {
81
 *           "self": "http://bootstrapi.dev/api/role/1"
82
 *         }
83
 *       }
84
 *     }
85
 *
86
 * @apiUse StandardErrors
87
 * @apiUse UnauthorizedError
88
 * @apiUse NotFoundError
89
 */
90
91
/**
92
 * @api {post} /role Создание роли
93
 * @apiName CreateRole
94
 * @apiGroup Role
95
 *
96
 * @apiDescription Метод для создания новой роли.
97
 *
98
 * @apiPermission admin
99
 *
100
 * @apiParam {String} name Имя роли (уникальный)
101
 * @apiParam {String} description Человекопонятное описание
102
 *
103
 * @apiParamExample {json} Пример запроса:
104
 *    {
105
 *      "data":{
106
 *        "attributes":{
107
 *          "name":"guest",
108
 *          "description": "Гость"
109
 *        }
110
 *      }
111
 *    }
112
 *
113
 * @apiHeader {String} Authorization Токен.
114
 *
115
 * @apiSuccessExample {json} Успешно (200)
116
 *     HTTP/1.1 200 OK
117
 *     {
118
 *       "data": {
119
 *         "type": "role",
120
 *         "id": "2",
121
 *         "attributes": {
122
 *           "name": "guest",
123
 *           "description": "Гость",
124
 *           "created_at": "2016-10-17T07:38:21+0000",
125
 *           "updated_at": "2016-10-17T07:38:21+0000",
126
 *           "created_by": 1,
127
 *           "updated_by": null
128
 *         },
129
 *         "relationships": {
130
 *            "rights": {
131
 *             "data": []
132
 *           }
133
 *         },
134
 *         "links": {
135
 *           "self": "http://bootstrapi.dev/api/role/2"
136
 *         }
137
 *       }
138
 *     }
139
 *
140
 * @apiUse StandardErrors
141
 * @apiUse UnauthorizedError
142
 */
143
144
/**
145
 * @api {patch} /role/:id Изменение роли
146
 * @apiName UpdateRole
147
 * @apiGroup Role
148
 *
149
 * @apiDescription Метод для изменения роли.
150
 *
151
 * @apiPermission admin
152
 *
153
 * @apiParam {String} name Имя роли (уникальный)
154
 * @apiParam {String} description Человекопонятное описание
155
 *
156
 * @apiParamExample {json} Пример запроса:
157
 *    {
158
 *      "data":{
159
 *        "attributes":{
160
 *          "name":"guest",
161
 *          "description": "Гость"
162
 *        }
163
 *      }
164
 *    }
165
 *
166
 * @apiHeader {String} Authorization Токен.
167
 *
168
 * @apiSuccessExample {json} Успешно (200)
169
 *     HTTP/1.1 200 OK
170
 *     {
171
 *       "data": {
172
 *         "type": "role",
173
 *         "id": "2",
174
 *         "attributes": {
175
 *           "name": "guest",
176
 *           "description": "Гость",
177
 *           "created_at": "2016-10-17T07:38:21+0000",
178
 *           "updated_at": "2016-10-17T07:38:21+0000",
179
 *           "created_by": 1,
180
 *           "updated_by": null
181
 *         },
182
 *         "relationships": {
183
 *            "rights": {
184
 *             "data": []
185
 *           }
186
 *         },
187
 *         "links": {
188
 *           "self": "http://bootstrapi.dev/api/role/2"
189
 *         }
190
 *       }
191
 *     }
192
 *
193
 * @apiUse StandardErrors
194
 * @apiUse UnauthorizedError
195
 * @apiUse NotFoundError
196
 */
197
198
/**
199
     * @api {delete} /role/:id Удаление роли
200
     * @apiName DeleteRole
201
     * @apiGroup Role
202
     *
203
     * @apiDescription Метод для удаления роли.
204
     *
205
     * @apiPermission admin
206
     *
207
     * @apiParam {Number} id Id роли
208
     *
209
     * @apiHeader {String} Authorization Токен.
210
     *
211
     * @apiSuccessExample {json} Успешно (204)
212
     *     HTTP/1.1 204 OK
213
     *
214
     * @apiUse UnauthorizedError
215
     * @apiUse StandardErrors
216
     * @apiUse NotFoundError
217
     */
218
final class RoleSchema extends BaseSchema
219
{
220
    protected $resourceType = 'role';
221
222
    public function getId($role)
223
    {
224
        return $role->id;
225
    }
226
227 View Code Duplication
    public function getAttributes($role)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
228
    {
229
        return [
230
            'name'        => $role->name,
231
            'description' => $role->description,
232
            'created_at'  => Carbon::parse($role->created_at)->setTimezone('UTC')->format(Carbon::ISO8601),
233
            'updated_at'  => Carbon::parse($role->updated_at)->setTimezone('UTC')->format(Carbon::ISO8601),
234
            'created_by'  => $role->created_by,
235
            'updated_by'  => $role->updated_by,
236
        ];
237
    }
238
239
    public function getRelationships($role, $isPrimary, array $includeList)
240
    {
241
        return [
242
            'rights' => [
243
                self::DATA => $role->rights,
244
            ],
245
        ];
246
    }
247
}