<?php
namespace LaunchPad\Bundle\LaunchPadBundle\Admin\Api\Controller;
use LaunchPad\Bundle\LaunchPadBundle\Admin\Api\Request\Account\InitializeAccountRequest;
use LaunchPad\Bundle\LaunchPadBundle\Base\Entity\Account\Account;
use LaunchPad\Bundle\LaunchPadBundle\Base\Service\AccountService;
use LaunchPad\Bundle\LaunchPadBundle\Base\Service\Translation\TranslationService;
use LaunchPad\Bundle\LaunchPadBundle\Base\Service\UserService;
use Symfony\Component\Routing\Annotation\Route;
use OpenApi\Annotations as OA;
/**
* Class PaymentDeviceController
* @package BoBoFin\Admin\Api\Controller
* @Route("/account", name="admin_account_")
*/
class AccountController extends BaseAdminApiController
{
/** @var AccountService */
private $accountService;
public function __construct(
TranslationService $translationService,
AccountService $accountService
) {
parent::__construct($translationService);
$this->accountService = $accountService;
}
/**
* @Route("/list", name="list")
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\Common\Annotations\AnnotationException
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
*
* @OA\Post(
* path="/account/list",
* operationId="listAccounts",
* tags={"Account"},
* summary="Account",
* description="List all accounts",
* @OA\Response(
* response=200,
* description="Successful operation",
* @OA\JsonContent(ref="#/components/schemas/SuccessResponse")
* ),
* security={
* {"Bearer": {}}
* }
* )
*/
public function getAccountListAction()
{
$list = $this->paginatorService->getPaginated(
Account::class,
$this->data
);
return $this->success($list, null, ['account_data', 'basic_data']);
}
/**
* @Route("/details", name="details")
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\Common\Annotations\AnnotationException
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
*
* @OA\Post(
* path="/account/details",
* operationId="Accounts",
* tags={"Account"},
* summary="Account",
* description="Get Account Details ",
* @OA\Response(
* response=200,
* description="Successful operation",
* @OA\JsonContent(ref="#/components/schemas/SuccessResponse")
* ),
* security={
* {"Bearer": {}}
* }
* )
*/
public function getAccountDetailsAction()
{
$this->requirePostParams(['id']);
$result = $this->accountService->getAccountById($this->data['id']);
return $this->success($result, null, ['account_data', 'basic_data']);
}
/**
* @Route("/initialize", name="initialize")
* @param UserService $userService
* @param AccountService $accountService
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\Common\Annotations\AnnotationException
* @throws \LaunchPad\Bundle\LaunchPadBundle\Base\Exception\MissingApiParamsException
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
*/
public function initializeAction(UserService $userService, AccountService $accountService)
{
$request = $this->validateRequest(InitializeAccountRequest::class);
$user = $userService->getUserById($request->id);
if(!$user) return $this->failure('User not found');
$accountService->userCreated($user);
return $this->success();
}
}