Total Complexity | 8 |
Total Lines | 89 |
Duplicated Lines | 0 % |
Coverage | 64.29% |
Changes | 0 |
1 | <?php |
||
13 | class JobApiController extends Controller |
||
14 | { |
||
15 | 6 | public function __construct() |
|
1 ignored issue
–
show
|
|||
16 | { |
||
17 | // This applies the appropriate policy to each resource route |
||
18 | 6 | $this->authorizeResource(JobPoster::class, 'job'); |
|
19 | 6 | } |
|
20 | |||
21 | /** |
||
22 | * Convert a job poster to the array expected by API requests, |
||
23 | * with all criteria, |
||
24 | * and with translation arrays in both languages. |
||
25 | * |
||
26 | * @param JobPoster $job |
||
1 ignored issue
–
show
|
|||
27 | * @return mixed[] |
||
28 | */ |
||
29 | 3 | private function jobToArray(JobPoster $job) |
|
30 | { |
||
31 | 3 | $criteria = Criteria::where('job_poster_id', $job->id)->get(); |
|
32 | 3 | $criteriaTranslated = []; |
|
33 | 3 | foreach ($criteria as $criterion) { |
|
34 | 3 | $criteriaTranslated[] = array_merge($criterion->toArray(), $criterion->getTranslationsArray()); |
|
35 | } |
||
36 | 3 | $jobArray = array_merge($job->toApiArray(), ['criteria' => $criteriaTranslated]); |
|
37 | 3 | return $jobArray; |
|
38 | } |
||
39 | /** |
||
40 | * Display a listing of the resource. |
||
41 | * |
||
42 | * @return \Illuminate\Http\Response |
||
1 ignored issue
–
show
|
|||
43 | */ |
||
44 | public function index() |
||
46 | //TODO: complete |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Store a newly created resource in storage. |
||
51 | * |
||
52 | * @param App\Http\Requests\StoreJobPoster $request |
||
2 ignored issues
–
show
|
|||
53 | * @return \Illuminate\Http\Response |
||
54 | */ |
||
55 | public function store(StoreJobPoster $request) |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Display the specified resource. |
||
67 | * |
||
68 | * @param JobPoster $job |
||
1 ignored issue
–
show
|
|||
69 | * @return \Illuminate\Http\Response |
||
70 | */ |
||
71 | 1 | public function show(JobPoster $job) |
|
72 | { |
||
73 | 1 | return $this->jobToArray($job); |
|
1 ignored issue
–
show
|
|||
74 | } |
||
75 | |||
76 | /** |
||
1 ignored issue
–
show
|
|||
77 | * Update the specified resource in storage. |
||
78 | * |
||
79 | * @param App\Http\Requests\UpdateJobPoster $request Validates input. |
||
2 ignored issues
–
show
|
|||
80 | * @param JobPoster $jobPoser |
||
2 ignored issues
–
show
|
|||
81 | * @return \Illuminate\Http\Response |
||
82 | */ |
||
83 | 2 | public function update(UpdateJobPoster $request, JobPoster $job) |
|
84 | { |
||
85 | 2 | $data = $request->validated(); |
|
86 | 2 | JobPosterValidator::validateUnpublished($job); |
|
87 | // Only values both in the JobPoster->fillable array, |
||
88 | // and returned by UpdateJobPoster->validatedData(), will be set |
||
89 | 2 | $job->fill($data); |
|
90 | 2 | $job->save(); |
|
91 | 2 | return $this->jobToArray($job); |
|
1 ignored issue
–
show
|
|||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Remove the specified resource from storage. |
||
96 | * |
||
97 | * @param int $id |
||
2 ignored issues
–
show
|
|||
98 | * @return \Illuminate\Http\Response |
||
1 ignored issue
–
show
|
|||
99 | */ |
||
100 | public function destroy($id) |
||
102 | // TODO: |
||
103 | } |
||
104 | } |
||
105 |