diff --git a/src/Action/Account/FetchUserSession.php b/src/Action/Account/FetchUserSession.php index 98c2aca..8a071ba 100644 --- a/src/Action/Account/FetchUserSession.php +++ b/src/Action/Account/FetchUserSession.php @@ -5,13 +5,13 @@ namespace App\Action\Account; use App\Action\ActionInterface; +use App\Contract\Repository\UserRepositoryInterface; use App\Dto\Aggregator\AggregateInterface; use App\Exception\SessionNotFoundException; -use App\Repository\UserRepository; final readonly class FetchUserSession implements ActionInterface { - public function __construct(private UserRepository $userRepository) {} + public function __construct(private UserRepositoryInterface $userRepository) {} public function __invoke(AggregateInterface $aggregator): void { diff --git a/src/Command/AccountDataCommand.php b/src/Command/AccountDataCommand.php index 63a2ecb..4995744 100644 --- a/src/Command/AccountDataCommand.php +++ b/src/Command/AccountDataCommand.php @@ -3,6 +3,8 @@ namespace App\Command; use App\ActionHandler\ActionHandlerInterface; +use App\Contract\Repository\MyFxBookRepositoryInterface; +use App\Contract\Repository\UserRepositoryInterface; use App\Dto\Aggregator\AggregateRoot; use App\Presentation\Output\TableInterface; use App\Strategy\StrategyManagerInterface; @@ -27,6 +29,8 @@ class AccountDataCommand extends Command * @param StrategyManagerInterface $tableStrategy */ public function __construct( + private readonly MyFxBookRepositoryInterface $myFxBookRepository, + private readonly UserRepositoryInterface $userRepository, private readonly StrategyManagerInterface $actionHandlerStrategy, private readonly StrategyManagerInterface $tableStrategy, ) { @@ -37,18 +41,25 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); - /** - * @todo fetch all accounts - * @todo ask which account should be used - * @todo create a single account flow - */ - /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); + $user = $this->userRepository->findLatest(); + + if (is_null($user)) { + $io->error('No user found!'); + } + + $accounts = $this->myFxBookRepository->accounts($user->getSession()); + $accountIds = array_map(static fn($a) => $a['id'], $accounts); + + $question = new ChoiceQuestion('Select account ID', $accountIds); + $account = $helper->ask($input, $output, $question); $dataType = $helper->ask($input, $output, new ChoiceQuestion('Please choose a data type: ', self::DATA_TYPES)); $aggregator = new AggregateRoot(); + $aggregator->setSession($user->getSession()); + $aggregator->setAccounts([$account]); /** @var ActionHandlerInterface $actionHandler */ $actionHandler = ($this->actionHandlerStrategy)($dataType); diff --git a/src/Command/LogoutCommand.php b/src/Command/LogoutCommand.php index fc9065b..6986668 100644 --- a/src/Command/LogoutCommand.php +++ b/src/Command/LogoutCommand.php @@ -4,8 +4,8 @@ namespace App\Command; +use App\Contract\Repository\UserRepositoryInterface; use App\Event\LogoutEvent; -use App\Repository\UserRepository; use Psr\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -21,7 +21,7 @@ class LogoutCommand extends Command { public function __construct( private readonly EventDispatcherInterface $eventDispatcher, - private readonly UserRepository $userRepository + private readonly UserRepositoryInterface $userRepository ) { parent::__construct(); } diff --git a/src/Contract/Repository/UserRepositoryInterface.php b/src/Contract/Repository/UserRepositoryInterface.php new file mode 100644 index 0000000..f1cee9d --- /dev/null +++ b/src/Contract/Repository/UserRepositoryInterface.php @@ -0,0 +1,18 @@ +