|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\RatingGuideAnswer; |
|
6
|
|
|
use App\Models\RatingGuideQuestion; |
|
7
|
|
|
use App\Models\Skill; |
|
8
|
|
|
|
|
9
|
|
|
use Illuminate\Http\Request; |
|
10
|
|
|
use Illuminate\Http\Response; |
|
11
|
|
|
|
|
12
|
|
|
class RatingGuideAnswerController extends Controller |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Store a newly created resource in storage. |
|
16
|
|
|
* |
|
17
|
|
|
* @param \Illuminate\Http\Request $request Incoming request. |
|
18
|
|
|
* @throws \InvalidArgumentException For missing $expected_answer. |
|
19
|
|
|
* @return mixed |
|
20
|
|
|
*/ |
|
21
|
|
|
public function store(Request $request) |
|
22
|
|
|
{ |
|
23
|
|
|
dump($request->json()); |
|
|
|
|
|
|
24
|
|
|
try { |
|
25
|
|
|
$rating_guide_question_id = (int)$request->json('rating_guide_question_id'); |
|
26
|
|
|
$skill_id = (int)$request->json('skill_id'); |
|
27
|
|
|
$expected_answer = $request->json('expected_answer'); |
|
28
|
|
|
|
|
29
|
|
|
RatingGuideQuestion::findOrFail($rating_guide_question_id); |
|
30
|
|
|
Skill::findOrFail($skill_id); |
|
31
|
|
|
|
|
32
|
|
|
if (empty($expected_answer)) { |
|
33
|
|
|
throw new \InvalidArgumentException('Expected answer is required.'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$ratingGuideAnswer = new RatingGuideAnswer([ |
|
37
|
|
|
'rating_guide_question_id' => $rating_guide_question_id, |
|
38
|
|
|
'skill_id' => $skill_id, |
|
39
|
|
|
'expected_answer' => $expected_answer, |
|
40
|
|
|
]); |
|
41
|
|
|
$ratingGuideAnswer->save(); |
|
42
|
|
|
$ratingGuideAnswer->refresh(); |
|
43
|
|
|
} catch (\Exception $e) { |
|
44
|
|
|
return response()->json([ |
|
45
|
|
|
'error' => $e->getMessage() |
|
46
|
|
|
], 400); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return [ |
|
50
|
|
|
'success' => "Successfully created rating guide answer $ratingGuideAnswer->id" |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Display the specified resource. |
|
56
|
|
|
* |
|
57
|
|
|
* @param \App\Models\RatingGuideAnswer $ratingGuideAnswer Incoming object. |
|
58
|
|
|
* @return mixed |
|
59
|
|
|
*/ |
|
60
|
|
|
public function show(RatingGuideAnswer $ratingGuideAnswer) |
|
61
|
|
|
{ |
|
62
|
|
|
$ratingGuideAnswer->load([ |
|
63
|
|
|
'skill', |
|
64
|
|
|
'rating_guide_question' |
|
65
|
|
|
]); |
|
66
|
|
|
return $ratingGuideAnswer->toArray(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Update the specified resource in storage. |
|
71
|
|
|
* |
|
72
|
|
|
* @param \Illuminate\Http\Request $request Incoming request. |
|
73
|
|
|
* @param \App\Models\RatingGuideAnswer $ratingGuideAnswer Incoming object. |
|
74
|
|
|
* @throws \InvalidArgumentException For empty $expected_answer. |
|
75
|
|
|
* @return mixed |
|
76
|
|
|
*/ |
|
77
|
|
|
public function update(Request $request, RatingGuideAnswer $ratingGuideAnswer) |
|
78
|
|
|
{ |
|
79
|
|
|
try { |
|
80
|
|
|
$rating_guide_question_id = (int)$request->json('rating_guide_question_id'); |
|
81
|
|
|
$skill_id = (int)$request->json('skill_id'); |
|
82
|
|
|
$expected_answer = $request->json('expected_answer'); |
|
83
|
|
|
|
|
84
|
|
|
RatingGuideQuestion::findOrFail($rating_guide_question_id); |
|
85
|
|
|
Skill::findOrFail($skill_id); |
|
86
|
|
|
|
|
87
|
|
|
if (empty($expected_answer)) { |
|
88
|
|
|
throw new \InvalidArgumentException('Expected answer is required.'); |
|
89
|
|
|
} |
|
90
|
|
|
$ratingGuideAnswer->rating_guide_question_id = $rating_guide_question_id; |
|
91
|
|
|
$ratingGuideAnswer->skill_id = $skill_id; |
|
92
|
|
|
$ratingGuideAnswer->expected_answer = $expected_answer; |
|
93
|
|
|
$ratingGuideAnswer->save(); |
|
94
|
|
|
} catch (\Exception $e) { |
|
95
|
|
|
return response()->json([ |
|
96
|
|
|
'error' => $e->getMessage() |
|
97
|
|
|
], 400); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return [ |
|
101
|
|
|
'success' => "Successfully updated rating guide answer $ratingGuideAnswer->id" |
|
102
|
|
|
]; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Remove the specified resource from storage. |
|
107
|
|
|
* |
|
108
|
|
|
* @param \App\Models\RatingGuideAnswer $ratingGuideAnswer Incoming object. |
|
109
|
|
|
* @return mixed |
|
110
|
|
|
*/ |
|
111
|
|
|
public function destroy(RatingGuideAnswer $ratingGuideAnswer) |
|
112
|
|
|
{ |
|
113
|
|
|
$ratingGuideAnswer->delete(); |
|
114
|
|
|
|
|
115
|
|
|
return [ |
|
116
|
|
|
'success' => "Successfully deleted rating guide answer $ratingGuideAnswer->id" |
|
117
|
|
|
]; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.