| Total Complexity | 9 |
| Total Lines | 117 |
| Duplicated Lines | 0 % |
| Coverage | 85.71% |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | class JobApiController extends Controller |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | 8 | * Class constructor |
|
| 19 | */ |
||
| 20 | public function __construct() |
||
| 21 | 8 | { |
|
| 22 | 8 | // This applies the appropriate policy to each resource route. |
|
| 23 | $this->authorizeResource(JobPoster::class, 'job'); |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Convert a job poster to the array expected by API requests, |
||
| 28 | * with all criteria, |
||
| 29 | * and with translation arrays in both languages. |
||
| 30 | * |
||
| 31 | * @param \App\Models\JobPoster $job Incoming Job Poster object. |
||
| 32 | 4 | * @return mixed[] |
|
| 33 | */ |
||
| 34 | 4 | private function jobToArray(JobPoster $job) |
|
| 45 | } |
||
| 46 | /** |
||
| 47 | * Display a listing of the resource. |
||
| 48 | * |
||
| 49 | * @return \Illuminate\Http\Response |
||
|
1 ignored issue
–
show
|
|||
| 50 | */ |
||
| 51 | public function index() |
||
| 52 | { |
||
| 53 | // TODO: complete. |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Store a newly created resource in storage. |
||
| 58 | * |
||
| 59 | * @param \App\Http\Requests\StoreJobPoster $request Incoming request. |
||
| 60 | 1 | * @return \Illuminate\Http\Response |
|
| 61 | */ |
||
| 62 | 1 | public function store(StoreJobPoster $request) |
|
| 63 | 1 | { |
|
| 64 | 1 | $data = $request->validated(); |
|
| 65 | 1 | $job = new JobPoster(); |
|
| 66 | 1 | $job->manager_id = $request->user()->manager->id; |
|
| 67 | 1 | $job->fill($data); |
|
| 68 | $job->save(); |
||
| 69 | return response()->json($this->jobToArray($job)); |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Display the specified resource. |
||
| 74 | * |
||
| 75 | * @param \App\Models\JobPoster $job Incoming Job Poster. |
||
| 76 | 1 | * @return \Illuminate\Http\Response |
|
| 77 | */ |
||
| 78 | 1 | public function show(JobPoster $job) |
|
| 79 | { |
||
| 80 | return response()->json($this->jobToArray($job)); |
||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Update the specified resource in storage. |
||
| 85 | * |
||
| 86 | * @param \App\Http\Requests\UpdateJobPoster $request Validates input. |
||
| 87 | * @param \App\Models\JobPoster $job Incoming Job Poster. |
||
| 88 | 2 | * @return \Illuminate\Http\Response |
|
| 89 | */ |
||
| 90 | 2 | public function update(UpdateJobPoster $request, JobPoster $job) |
|
| 91 | { |
||
| 92 | $data = $request->validated(); |
||
| 93 | 2 | // Only values both in the JobPoster->fillable array, |
|
| 94 | 2 | // and returned by UpdateJobPoster->validatedData(), will be set. |
|
| 95 | 2 | $job->fill($data); |
|
| 96 | $job->save(); |
||
| 97 | return response()->json($this->jobToArray($job->fresh())); |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Remove the specified resource from storage. |
||
| 102 | * |
||
| 103 | * @param integer $id Job Poster ID. |
||
| 104 | * @return \Illuminate\Http\Response |
||
|
1 ignored issue
–
show
|
|||
| 105 | */ |
||
| 106 | public function destroy($id) |
||
|
1 ignored issue
–
show
|
|||
| 107 | { |
||
| 108 | // TODO: complete. |
||
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Submit the Job Poster for review. |
||
| 113 | * |
||
| 114 | * @param \App\Models\JobPoster $job Job Poster object. |
||
|
1 ignored issue
–
show
|
|||
| 115 | * @return \Illuminate\Http\Response |
||
| 116 | */ |
||
| 117 | public function submitForReview(JobPoster $job) |
||
| 132 | } |
||
| 133 | } |
||
| 134 |