<?php
declare(strict_types=1);
namespace App\Controller\Api;
use App\Entity\Account;
use App\Entity\Type\AccountType;
use App\Entity\Type\Currency;
use App\Repository\ClientRepository;
use App\Service\TokenService;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
class AccountController extends AbstractApiController
{
public function __construct(
TokenService $tokenService,
ClientRepository $clientRepository
) {
parent::__construct($tokenService, $clientRepository);
}
public function getAccountsListAction(Request $request): JsonResponse
{
$client = $this->getClient($request);
$userAccounts = $client->getAccounts();
$responseAccounts = [];
$userAccounts->map(function (Account $account) use (&$responseAccounts) {
$responseAccounts[] = [
'number' => $account->getAccountSpecialNumber(),
'type' => AccountType::VALUES[$account->getAccountType()],
'currency' => Currency::VALUES[$account->getCurrency()],
'balance' => $account->getBalance(),
'minBalance' => $account->getMinBalance(),
'isActive' => true
];
});
return new JsonResponse($responseAccounts);
}
}