Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 38 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| GetAdminFundsAction | |
0.00% |
0 / 38 |
|
0.00% |
0 / 2 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __invoke | |
0.00% |
0 / 37 |
|
0.00% |
0 / 1 |
72 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Action\Admin; |
| 6 | |
| 7 | use App\Domain\Funds\Service\FundsFinder; |
| 8 | use App\Renderer\JsonRenderer; |
| 9 | use Psr\Http\Message\ResponseInterface; |
| 10 | use Psr\Http\Message\ServerRequestInterface; |
| 11 | |
| 12 | /** |
| 13 | * Get funds list for admin view. |
| 14 | * |
| 15 | * GET /api/admin/funds |
| 16 | */ |
| 17 | final readonly class GetAdminFundsAction |
| 18 | { |
| 19 | public function __construct( |
| 20 | private FundsFinder $finder, |
| 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 | |
| 33 | $search = !empty($params['search']) ? (string)$params['search'] : null; |
| 34 | $type = !empty($params['type']) ? (string)$params['type'] : null; |
| 35 | $status = !empty($params['status']) ? (string)$params['status'] : null; |
| 36 | |
| 37 | $published = null; |
| 38 | if (array_key_exists('published', $params) && $params['published'] !== '') { |
| 39 | $publishedValue = is_string($params['published']) |
| 40 | ? $params['published'] |
| 41 | : (string)$params['published']; |
| 42 | |
| 43 | $parsed = filter_var($publishedValue, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); |
| 44 | if ($parsed !== null) { |
| 45 | $published = (bool)$parsed; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | $result = $this->finder->findFunds( |
| 50 | page: $page, |
| 51 | limit: $limit, |
| 52 | search: $search, |
| 53 | type: $type, |
| 54 | status: $status, |
| 55 | published: $published, |
| 56 | ); |
| 57 | |
| 58 | return $this->renderer->json($response, [ |
| 59 | 'success' => true, |
| 60 | 'data' => [ |
| 61 | 'funds' => array_map( |
| 62 | static fn($fund): array => $fund->toArray(), |
| 63 | $result['data'], |
| 64 | ), |
| 65 | 'pagination' => [ |
| 66 | 'total' => $result['total'], |
| 67 | 'page' => $result['page'], |
| 68 | 'limit' => $result['limit'], |
| 69 | 'totalPages' => (int)ceil($result['total'] / $result['limit']), |
| 70 | ], |
| 71 | ], |
| 72 | ]); |
| 73 | } |
| 74 | } |
| 75 |