Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
AngelTypeController | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
index | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
ofUser | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Engelsystem\Controllers\Api; |
6 | |
7 | use Engelsystem\Controllers\Api\Resources\AngelTypeResource; |
8 | use Engelsystem\Controllers\Api\Resources\UserAngelTypeResource; |
9 | use Engelsystem\Http\Request; |
10 | use Engelsystem\Http\Response; |
11 | use Engelsystem\Models\AngelType; |
12 | |
13 | class AngelTypeController extends ApiController |
14 | { |
15 | use UsesAuth; |
16 | |
17 | public function index(): Response |
18 | { |
19 | $models = AngelType::query() |
20 | ->orderBy('name') |
21 | ->get(); |
22 | |
23 | $data = ['data' => AngelTypeResource::collection($models)]; |
24 | return $this->response |
25 | ->withContent(json_encode($data)); |
26 | } |
27 | |
28 | public function ofUser(Request $request): Response |
29 | { |
30 | $id = $request->getAttribute('user_id'); |
31 | $user = $this->getUser($id); |
32 | |
33 | $data = ['data' => UserAngelTypeResource::collection($user->userAngelTypes)]; |
34 | |
35 | return $this->response |
36 | ->withContent(json_encode($data)); |
37 | } |
38 | } |