EmploymentStatusController::update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the HRis Software package.
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * Licensed under the 3-clause BSD License.
9
 *
10
 * This source file is subject to the 3-clause BSD License that is
11
 * bundled with this package in the LICENSE file.
12
 *
13
 * @version    alpha
14
 *
15
 * @author     Bertrand Kintanar <[email protected]>
16
 * @license    BSD License (3-clause)
17
 * @copyright  (c) 2014-2016, b8 Studios, Ltd
18
 *
19
 * @link       http://github.com/HB-Co/HRis
20
 */
21
22
namespace HRis\Api\Controllers\Admin\Job;
23
24
use HRis\Api\Requests\Admin\Job\EmploymentStatusRequest;
25
use Irradiate\Api\Controllers\BaseController;
26
use Irradiate\Eloquent\EmploymentStatus;
27
use Swagger\Annotations as SWG;
28
use Symfony\Component\HttpFoundation\Response;
29
30
/**
31
 * Class EmploymentStatusController.
32
 */
33 View Code Duplication
class EmploymentStatusController extends BaseController
0 ignored issues
show
Duplication introduced by
This class 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...
34
{
35
    /**
36
     * @var EmploymentStatus
37
     */
38
    protected $employment_status;
39
40
    /**
41
     * @param EmploymentStatus $employment_status
42
     *
43
     * @author Bertrand Kintanar <[email protected]>
44
     */
45 14
    public function __construct(EmploymentStatus $employment_status)
46
    {
47 14
        $this->employment_status = $employment_status;
48 14
    }
49
50
    /**
51
     * Delete the Admin - Employment Status.
52
     *
53
     * @SWG\Delete(
54
     *     path="/admin/job/employment-status/{employment_status}",
55
     *     description="This route provides the ability to delete an Employment Status.",
56
     *     tags={"Administration"},
57
     *     consumes={"application/json"},
58
     *     summary="Deletes an Employment Status.",
59
     *     @SWG\Response(response="200", description="Success",
60
     *         @SWG\Schema(
61
     *             title="data",
62
     *             type="object",
63
     *             required={"message", "status_code"},
64
     *             @SWG\Property(property="message", type="string", default="Record successfully deleted.", description="Status message from server"),
65
     *             @SWG\Property(property="status_code", type="integer", default=200, description="Status code from server"),
66
     *         )
67
     *     ),
68
     *     @SWG\Response(response="400", description="Token not provided",
69
     *         @SWG\Schema(
70
     *             title="data",
71
     *             type="object",
72
     *             required={"message", "status_code", "debug"},
73
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
74
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
75
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
76
     *         )
77
     *     ),
78
     *     @SWG\Response(response="422", description="422 Unprocessable Entity",
79
     *         @SWG\Schema(
80
     *             title="data",
81
     *             type="object",
82
     *             required={"message", "status_code"},
83
     *             @SWG\Property(property="message", type="string", default="422 Unprocessable Entity", description="Status message from server"),
84
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
85
     *         )
86
     *     ),
87
     *     @SWG\Parameter(
88
     *         name="employment_status",
89
     *         in="path",
90
     *         description="Employment status id to be deleted",
91
     *         required=true,
92
     *         type="integer",
93
     *         format="int64",
94
     *         default=1,
95
     *     ),
96
     *     @SWG\Parameter(
97
     *         name="Authorization",
98
     *         in="header",
99
     *         description="JWT Token",
100
     *         required=true,
101
     *         type="string",
102
     *         default="Bearer "
103
     *     ),
104
     * )
105
     *
106
     * @param EmploymentStatus        $employment_status
107
     * @param EmploymentStatusRequest $request
108
     *
109
     * @return \Dingo\Api\Http\Response
110
     *
111
     * @author Bertrand Kintanar <[email protected]>
112
     */
113 2
    public function destroy(EmploymentStatus $employment_status, EmploymentStatusRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
114
    {
115 2
        return $this->destroyModel($employment_status, $this->employment_status);
116
    }
117
118
    /**
119
     * Retrieves a paginate aware collection of Employment Statuses.
120
     *
121
     * @SWG\Get(
122
     *     path="/admin/job/employment-status",
123
     *     description="This route provides the ability to retrieve a paginate aware collection of Employment Statuses.",
124
     *     tags={"Administration"},
125
     *     consumes={"application/json"},
126
     *     summary="Retrieves a paginate aware collection of Employment Statuses.",
127
     *     @SWG\Response(response="200", description="Success",
128
     *         @SWG\Schema(
129
     *             title="data",
130
     *             type="object",
131
     *             required={"data", "table", "message", "status_code"},
132
     *             @SWG\Property(property="data", type="object",
133
     *                 @SWG\Property(property="total", type="integer", default=22),
134
     *                 @SWG\Property(property="per_page", type="integer", default=10),
135
     *                 @SWG\Property(property="current_page", type="integer", default=1),
136
     *                 @SWG\Property(property="last_page", type="integer", default=3),
137
     *                 @SWG\Property(property="next_page_url", type="string", default="https://api.hris.dev/api/admin/job/employment-status?page=2"),
138
     *                 @SWG\Property(property="prev_page_url", type="string", default="null"),
139
     *                 @SWG\Property(property="from", type="integer", default=1),
140
     *                 @SWG\Property(property="to", type="integer", default=10),
141
     *                 @SWG\Property(property="data", type="array",
142
     *                     @SWG\Items(ref="#/definitions/EmploymentStatus"),
143
     *                 ),
144
     *             ),
145
     *             @SWG\Property(property="table", type="object",
146
     *                 @SWG\Property(property="title", type="string", default="Employment Status"),
147
     *                 @SWG\Property(property="permission", type="string", default="admin.job.employment-status"),
148
     *                 @SWG\Property(property="headers", type="array",
149
     *                     @SWG\Items(title="Id", type="string", default="Id"),
150
     *                 ),
151
     *                 @SWG\Property(property="model", type="object",
152
     *                     @SWG\Property(property="singular", type="string", default="employment_status"),
153
     *                     @SWG\Property(property="plural", type="string", default="employment_statuses"),
154
     *                     @SWG\Property(property="dashed", type="string", default="employment-statuses"),
155
     *                 ),
156
     *                 @SWG\Property(property="data", type="array",
157
     *                     @SWG\Items(ref="#/definitions/EmploymentStatus"),
158
     *                 ),
159
     *             ),
160
     *             @SWG\Property(property="message", type="string", default="Record successfully added.", description="Status message from server"),
161
     *             @SWG\Property(property="status_code", type="integer", default=200, description="Status code from server"),
162
     *         )
163
     *     ),
164
     *     @SWG\Parameter(
165
     *         name="page",
166
     *         in="query",
167
     *         description="Page number for pagination",
168
     *         required=true,
169
     *         type="string",
170
     *         default="1"
171
     *     ),
172
     *     @SWG\Parameter(
173
     *         name="Authorization",
174
     *         in="header",
175
     *         description="JWT Token",
176
     *         required=true,
177
     *         type="string",
178
     *         default="Bearer "
179
     *     ),
180
     * )
181
     *
182
     * @param EmploymentStatusRequest $request
183
     *
184
     * @return \Dingo\Api\Http\Response
185
     *
186
     * @author Bertrand Kintanar <[email protected]>
187
     */
188 2
    public function index(EmploymentStatusRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
189
    {
190 2
        $employment_statuses = $this->employment_status->paginate(ROWS_PER_PAGE);
191
192 2
        $data = ['data' => $employment_statuses, 'table' => $this->setupDataTable($employment_statuses)];
193
194 2
        return $this->responseAPI(Response::HTTP_OK, SUCCESS_RETRIEVE_MESSAGE, $data);
195
    }
196
197
    /**
198
     * Setup table for employment status.
199
     *
200
     * @param $employment_statuses
201
     *
202
     * @return array
203
     *
204
     * @author Bertrand Kintanar <[email protected]>
205
     */
206 2
    protected function setupDataTable($employment_statuses)
207
    {
208 2
        $table = [];
209
210 2
        $table['title'] = 'Employment Statuses';
211 2
        $table['permission'] = 'admin.job.employment-status';
212 2
        $table['headers'] = ['Id', 'Name'];
213 2
        $table['model'] = [
214 2
            'singular' => 'employment_status',
215 2
            'plural'   => 'employment_statuses',
216 2
            'dashed'   => 'employment-statuses',
217
        ];
218 2
        $table['items'] = $employment_statuses;
219
220 2
        return $table;
221
    }
222
223
    /**
224
     * Stores a single instance of Employment Status.
225
     *
226
     * @SWG\Post(
227
     *     path="/admin/job/employment-status",
228
     *     description="This route provides the ability to store a single instance of Employment Status.",
229
     *     tags={"Administration"},
230
     *     consumes={"application/json"},
231
     *     summary="Stores a single instance of Employment Status.",
232
     *     @SWG\Response(response="201", description="Success",
233
     *         @SWG\Schema(
234
     *             title="data",
235
     *             type="object",
236
     *             required={"employment_status", "message", "status_code"},
237
     *             @SWG\Property(property="employment_status", ref="#/definitions/EmploymentStatus"),
238
     *             @SWG\Property(property="message", type="string", default="Record successfully added.", description="Status message from server"),
239
     *             @SWG\Property(property="status_code", type="integer", default=201, description="Status code from server"),
240
     *         )
241
     *     ),
242
     *     @SWG\Response(response="400", description="Token not provided",
243
     *         @SWG\Schema(
244
     *             title="data",
245
     *             type="object",
246
     *             required={"message", "status_code", "debug"},
247
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
248
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
249
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
250
     *         )
251
     *     ),
252
     *     @SWG\Response(response="422", description="Unable to add record to the database.",
253
     *         @SWG\Schema(
254
     *             title="data",
255
     *             type="object",
256
     *             required={"message", "status_code"},
257
     *             @SWG\Property(property="message", type="string", default="Unable to add record to the database.", description="Status message from server"),
258
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
259
     *         )
260
     *     ),
261
     *     @SWG\Parameter(
262
     *         name="employment_status",
263
     *         in="body",
264
     *         required=true,
265
     *         @SWG\Property(ref="#/definitions/EmploymentStatus")
266
     *     ),
267
     *     @SWG\Parameter(
268
     *         name="Authorization",
269
     *         in="header",
270
     *         description="JWT Token",
271
     *         required=true,
272
     *         type="string",
273
     *         default="Bearer "
274
     *     ),
275
     * )
276
     *
277
     * @param EmploymentStatusRequest $request
278
     *
279
     * @return \Dingo\Api\Http\Response
280
     *
281
     * @author Bertrand Kintanar <[email protected]>
282
     */
283 6
    public function store(EmploymentStatusRequest $request)
284
    {
285 6
        return $this->storeModel($request, $this->employment_status, 'employment_status');
286
    }
287
288
    /**
289
     * Retrieves a single instance of Employment Status.
290
     *
291
     * @SWG\Get(
292
     *     path="/admin/job/employment-status/{employment_status}",
293
     *     description="This route provides the ability to retrieve a single instance of Employment Status.",
294
     *     tags={"Administration"},
295
     *     consumes={"application/json"},
296
     *     summary="Retrieves a single instance of Employment Status.",
297
     *     @SWG\Response(response="200", description="Success",
298
     *         @SWG\Schema(
299
     *             title="data",
300
     *             type="object",
301
     *             required={"employment_status", "message", "status_code"},
302
     *             @SWG\Property(property="employment_status", ref="#/definitions/EmploymentStatus"),
303
     *             @SWG\Property(property="message", type="string", default="Record successfully retrieved.", description="Status message from server"),
304
     *             @SWG\Property(property="status_code", type="integer", default=200, description="Status code from server"),
305
     *         )
306
     *     ),
307
     *     @SWG\Response(response="400", description="Token not provided",
308
     *         @SWG\Schema(
309
     *             title="data",
310
     *             type="object",
311
     *             required={"message", "status_code", "debug"},
312
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
313
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
314
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
315
     *         )
316
     *     ),
317
     *     @SWG\Response(response="422", description="422 Unprocessable Entity",
318
     *         @SWG\Schema(
319
     *             title="data",
320
     *             type="object",
321
     *             required={"message", "status_code"},
322
     *             @SWG\Property(property="message", type="string", default="422 Unprocessable Entity", description="Status message from server"),
323
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
324
     *         )
325
     *     ),
326
     *     @SWG\Parameter(
327
     *         name="employment_status",
328
     *         in="path",
329
     *         description="Employment status id to be retrieved.",
330
     *         required=true,
331
     *         type="integer",
332
     *         format="int64",
333
     *         default=1,
334
     *     ),
335
     *     @SWG\Parameter(
336
     *         name="Authorization",
337
     *         in="header",
338
     *         description="JWT Token",
339
     *         required=true,
340
     *         type="string",
341
     *         default="Bearer "
342
     *     ),
343
     * )
344
     *
345
     * @param EmploymentStatus $employment_status
346
     *
347
     * @return \Dingo\Api\Http\Response
348
     *
349
     * @author Bertrand Kintanar <[email protected]>
350
     */
351 2
    public function show(EmploymentStatus $employment_status)
352
    {
353 2
        return $this->responseAPI(Response::HTTP_OK, SUCCESS_RETRIEVE_MESSAGE, compact('employment_status'));
354
    }
355
356
    /**
357
     * Updates a single instance of Employment Status.
358
     *
359
     * @SWG\Patch(
360
     *     path="/admin/job/employment-status",
361
     *     description="This route provides the ability to update a single instance of Employment Status.",
362
     *     tags={"Administration"},
363
     *     consumes={"application/json"},
364
     *     summary="Updates a single instance of Employment Status",
365
     *     @SWG\Response(response="200", description="Success",
366
     *         @SWG\Schema(
367
     *             title="data",
368
     *             type="object",
369
     *             required={"message", "status_code"},
370
     *             @SWG\Property(property="message", type="string", default="Record successfully updated.", description="Status message from server"),
371
     *             @SWG\Property(property="status_code", type="integer", default=200, description="Status code from server"),
372
     *         )
373
     *     ),
374
     *     @SWG\Response(response="400", description="Token not provided",
375
     *         @SWG\Schema(
376
     *             title="data",
377
     *             type="object",
378
     *             required={"message", "status_code", "debug"},
379
     *             @SWG\Property(property="message", type="string", default="Token not provided", description="Error message from server"),
380
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
381
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
382
     *         )
383
     *     ),
384
     *     @SWG\Response(response="404", description="Unable to retrieve record from database.",
385
     *         @SWG\Schema(
386
     *             title="data",
387
     *             type="object",
388
     *             required={"message", "status_code", "debug"},
389
     *             @SWG\Property(property="message", type="string", default="Unable to retrieve record from database.", description="Error message from server"),
390
     *             @SWG\Property(property="status_code", type="integer", default=400, description="Status code from server"),
391
     *             @SWG\Property(property="debug", type="object", description="Debug back trace"),
392
     *         )
393
     *     ),
394
     *     @SWG\Response(response="422", description="Unable to update record.",
395
     *         @SWG\Schema(
396
     *             title="data",
397
     *             type="object",
398
     *             required={"message", "status_code"},
399
     *             @SWG\Property(property="message", type="string", default="Unable to update record.", description="Status message from server"),
400
     *             @SWG\Property(property="status_code", type="integer", default=422, description="Status code from server"),
401
     *         )
402
     *     ),
403
     *     @SWG\Parameter(
404
     *         name="employment_status",
405
     *         in="body",
406
     *         required=true,
407
     *         description="employment status object that needs to be updated",
408
     *         @SWG\Property(ref="#/definitions/EmploymentStatus")
409
     *     ),
410
     *     @SWG\Parameter(
411
     *         name="Authorization",
412
     *         in="header",
413
     *         description="JWT Token",
414
     *         required=true,
415
     *         type="string",
416
     *         default="Bearer "
417
     *     ),
418
     * )
419
     *
420
     * @param EmploymentStatusRequest $request
421
     *
422
     * @return \Dingo\Api\Http\Response
423
     *
424
     * @author Bertrand Kintanar <[email protected]>
425
     */
426 4
    public function update(EmploymentStatusRequest $request)
427
    {
428 4
        return $this->updateModel($request, $this->employment_status, ['name', 'class']);
429
    }
430
}
431