Completed
Pull Request — master (#20)
by Pavel
02:25
created

UserSchema::getRelationships()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 8
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} /user List of user
8
 * @apiName GetUsers
9
 * @apiGroup User
10
 *
11
 * @apiDescription Get list of user
12
 *
13
 * @apiSuccessExample {json} Success (200)
14
 *     HTTP/1.1 200 OK
15
 *     {
16
 *       "data": [
17
 *         {
18
 *           "type": "user",
19
 *           "id": "1",
20
 *           "attributes": {
21
 *             "email": "String",
22
 *             "full_name": "String",
23
 *             "password": "String",
24
 *             "password_reset_token": "String",
25
 *             "role_id": 1,
26
 *             "created_by": 1,
27
 *             "updated_by": 1,
28
 *             "created_at": "2016-10-17T07:38:21+0000",
29
 *             "updated_at": "2016-10-17T07:38:21+0000",
30
 *             "deleted_at": "2016-10-17T07:38:21+0000",
31
 *             "status": 1
32
 *           },
33
 *           "links": {
34
 *             "self": "/user/1"
35
 *           }
36
 *         }
37
 *       ]
38
 *     }
39
 *
40
 * @apiUse StandardErrors
41
 */
42
43
/**
44
 * @api {get} /user/:id Get user
45
 * @apiName GetUser
46
 * @apiGroup User
47
 *
48
 * @apiDescription Get user.
49
 *
50
 * @apiParam {Number} id Id user
51
 *
52
 * @apiSuccessExample {json} Success (200)
53
 *     HTTP/1.1 200 OK
54
 *     {
55
 *       "data": {
56
 *         "type": "user",
57
 *         "id": "1",
58
 *         "attributes": {
59
 *             "email": "String",
60
 *             "full_name": "String",
61
 *             "password": "String",
62
 *             "password_reset_token": "String",
63
 *             "role_id": 1,
64
 *             "created_by": 1,
65
 *             "updated_by": 1,
66
 *             "created_at": "2016-10-17T07:38:21+0000",
67
 *             "updated_at": "2016-10-17T07:38:21+0000",
68
 *             "deleted_at": "2016-10-17T07:38:21+0000",
69
 *             "status": 1
70
 *         },
71
 *         "links": {
72
 *           "self": "/user/1"
73
 *         }
74
 *       }
75
 *     }
76
 *
77
 * @apiUse StandardErrors
78
 * @apiUse NotFoundError
79
 */
80
81
/**
82
 * @api {post} /user Create user
83
 * @apiName CreateUser
84
 * @apiGroup User
85
 *
86
 * @apiDescription Create user.
87
 *
88
 * @apiParam {String} email
89
 * @apiParam {String} full_name
90
 * @apiParam {String} password
91
 * @apiParam {String} password_reset_token
92
 * @apiParam {Integer} role_id
93
 * @apiParam {Integer} created_by
94
 * @apiParam {Integer} updated_by
95
 * @apiParam {Datetime} created_at
96
 * @apiParam {Datetime} updated_at
97
 * @apiParam {Datetime} deleted_at
98
 * @apiParam {Integer} status
99
 *
100
 * @apiParamExample {json} Example request:
101
 *    {
102
 *      "data": {
103
 *        "attributes": {
104
 *             "email": "String",
105
 *             "full_name": "String",
106
 *             "password": "String",
107
 *             "password_reset_token": "String",
108
 *             "role_id": 1,
109
 *             "created_by": 1,
110
 *             "updated_by": 1,
111
 *             "created_at": "2016-10-17T07:38:21+0000",
112
 *             "updated_at": "2016-10-17T07:38:21+0000",
113
 *             "deleted_at": "2016-10-17T07:38:21+0000",
114
 *             "status": 1
115
 *        }
116
 *      }
117
 *    }
118
 *
119
 * @apiSuccessExample {json} Success (200)
120
 *     HTTP/1.1 200 OK
121
 *     {
122
 *       "data": {
123
 *         "type": "user",
124
 *         "id": "1",
125
 *         "attributes": {
126
 *             "email": "String",
127
 *             "full_name": "String",
128
 *             "password": "String",
129
 *             "password_reset_token": "String",
130
 *             "role_id": 1,
131
 *             "created_by": 1,
132
 *             "updated_by": 1,
133
 *             "created_at": "2016-10-17T07:38:21+0000",
134
 *             "updated_at": "2016-10-17T07:38:21+0000",
135
 *             "deleted_at": "2016-10-17T07:38:21+0000",
136
 *             "status": 1
137
 *         },
138
 *         "links": {
139
 *           "self": "/user/1"
140
 *         }
141
 *       }
142
 *     }
143
 *
144
 * @apiUse StandardErrors
145
 */
