Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
25 / 25
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
GetAccountTransactionsAction
100.00% covered (success)
100.00%
25 / 25
100.00% covered (success)
100.00%
2 / 2
8
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __invoke
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
1 / 1
7
1<?php
2
3declare(strict_types=1);
4
5namespace App\Action\Account;
6
7use App\Domain\Transaction\Service\TransactionFinder;
8use App\Renderer\JsonRenderer;
9use Psr\Http\Message\ResponseInterface;
10use Psr\Http\Message\ServerRequestInterface;
11
12final readonly class GetAccountTransactionsAction
13{
14    public function __construct(
15        private TransactionFinder $transactionFinder,
16        private JsonRenderer $renderer,
17    ) {}
18
19    /**
20     * @param ServerRequestInterface $request
21     * @param ResponseInterface $response
22     * @param array<string, string> $args
23     * @return ResponseInterface
24     */
25    public function __invoke(
26        ServerRequestInterface $request,
27        ResponseInterface $response,
28        array $args,
29    ): ResponseInterface {
30        $accountId = (int)$args['id'];
31        $params = $request->getQueryParams();
32
33        $page = max(1, (int)($params['page'] ?? 1));
34        $limit = max(1, min(100, (int)($params['limit'] ?? 10)));
35        $type = isset($params['type']) && $params['type'] !== '' ? $params['type'] : null;
36        $startDate = isset($params['startDate']) && $params['startDate'] !== '' ? $params['startDate'] : null;
37        $endDate = isset($params['endDate']) && $params['endDate'] !== '' ? $params['endDate'] : null;
38
39        $result = $this->transactionFinder->findByAccountId(
40            accountId: $accountId,
41            page: $page,
42            limit: $limit,
43            type: $type,
44            startDate: $startDate,
45            endDate: $endDate,
46        );
47
48        return $this->renderer->json($response, [
49            'success' => true,
50            'data' => [
51                'transactions' => $result['data'],
52                'total' => $result['total'],
53                'page' => $result['page'],
54                'limit' => $result['limit'],
55            ],
56        ]);
57    }
58}