src/Controller/Api/AccountController.php line 24

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Api;
  4. use App\Entity\Account;
  5. use App\Entity\Type\AccountType;
  6. use App\Entity\Type\Currency;
  7. use App\Repository\ClientRepository;
  8. use App\Service\TokenService;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\HttpFoundation\Request;
  11. class AccountController extends AbstractApiController
  12. {
  13.     public function __construct(
  14.         TokenService $tokenService,
  15.         ClientRepository $clientRepository
  16.     ) {
  17.         parent::__construct($tokenService$clientRepository);
  18.     }
  19.     public function getAccountsListAction(Request $request): JsonResponse
  20.     {
  21.         $client $this->getClient($request);
  22.         $userAccounts $client->getAccounts();
  23.         $responseAccounts = [];
  24.         $userAccounts->map(function (Account $account) use (&$responseAccounts)  {
  25.             $responseAccounts[] = [
  26.                 'number' => $account->getAccountSpecialNumber(),
  27.                 'type' => AccountType::VALUES[$account->getAccountType()],
  28.                 'currency' => Currency::VALUES[$account->getCurrency()],
  29.                 'balance' => $account->getBalance(),
  30.                 'minBalance' => $account->getMinBalance(),
  31.                 'isActive' => true
  32.             ];
  33.         });
  34.         return new JsonResponse($responseAccounts);
  35.     }
  36. }