Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| GetFundsAction | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __invoke | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Action\Fund; |
| 6 | |
| 7 | use App\Domain\Funds\Service\InvestorFundsService; |
| 8 | use App\Renderer\JsonRenderer; |
| 9 | use Psr\Http\Message\ResponseInterface; |
| 10 | use Psr\Http\Message\ServerRequestInterface; |
| 11 | |
| 12 | final readonly class GetFundsAction |
| 13 | { |
| 14 | public function __construct( |
| 15 | private InvestorFundsService $service, |
| 16 | private JsonRenderer $renderer, |
| 17 | ) {} |
| 18 | |
| 19 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
| 20 | { |
| 21 | $params = $request->getQueryParams(); |
| 22 | |
| 23 | $page = max(1, (int)($params['page'] ?? 1)); |
| 24 | $limit = min(100, max(1, (int)($params['limit'] ?? 12))); |
| 25 | $search = !empty($params['search']) ? (string)$params['search'] : null; |
| 26 | $type = !empty($params['type']) ? (string)$params['type'] : null; |
| 27 | |
| 28 | $result = $this->service->getPublishedFunds( |
| 29 | page: $page, |
| 30 | limit: $limit, |
| 31 | search: $search, |
| 32 | type: $type, |
| 33 | userId: (int)$request->getAttribute('userId'), |
| 34 | ); |
| 35 | |
| 36 | return $this->renderer->json($response, [ |
| 37 | 'success' => true, |
| 38 | 'data' => $result, |
| 39 | ]); |
| 40 | } |
| 41 | } |
| 42 |