Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
PostInterestAction
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 2
6
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 / 9
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace App\Action\SuperAdmin;
6
7use App\Domain\SuperAdmin\Service\SuperAdminService;
8use App\Renderer\JsonRenderer;
9use App\Support\Row;
10use Psr\Http\Message\ResponseInterface;
11use Psr\Http\Message\ServerRequestInterface;
12
13/**
14 * POST /api/super-admin/post-interest
15 *
16 * Posts accumulated daily interest as transactions for a given month.
17 */
18final readonly class PostInterestAction
19{
20    public function __construct(
21        private SuperAdminService $superAdminService,
22        private JsonRenderer $renderer,
23    ) {}
24
25    public function __invoke(
26        ServerRequestInterface $request,
27        ResponseInterface $response,
28    ): ResponseInterface {
29        $data = (array)$request->getParsedBody();
30
31        $result = $this->superAdminService->postInterest(
32            Row::nullableString($data, 'month'),
33        );
34
35        return $this->renderer->json($response, [
36            'success' => true,
37            'message' => "Posted interest for {$result['accountsPosted']} account(s)",
38            'data' => $result,
39        ]);
40    }
41}