Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 21 |
TestController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 7 |
72 | |
0.00% |
0 / 21 |
__construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
index | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
indexFiltered | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
store | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
show | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
update | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 6 |
|||
destroy | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\ApiGateway\Controllers; |
4 | |
5 | use Qmp\Laravel\ApiGateway\Models\Test; |
6 | use Illuminate\Http\Request; |
7 | |
8 | class TestController extends AbstractApiController |
9 | { |
10 | public function __construct() |
11 | { |
12 | parent::__construct(); |
13 | } |
14 | |
15 | /** |
16 | * @api {get} /latest/test 1. Get Test entries |
17 | * @apiVersion 1.0.0 |
18 | * @apiName GetTest |
19 | * @apiGroup Test |
20 | * @apiDescription Get all test entries paginate. |
21 | * |
22 | * @apiUse AuthHeader |
23 | * |
24 | * @apiUse SuccessGet |
25 | * |
26 | * @apiSuccess (Response-Data) {Integer} id id of test entry. |
27 | * @apiSuccess (Response-Data) {String} test test value 1. |
28 | * @apiSuccess (Response-Data) {String} value test value 2. |
29 | * @apiSuccess (Response-Data) {String} created_at Created at value. |
30 | * @apiSuccess (Response-Data) {String} updated_at Last update. |
31 | * |
32 | * @apiSuccessExample Response-Data (example): |
33 | * { |
34 | * "id": 30, |
35 | * "test": "sdkrtyurtezarzerksdjhg", |
36 | * "value": "sdfqazerazerq", |
37 | * "created_at": "2018-04-05 00:00:00", |
38 | * "updated_at": "2018-04-05 00:00:00" |
39 | * } |
40 | * |
41 | * @apiUse AuthError |
42 | * |
43 | * |
44 | * @return \Illuminate\Http\Response |
45 | */ |
46 | public function index() |
47 | { |
48 | |
49 | |
50 | $tests = Test::selectPaginate(); |
51 | |
52 | return $this->response($tests); |
53 | } |
54 | |
55 | /** |
56 | * @api {post} /latest/test/filter 2. Get Test filtered entries |
57 | * @apiVersion 1.0.0 |
58 | * @apiName GetFilteredTest |
59 | * @apiGroup Test |
60 | * @apiDescription Get test entries paginate filtered by json post options. |
61 | * |
62 | * @apiUse AuthHeader |
63 | * |
64 | * @apiUse SuccessGet |
65 | * |
66 | * @apiUse FilterGet |
67 | * |
68 | * @apiSuccess (Response-Data) {Integer} id id of test entry. |
69 | * @apiSuccess (Response-Data) {String} test test value 1. |
70 | * @apiSuccess (Response-Data) {String} value test value 2. |
71 | * @apiSuccess (Response-Data) {String} created_at Created at value. |
72 | * @apiSuccess (Response-Data) {String} updated_at Last update. |
73 | * |
74 | * @apiSuccessExample Response-Data (example): |
75 | * { |
76 | * "id": 30, |
77 | * "test": "sdkrtyurtezarzerksdjhg", |
78 | * "value": "sdfqazerazerq", |
79 | * "created_at": "2018-04-05 00:00:00", |
80 | * "updated_at": "2018-04-05 00:00:00" |
81 | * } |
82 | * |
83 | * @apiUse AuthError |
84 | * |
85 | * |
86 | * @param Request $request |
87 | * @return \Illuminate\Http\Response |
88 | */ |
89 | public function indexFiltered(Request $request) |
90 | { |
91 | $filters = $request->filter_request; |
92 | $tests = Test::selectPaginate($filters); |
93 | |
94 | return $this->response($tests); |
95 | } |
96 | |
97 | /** |
98 | * @api {post} /latest/test 4. Store new entry |
99 | * @apiVersion 1.0.0 |
100 | * @apiName CreateTest |
101 | * @apiGroup Test |
102 | * @apiDescription Store a newly created resource in storage. |
103 | * |
104 | * @apiUse AuthHeader |
105 | * |
106 | * @apiParam (POST) {String} test Test value. |
107 | * @apiParam (POST) {String} value Values string. |
108 | * |
109 | * |
110 | * @apiSuccessExample Response-Data (example): |
111 | * HTTP/1.1 201 Created |
112 | * [] |
113 | * |
114 | * @apiUse AuthError |
115 | * |
116 | * |
117 | * @param \Illuminate\Http\Request $request |
118 | * @return \Illuminate\Http\Response |
119 | */ |
120 | public function store(Request $request) |
121 | { |
122 | $validatedData = $request->validate([ |
123 | 'test' => 'required|max:255', |
124 | 'value' => 'required|max:255', |
125 | ]); |
126 | |
127 | $test = Test::create($validatedData); |
128 | $test->save(); |
129 | |
130 | return $this->response([], 201); |
131 | } |
132 | |
133 | /** |
134 | * @api {get} /latest/test/{id} 3. Get Test entry |
135 | * @apiVersion 1.0.0 |
136 | * @apiName GetOneTest |
137 | * @apiGroup Test |
138 | * @apiDescription Display the specified resource. |
139 | * |
140 | * @apiUse AuthHeader |
141 | * |
142 | * @apiParam (URL) {String} id id of expected entry. |
143 | * |
144 | * @apiSuccess (Response) {Integer} id id of test entry. |
145 | * @apiSuccess (Response) {String} test test value 1. |
146 | * @apiSuccess (Response) {String} value test value 2. |
147 | * @apiSuccess (Response) {String} created_at Created at value. |
148 | * @apiSuccess (Response) {String} updated_at Last update. |
149 | * |
150 | * @apiSuccessExample Response (example): |
151 | * HTTP/1.1 200 OK |
152 | * { |
153 | * "id": 30, |
154 | * "test": "sdkrtyurtezarzerksdjhg", |
155 | * "value": "sdfqazerazerq", |
156 | * "created_at": "2018-04-05 00:00:00", |
157 | * "updated_at": "2018-04-05 00:00:00" |
158 | * } |
159 | * |
160 | * @apiUse AuthError |
161 | * |
162 | * @param \Qmp\Laravel\ApiGateway\Models\Test $test |
163 | * @return \Illuminate\Http\Response |
164 | */ |
165 | public function show(Test $test) |
166 | { |
167 | return $this->response($test); |
168 | } |
169 | |
170 | /** |
171 | * @api {put} /latest/test/{id} 5. Update entry |
172 | * @apiVersion 1.0.0 |
173 | * @apiName UpdateTest |
174 | * @apiGroup Test |
175 | * @apiDescription Update the specified resource in storage. |
176 | * |
177 | * @apiUse AuthHeader |
178 | * |
179 | * @apiParam (URL) {String} id id of expected entry. |
180 | * |
181 | * @apiParam (PUT) {String} [test] Test value to update. |
182 | * @apiParam (PUT) {String} [value] Values string to update. |
183 | * |
184 | * |
185 | * @apiSuccessExample Response-Data (example): |
186 | * HTTP/1.1 204 No Content |
187 | * [] |
188 | * |
189 | * @apiUse AuthError |
190 | * |
191 | * |
192 | * @param \Illuminate\Http\Request $request |
193 | * @param \Qmp\Laravel\ApiGateway\Models\Test $test |
194 | * @return \Illuminate\Http\Response |
195 | */ |
196 | public function update(Request $request, Test $test) |
197 | { |
198 | $validatedData = $request->validate([ |
199 | 'test' => 'max:255', |
200 | 'value' => 'max:255', |
201 | ]); |
202 | |
203 | foreach ($validatedData as $key => $value) { |
204 | $test->$key = $value; |
205 | } |
206 | |
207 | $test->save(); |
208 | |
209 | return $this->response([], 204); |
210 | } |
211 | |
212 | /** |
213 | * @api {delete} /latest/test/{id} 6. Delete entry |
214 | * @apiVersion 1.0.0 |
215 | * @apiName DeleteTest |
216 | * @apiGroup Test |
217 | * @apiDescription Remove the specified resource from storage. |
218 | * |
219 | * @apiUse AuthHeader |
220 | * |
221 | * @apiParam (URL) {String} id id of expected entry. |
222 | * |
223 | * @apiSuccessExample Response-Data (example): |
224 | * HTTP/1.1 204 No Content |
225 | * [] |
226 | * |
227 | * @apiUse AuthError |
228 | * |
229 | * @param \Qmp\Laravel\ApiGateway\Models\Test $test |
230 | * @return \Illuminate\Http\Response |
231 | */ |
232 | public function destroy(Test $test) |
233 | { |
234 | Test::destroy($test->id); |
235 | |
236 | return $this->response([], 204); |
237 | } |
238 | } |