Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
UsersController | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
user | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Engelsystem\Controllers\Api; |
6 | |
7 | use Engelsystem\Controllers\Api\Resources\UserDetailResource; |
8 | use Engelsystem\Controllers\Api\Resources\UserResource; |
9 | use Engelsystem\Http\Request; |
10 | use Engelsystem\Http\Response; |
11 | |
12 | class UsersController extends ApiController |
13 | { |
14 | use UsesAuth; |
15 | |
16 | public function user(Request $request): Response |
17 | { |
18 | $id = $request->getAttribute('user_id'); |
19 | $user = $this->getUser($id); |
20 | |
21 | $userData = $user->id == $this->auth->user()->id ? new UserDetailResource($user) : new UserResource($user); |
22 | $data = ['data' => $userData->toArray()]; |
23 | return $this->response |
24 | ->withContent(json_encode($data)); |
25 | } |
26 | } |