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