Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
GetAdminInvestorLoansAction
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 2
12
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 / 8
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3declare(strict_types=1);
4
5namespace App\Action\Admin;
6
7use App\Domain\Loan\Service\LoanService;
8use App\Renderer\JsonRenderer;
9use InvalidArgumentException;
10use Psr\Http\Message\ResponseInterface;
11use Psr\Http\Message\ServerRequestInterface;
12
13/**
14 * Get all loans for a specific investor (admin view).
15 *
16 * GET /api/admin/investors/{investorId}/loans
17 */
18final readonly class GetAdminInvestorLoansAction
19{
20    public function __construct(
21        private LoanService $loanService,
22        private JsonRenderer $renderer,
23    ) {}
24
25    /**
26     * @param array<string, string> $args
27     * @param ServerRequestInterface $request
28     * @param ResponseInterface $response
29     */
30    public function __invoke(
31        ServerRequestInterface $request,
32        ResponseInterface $response,
33        array $args,
34    ): ResponseInterface {
35        $investorId = (int)$args['investorId'];
36
37        if ($investorId <= 0) {
38            throw new InvalidArgumentException('Invalid investor ID');
39        }
40
41        $loans = $this->loanService->getInvestorLoans($investorId);
42
43        return $this->renderer->json($response, [
44            'success' => true,
45            'data' => ['loans' => array_map(static fn($l) => $l->toArray(), $loans)],
46        ]);
47    }
48}