Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| GetLendingActivityAction | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __invoke | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Action\Admin; |
| 6 | |
| 7 | use App\Domain\Admin\Service\AdminService; |
| 8 | use App\Renderer\JsonRenderer; |
| 9 | use App\Support\Row; |
| 10 | use Psr\Http\Message\ResponseInterface; |
| 11 | use Psr\Http\Message\ServerRequestInterface; |
| 12 | |
| 13 | use function ceil; |
| 14 | |
| 15 | /** |
| 16 | * Get lending-side activity (disbursements + loan payments) for admin view. |
| 17 | * |
| 18 | * GET /api/admin/lending/activity |
| 19 | */ |
| 20 | final readonly class GetLendingActivityAction |
| 21 | { |
| 22 | public function __construct( |
| 23 | private AdminService $service, |
| 24 | private JsonRenderer $renderer, |
| 25 | ) {} |
| 26 | |
| 27 | public function __invoke( |
| 28 | ServerRequestInterface $request, |
| 29 | ResponseInterface $response, |
| 30 | ): ResponseInterface { |
| 31 | $params = $request->getQueryParams(); |
| 32 | |
| 33 | $page = max(1, Row::nullableInt($params, 'page') ?? 1); |
| 34 | $limit = min(100, max(1, Row::nullableInt($params, 'limit') ?? 25)); |
| 35 | |
| 36 | $result = $this->service->getLendingActivity($page, $limit); |
| 37 | |
| 38 | return $this->renderer->json($response, [ |
| 39 | 'success' => true, |
| 40 | 'data' => [ |
| 41 | 'activity' => $result['data'], |
| 42 | 'pagination' => [ |
| 43 | 'total' => $result['total'], |
| 44 | 'page' => $result['page'], |
| 45 | 'limit' => $result['limit'], |
| 46 | 'totalPages' => (int)ceil($result['total'] / $result['limit']), |
| 47 | ], |
| 48 | ], |
| 49 | ]); |
| 50 | } |
| 51 | } |