Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| MeController | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| me | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Identity\Infrastructure\Controllers; |
| 6 | |
| 7 | use App\Identity\Application\Query\GetCurrentUserHandler; |
| 8 | use App\Identity\Application\Query\GetCurrentUserQuery; |
| 9 | use App\Identity\Infrastructure\Http\ResolvesAuthenticatedUser; |
| 10 | use OpenApi\Attributes as OA; |
| 11 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
| 12 | use Symfony\Component\HttpFoundation\JsonResponse; |
| 13 | use Symfony\Component\Routing\Attribute\Route; |
| 14 | |
| 15 | #[OA\Tag(name: 'Users')] |
| 16 | class MeController extends AbstractController |
| 17 | { |
| 18 | use ResolvesAuthenticatedUser; |
| 19 | |
| 20 | public function __construct( |
| 21 | private readonly GetCurrentUserHandler $handler, |
| 22 | ) { |
| 23 | } |
| 24 | |
| 25 | #[Route('/users/me', name: 'users_me', methods: ['GET'])] |
| 26 | public function me(): JsonResponse |
| 27 | { |
| 28 | $securityUser = $this->securityUser(); |
| 29 | |
| 30 | $view = $this->handler->handle(new GetCurrentUserQuery($securityUser->userId())); |
| 31 | |
| 32 | if ($view === null) { |
| 33 | return new JsonResponse(['error' => 'User not found.'], 404); |
| 34 | } |
| 35 | |
| 36 | return new JsonResponse($view->toArray(), 200); |
| 37 | } |
| 38 | } |