Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
AngelTypeController
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 index
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 ofUser
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Controllers\Api;
6
7use Engelsystem\Controllers\Api\Resources\AngelTypeResource;
8use Engelsystem\Controllers\Api\Resources\UserAngelTypeResource;
9use Engelsystem\Http\Request;
10use Engelsystem\Http\Response;
11use Engelsystem\Models\AngelType;
12
13class 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}