PayGradesController::store()   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\PayGradeRequest;
25
use Irradiate\Api\Controllers\BaseController;
26
use Irradiate\Eloquent\PayGrade;
27
use Swagger\Annotations as SWG;
28
use Symfony\Component\HttpFoundation\Response;
29
30
/**
31
 * Class PayGradesController.
32
 */
33 View Code Duplication
class PayGradesController 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 PayGrade
37
     */
38
    protected $pay_grade;
39
40
    /**
41
     * @param PayGrade $pay_grade
42
     *
43
     * @author Bertrand Kintanar <[email protected]>
44
     */
45 14
    public function __construct(PayGrade $pay_grade)
46
    {
47 14
        $this->pay_grade = $pay_grade;
48 14
    }
49
50
    /**
51
     * Deletes a single instance of Pay Grade.
52
     *
53
     * @SWG\Delete(
54
     *     path="/admin/job/pay-grades/{pay_grade}",
55
     *     description="This route provides the ability to delete a Pay Grade.",
56
     *     tags={"Administration"},
57
     *     consumes={"application/json"},
58
     *     summary="Deletes a single instance of Pay Grade.",
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="pay_grade",
89
     *         in="path",
90
     *         description="Pay grade 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 PayGrade        $pay_grade
107
     * @param PayGradeRequest $request
108
     *
109
     * @return \Dingo\Api\Http\Response
110
     *
111
     * @author Bertrand Kintanar <[email protected]>
112
     */
113 2
    public function destroy(PayGrade $pay_grade, PayGradeRequest $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($pay_grade, $this->pay_grade);
116
    }
117
118
    /**
119
     * Retrieves a paginate aware collection of Pay Grades.
120
     *
121
     * @SWG\Get(
122
     *     path="/admin/job/pay-grades",
123
     *     description="This route provides the ability to retrieve a paginate aware collection of Pay Grades.",
124
     *     tags={"Administration"},
125
     *     consumes={"application/json"},
126
     *     summary="Retrieves a paginate aware collection of Pay Grades.",
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/pay-grades?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/PayGrade"),
143
     *                 ),
144
     *             ),
145
     *             @SWG\Property(property="table", type="object",
146
     *                 @SWG\Property(property="title", type="string", default="Pay Grade"),
147
     *                 @SWG\Property(property="permission", type="string", default="admin.job.pay-grades"),
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="pay_grade"),
153
     *                     @SWG\Property(property="plural", type="string", default="pay_grades"),
154
     *                     @SWG\Property(property="dashed", type="string", default="pay-grades"),
155
     *                 ),
156
     *                 @SWG\Property(property="data", type="array",
157
     *                     @SWG\Items(ref="#/definitions/PayGrade"),
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 PayGradeRequest $request
183
     *
184
     * @return \Dingo\Api\Http\Response
185
     *
186
     * @author Bertrand Kintanar <[email protected]>
187
     */
188 2
    public function index(PayGradeRequest $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
        $pay_grades = $this->pay_grade->paginate(ROWS_PER_PAGE);
191
192 2
        $data = ['data' => $pay_grades, 'table' => $this->setupDataTable($pay_grades)];
193
194 2
        return $this->responseAPI(Response::HTTP_OK, SUCCESS_RETRIEVE_MESSAGE, $data);
195
    }
196
197
    /**
198
     * Setup table for pay grade.
199
     *
200
     * @param $pay_grades
201
     *
202
     * @return array
203
     *
204
     * @author Bertrand Kintanar <[email protected]>
205
     */
206 2
    protected function setupDataTable($pay_grades)
207
    {
208 2
        $table = [];
209
210 2
        $table['title'] = 'Pay Grades';
211 2
        $table['permission'] = 'admin.job.pay-grades';
212 2
        $table['headers'] = ['Id', 'Pay Grade', 'Minimum Salary', 'Maximum Salary'];
213 2
        $table['model'] = [
214 2
            'singular' => 'pay_grade',
215 2
            'plural'   => 'pay_grades',
216 2
            'dashed'   => 'pay-grades',
217
        ];
218 2
        $table['items'] = $pay_grades;
219
220 2
        return $table;
221
    }
222
223
    /**
224
     * Stores a single instance of Pay Grade.
225
     *
226
     * @SWG\Post(
227
     *     path="/admin/job/pay-grades",
228
     *     description="This route provides the ability to store a single instance of Pay Grade.",
229
     *     tags={"Administration"},
230
     *     consumes={"application/json"},
231
     *     summary="Stores a single instance of Pay Grade.",
232
     *     @SWG\Response(response="201", description="Success",
233
     *         @SWG\Schema(
234
     *             title="data",
235
     *             type="object",
236
     *             required={"pay_grade", "message", "status_code"},
237
     *             @SWG\Property(property="pay_grade", ref="#/definitions/PayGrade"),
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="pay_grade",
263
     *         in="body",
264
     *         required=true,
265
     *         @SWG\Property(ref="#/definitions/PayGrade")
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 PayGradeRequest $request
278
     *
279
     * @return \Dingo\Api\Http\Response
280
     *
281
     * @author Bertrand Kintanar <[email protected]>
282
     */
283 8
    public function store(PayGradeRequest $request)
284
    {
285 8
        return $this->storeModel($request, $this->pay_grade, 'pay_grade');
286
    }
287
288
    /**
289
     * Retrieves a single instance of Pay Grade.
290
     *
291
     * @SWG\Get(
292
     *     path="/admin/job/pay-grades/{pay_grade}",
293
     *     description="This route provides the ability to retrieve a single instance of Pay Grade.",
294
     *     tags={"Administration"},
295
     *     consumes={"application/json"},
296
     *     summary="Retrieves a single instance of Pay Grade.",
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/PayGrade"),
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="pay_grade",
328
     *         in="path",
329
     *         description="Pay grade 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 PayGrade $pay_grade
346
     *
347
     * @return \Dingo\Api\Http\Response
348
     *
349
     * @author Bertrand Kintanar <[email protected]>
350
     */
351 2
    public function show(PayGrade $pay_grade)
352
    {
353 2
        return $this->responseAPI(Response::HTTP_OK, SUCCESS_RETRIEVE_MESSAGE, compact('pay_grade'));
354
    }
355
356
    /**
357
     * Updates a single instance of Pay Grade.
358
     *
359
     * @SWG\Patch(
360
     *     path="/admin/job/pay-grades",
361
     *     description="This route provides the ability to update a single instance of Pay Grade.",
362
     *     tags={"Administration"},
363
     *     consumes={"application/json"},
364
     *     summary="Updates a single instance of Pay Grade.",
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="pay_grade",
405
     *         in="body",
406
     *         required=true,
407
     *         description="pay grade object that needs to be updated",
408
     *         @SWG\Property(ref="#/definitions/PayGrade")
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 PayGradeRequest $request
421
     *
422
     * @return \Dingo\Api\Http\Response
423
     *
424
     * @author Bertrand Kintanar <[email protected]>
425
     */
426 4
    public function update(PayGradeRequest $request)
427
    {
428 4
        return $this->updateModel($request, $this->pay_grade);
429
    }
430
}
431