Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.91% |
10 / 11 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ListMyUploadsAction | |
90.91% |
10 / 11 |
|
50.00% |
1 / 2 |
3.01 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
2.00 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Action\Document\Submission; |
| 6 | |
| 7 | use App\Domain\Document\Submission\Service\InvestorDocumentService; |
| 8 | use App\Domain\Exception\ForbiddenException; |
| 9 | use App\Renderer\JsonRenderer; |
| 10 | use App\Support\Row; |
| 11 | use Psr\Http\Message\ResponseInterface; |
| 12 | use Psr\Http\Message\ServerRequestInterface; |
| 13 | |
| 14 | final readonly class ListMyUploadsAction |
| 15 | { |
| 16 | public function __construct( |
| 17 | private InvestorDocumentService $service, |
| 18 | private JsonRenderer $renderer, |
| 19 | ) {} |
| 20 | |
| 21 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
| 22 | { |
| 23 | $investorId = Row::nullableInt($request->getAttributes(), 'investorId'); |
| 24 | if ($investorId === null) { |
| 25 | throw new ForbiddenException('This endpoint requires an investor account.'); |
| 26 | } |
| 27 | |
| 28 | $documents = $this->service->listForInvestor($investorId); |
| 29 | |
| 30 | return $this->renderer->json($response, [ |
| 31 | 'success' => true, |
| 32 | 'data' => [ |
| 33 | 'documents' => array_map(static fn($doc) => $doc->toArray(), $documents), |
| 34 | ], |
| 35 | ]); |
| 36 | } |
| 37 | } |