Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| GetCronJobStatusesAction | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Action\Admin; |
| 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 /api/admin/cron-jobs |
| 16 | * |
| 17 | * Returns last-run status for the three scheduled console commands — |
| 18 | * the data behind the super-admin dashboard "Scheduled Jobs" tile |
| 19 | * (FSC-114). Admin and super_admin can both read; investors are |
| 20 | * forbidden. |
| 21 | */ |
| 22 | final readonly class GetCronJobStatusesAction |
| 23 | { |
| 24 | public function __construct( |
| 25 | private SuperAdminService $service, |
| 26 | private JsonRenderer $renderer, |
| 27 | ) {} |
| 28 | |
| 29 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
| 30 | { |
| 31 | $user = $request->getAttribute('user'); |
| 32 | if (!$user instanceof UserAuthData || !in_array($user->role, ['admin', 'super_admin'], true)) { |
| 33 | throw new ForbiddenException('Admin access required'); |
| 34 | } |
| 35 | |
| 36 | $jobs = $this->service->getCronJobStatuses(); |
| 37 | |
| 38 | return $this->renderer->json($response, [ |
| 39 | 'success' => true, |
| 40 | 'data' => ['jobs' => $jobs], |
| 41 | ]); |
| 42 | } |
| 43 | } |