146
147
/**
148
 * @api {patch} /user/:id Update user
149
 * @apiName UpdateUser
150
 * @apiGroup User
151
 *
152
 * @apiDescription Update user.
153
 *
154
 * @apiParam {String} email
155
 * @apiParam {String} full_name
156
 * @apiParam {String} password
157
 * @apiParam {String} password_reset_token
158
 * @apiParam {Integer} role_id
159
 * @apiParam {Integer} created_by
160
 * @apiParam {Integer} updated_by
161
 * @apiParam {Datetime} created_at
162
 * @apiParam {Datetime} updated_at
163
 * @apiParam {Datetime} deleted_at
164
 * @apiParam {Integer} status
165
 *
166
 * @apiParamExample {json} Example request:
167
 *    {
168
 *      "data": {
169
 *        "attributes": {
170
 *             "email": "String",
171
 *             "full_name": "String",
172
 *             "password": "String",
173
 *             "password_reset_token": "String",
174
 *             "role_id": 1,
175
 *             "created_by": 1,
176
 *             "updated_by": 1,
177
 *             "created_at": "2016-10-17T07:38:21+0000",
178
 *             "updated_at": "2016-10-17T07:38:21+0000",
179
 *             "deleted_at": "2016-10-17T07:38:21+0000",
180
 *             "status": 1
181
 *        }
182
 *      }
183
 *    }
184
 *
185
 * @apiSuccessExample {json} Success (200)
186
 *     HTTP/1.1 200 OK
187
 *     {
188
 *       "data": {
189
 *         "type": "user",
190
 *         "id": "1",
191
 *         "attributes": {
192
 *             "email": "String",
193
 *             "full_name": "String",
194
 *             "password": "String",
195
 *             "password_reset_token": "String",
196
 *             "role_id": 1,
197
 *             "created_by": 1,
198
 *             "updated_by": 1,
199
 *             "created_at": "2016-10-17T07:38:21+0000",
200
 *             "updated_at": "2016-10-17T07:38:21+0000",
201
 *             "deleted_at": "2016-10-17T07:38:21+0000",
202
 *             "status": 1
203
 *         },
204
 *         "links": {
205
 *           "self": "/user/1"
206
 *         }
207
 *       }
208
 *     }
209
 *
210
 * @apiUse StandardErrors
211
 * @apiUse NotFoundError
212
 */
213
214
/**
215
 * @api {delete} /user/:id Delete user
216
 * @apiName DeleteUser
217
 * @apiGroup User
218
 *
219
 * @apiDescription Delete user.
220
 *
221
 * @apiParam {Number} id Id user
222
 *
223
 * @apiSuccessExample {json} Success (204)
224
 *     HTTP/1.1 204 OK
225
 *
226
 * @apiUse StandardErrors
227
 * @apiUse NotFoundError
228
 */
229
230
final class UserSchema extends BaseSchema
231
{
232
    protected $resourceType = 'user';
233
234
    public function getId($entity)
235
    {
236
        return $entity->id;
237
    }
238
239
    public function getAttributes($entity)
240
    {
241
        return [
242
			'email'	=> (string)$entity->email,
243
			'full_name'	=> (string)$entity->full_name,
244
			'password'	=> (string)$entity->password,
245
			'password_reset_token'	=> (string)$entity->password_reset_token,
246
			'role_id'	=> (integer)$entity->role_id,
247
			'created_by'	=> (integer)$entity->created_by,
248
			'updated_by'	=> (integer)$entity->updated_by,
249
			'created_at'	=> Carbon::parse($entity->created_at)->setTimezone('UTC')->format(Carbon::ISO8601),
250
			'updated_at'	=> Carbon::parse($entity->updated_at)->setTimezone('UTC')->format(Carbon::ISO8601),
251
			'deleted_at'	=> Carbon::parse($entity->deleted_at)->setTimezone('UTC')->format(Carbon::ISO8601),
252
			'status'	=> (integer)$entity->status,
253
        ];
254
    }
255
}
256