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