Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| GetAdminTransactionsAction | |
0.00% |
0 / 21 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __invoke | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Action\Admin; |
| 6 | |
| 7 | use App\Domain\Admin\Service\AdminService; |
| 8 | use App\Renderer\JsonRenderer; |
| 9 | use Psr\Http\Message\ResponseInterface; |
| 10 | use Psr\Http\Message\ServerRequestInterface; |
| 11 | |
| 12 | /** |
| 13 | * Get all platform transactions for admin view. |
| 14 | * |
| 15 | * GET /api/admin/transactions |
| 16 | */ |
| 17 | final readonly class GetAdminTransactionsAction |
| 18 | { |
| 19 | public function __construct( |
| 20 | private AdminService $service, |
| 21 | private JsonRenderer $renderer, |
| 22 | ) {} |
| 23 | |
| 24 | public function __invoke( |
| 25 | ServerRequestInterface $request, |
| 26 | ResponseInterface $response, |
| 27 | ): ResponseInterface { |
| 28 | $params = $request->getQueryParams(); |
| 29 | |
| 30 | $page = max(1, (int)($params['page'] ?? 1)); |
| 31 | $limit = min(100, max(1, (int)($params['limit'] ?? 25))); |
| 32 | $type = !empty($params['type']) ? (string)$params['type'] : null; |
| 33 | $search = !empty($params['search']) ? (string)$params['search'] : null; |
| 34 | $startDate = !empty($params['startDate']) ? (string)$params['startDate'] : null; |
| 35 | $endDate = !empty($params['endDate']) ? (string)$params['endDate'] : null; |
| 36 | |
| 37 | $result = $this->service->getAllTransactions($page, $limit, $type, $search, $startDate, $endDate); |
| 38 | |
| 39 | return $this->renderer->json($response, [ |
| 40 | 'success' => true, |
| 41 | 'data' => [ |
| 42 | 'transactions' => $result['data'], |
| 43 | 'pagination' => [ |
| 44 | 'total' => $result['total'], |
| 45 | 'page' => $result['page'], |
| 46 | 'limit' => $result['limit'], |
| 47 | 'totalPages' => (int)ceil($result['total'] / $result['limit']), |
| 48 | ], |
| 49 | ], |
| 50 | ]); |
| 51 | } |
| 52 | } |