Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Controller;
- use App\Core\Controller\FrontendApiController;
- use App\Entity\User;
- use App\Model\ApplicationModel;
- use App\Model\Pagination\PaginatedApplicationModel;
- use App\Service\Api\AccountApplicationApiService;
- use App\Service\Api\ApplicationApiService;
- use Nelmio\ApiDocBundle\Annotation\Model;
- use OpenApi\Attributes as OA;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\Routing\Annotation\Route;
- use Symfony\Component\Routing\Requirement\Requirement;
- use Symfony\Component\Security\Http\Attribute\CurrentUser;
- use Symfony\Component\Security\Http\Attribute\IsGranted;
- #[Route(path: '/api/v1/vendor/applications', requirements: ['id' => Requirement::UUID_V7])]
- #[OA\Tag(name: 'Application', description: 'Приложения')]
- //#[IsGranted('ROLE_VENDOR')]
- class VendorApplicationController extends FrontendApiController
- {
- public function __construct(
- protected ApplicationApiService $applicationExternalApiService,
- protected AccountApplicationApiService $accountApplicationApiService,
- ) {
- }
- #[Route(path: '', methods: ['GET'])]
- #[OA\Get(
- description: 'Все приложения',
- summary: 'Все приложения',
- parameters: [
- new OA\Parameter(
- name: 'limit',
- description: 'Кол-во, выводимое на страницу',
- in: 'query',
- schema: new OA\Schema(type: 'integer')
- ),
- new OA\Parameter(
- name: 'offset',
- description: 'Смещение указателя',
- in: 'query',
- schema: new OA\Schema(type: 'integer')
- ),
- ],
- responses: [
- new OA\Response(
- response: Response::HTTP_OK,
- description: 'Возвращает список всех приложений',
- content: new OA\JsonContent(
- type: 'array', items: new OA\Items(
- ref: new Model(
- type: PaginatedApplicationModel::class,
- // groups: ApplicationModel::CONTEXT_LIST
- )
- )
- ),
- ),
- ]
- )]
- public function index(#[CurrentUser] User $currentUser, Request $request): Response
- {
- $query = $request->query;
- return $this->response(
- $this->applicationExternalApiService->getAll(
- $currentUser,
- $query->get('limit'),
- $query->get('offset'),
- null,
- '',
- ApplicationModel::CONTEXT_LIST
- ),
- ApplicationModel::CONTEXT_LIST
- );
- }
- #[Route(
- path: '/{id}',
- requirements: ['id' => Requirement::UUID_V7],
- methods: ['GET']
- )]
- #[OA\Get(
- description: 'Возвращает приложение по его идентификатору',
- summary: 'Приложение',
- responses: [
- new OA\Response(
- response: Response::HTTP_OK,
- description: 'Возвращает приложение',
- content: new OA\JsonContent(
- ref: new Model(
- type: ApplicationModel::class,
- // groups: ApplicationModel::CONTEXT_VIEW
- )
- )
- ),
- ]
- )]
- public function view(#[CurrentUser] User $currentUser, string $id): Response
- {
- return $this->response(
- $this->applicationExternalApiService->get(
- $currentUser,
- $id,
- null,
- ApplicationModel::CONTEXT_VIEW
- ),
- ApplicationModel::CONTEXT_VIEW
- );
- }
- #[Route(
- path: '/{id}/installed',
- requirements: ['id' => Requirement::UUID_V7],
- methods: ['GET']
- )]
- #[OA\Get(
- description: 'Возвращает список установленных приложений',
- summary: 'Возвращает список установленных приложений',
- responses: [
- new OA\Response(
- response: Response::HTTP_OK,
- description: 'Возвращает список установленных приложений',
- content: new OA\JsonContent(
- ref: new Model(
- type: ApplicationModel::class,
- // groups: ApplicationModel::CONTEXT_VIEW
- )
- )
- ),
- ]
- )]
- public function installed(#[CurrentUser] User $currentUser, string $id): Response
- {
- dd($this->accountApplicationApiService->getSKey($id, $currentUser, []));
- return $this->response(
- $this->applicationExternalApiService->get(
- $currentUser,
- $id,
- null,
- ApplicationModel::CONTEXT_VIEW
- ),
- ApplicationModel::CONTEXT_VIEW
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment