Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| GetAccountsForSuperAdminAction | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Action\SuperAdmin; |
| 6 | |
| 7 | use App\Domain\Auth\Data\UserAuthData; |
| 8 | use App\Domain\Exception\ForbiddenException; |
| 9 | use App\Domain\SuperAdmin\Service\SuperAdminService; |
| 10 | use App\Renderer\JsonRenderer; |
| 11 | use Psr\Http\Message\ResponseInterface; |
| 12 | use Psr\Http\Message\ServerRequestInterface; |
| 13 | |
| 14 | /** |
| 15 | * Get all accounts for super admin dropdown selection. |
| 16 | */ |
| 17 | final readonly class GetAccountsForSuperAdminAction |
| 18 | { |
| 19 | public function __construct( |
| 20 | private JsonRenderer $renderer, |
| 21 | private SuperAdminService $service, |
| 22 | ) {} |
| 23 | |
| 24 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
| 25 | { |
| 26 | // Verify super_admin role |
| 27 | $user = $request->getAttribute('user'); |
| 28 | if (!$user instanceof UserAuthData || $user->role !== 'super_admin') { |
| 29 | throw new ForbiddenException('Super admin access required'); |
| 30 | } |
| 31 | |
| 32 | $accounts = $this->service->getAccountsForDropdown(); |
| 33 | $counts = $this->service->getTestDataCounts(); |
| 34 | |
| 35 | return $this->renderer->json($response, [ |
| 36 | 'success' => true, |
| 37 | 'data' => [ |
| 38 | 'accounts' => $accounts, |
| 39 | 'testDataCounts' => $counts, |
| 40 | ], |
| 41 | ]); |
| 42 | } |
| 43 | } |