. */ namespace SP\Modules\Web\Controllers\Items; use SP\Core\Application; use SP\Domain\Account\Ports\AccountService; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Http\Dtos\JsonMessage; use SP\Domain\Http\Services\JsonResponse; use SP\Modules\Web\Controllers\SimpleControllerBase; use SP\Mvc\Controller\SimpleControllerHelper; use stdClass; /** * Class AccountsUserController */ final class AccountsUserController extends SimpleControllerBase { private AccountService $accountService; public function __construct( Application $application, SimpleControllerHelper $simpleControllerHelper, AccountService $accountService ) { parent::__construct($application, $simpleControllerHelper); $this->checks(); $this->accountService = $accountService; } /** * Devolver las cuentas visibles por el usuario * * @param int|null $accountId * * @throws ConstraintException * @throws QueryException * @throws SPException */ public function accountsUserAction(?int $accountId = null): void { $outItems = []; foreach ($this->accountService->getForUser($accountId) as $account) { $obj = new stdClass(); $obj->id = $account->id; $obj->name = $account->clientName.' - '.$account->name; $outItems[] = $obj; } $jsonResponse = new JsonMessage(); $jsonResponse->setStatus(0); $jsonResponse->setData($outItems); JsonResponse::factory($this->router->response())->send($jsonResponse); } }