Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| AcceptLoanAction | |
0.00% |
0 / 9 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __invoke | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Action\Loan; |
| 6 | |
| 7 | use App\Domain\Loan\Service\LoanService; |
| 8 | use App\Renderer\JsonRenderer; |
| 9 | use App\Support\Row; |
| 10 | use Psr\Http\Message\ResponseInterface; |
| 11 | use Psr\Http\Message\ServerRequestInterface; |
| 12 | |
| 13 | /** |
| 14 | * POST /api/loans/{id}/accept |
| 15 | * |
| 16 | * FSC-94: investor accepts the (possibly admin-modified) terms of a |
| 17 | * loan in `pending_acceptance`. Transitions to `approved` and enqueues |
| 18 | * disbursement. |
| 19 | */ |
| 20 | final readonly class AcceptLoanAction |
| 21 | { |
| 22 | public function __construct( |
| 23 | private LoanService $loanService, |
| 24 | private JsonRenderer $renderer, |
| 25 | ) {} |
| 26 | |
| 27 | /** |
| 28 | * @param array<string, string> $args |
| 29 | * @param ServerRequestInterface $request |
| 30 | * @param ResponseInterface $response |
| 31 | */ |
| 32 | public function __invoke( |
| 33 | ServerRequestInterface $request, |
| 34 | ResponseInterface $response, |
| 35 | array $args, |
| 36 | ): ResponseInterface { |
| 37 | $investorId = Row::int($request->getAttributes(), 'investorId'); |
| 38 | $loanId = Row::int($args, 'id'); |
| 39 | |
| 40 | $loan = $this->loanService->acceptLoan($loanId, $investorId); |
| 41 | |
| 42 | return $this->renderer->json($response, [ |
| 43 | 'success' => true, |
| 44 | 'message' => 'Loan accepted; disbursement is queued for admin review', |
| 45 | 'data' => ['loan' => $loan->toArray()], |
| 46 | ]); |
| 47 | } |
| 48 | } |