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