spasmie

Untitled

Aug 3rd, 2023
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Controller;
  4.  
  5. use App\Core\Controller\FrontendApiController;
  6. use App\Entity\User;
  7. use App\Model\ApplicationModel;
  8. use App\Model\Pagination\PaginatedApplicationModel;
  9. use App\Service\Api\AccountApplicationApiService;
  10. use App\Service\Api\ApplicationApiService;
  11. use Nelmio\ApiDocBundle\Annotation\Model;
  12. use OpenApi\Attributes as OA;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Symfony\Component\Routing\Requirement\Requirement;
  17. use Symfony\Component\Security\Http\Attribute\CurrentUser;
  18. use Symfony\Component\Security\Http\Attribute\IsGranted;
  19.  
  20. #[Route(path: '/api/v1/vendor/applications', requirements: ['id' => Requirement::UUID_V7])]
  21. #[OA\Tag(name: 'Application', description: 'Приложения')]
  22. //#[IsGranted('ROLE_VENDOR')]
  23. class VendorApplicationController extends FrontendApiController
  24. {
  25. public function __construct(
  26. protected ApplicationApiService $applicationExternalApiService,
  27. protected AccountApplicationApiService $accountApplicationApiService,
  28. ) {
  29. }
  30.  
  31. #[Route(path: '', methods: ['GET'])]
  32. #[OA\Get(
  33. description: 'Все приложения',
  34. summary: 'Все приложения',
  35. parameters: [
  36. new OA\Parameter(
  37. name: 'limit',
  38. description: 'Кол-во, выводимое на страницу',
  39. in: 'query',
  40. schema: new OA\Schema(type: 'integer')
  41. ),
  42. new OA\Parameter(
  43. name: 'offset',
  44. description: 'Смещение указателя',
  45. in: 'query',
  46. schema: new OA\Schema(type: 'integer')
  47. ),
  48. ],
  49. responses: [
  50. new OA\Response(
  51. response: Response::HTTP_OK,
  52. description: 'Возвращает список всех приложений',
  53. content: new OA\JsonContent(
  54. type: 'array', items: new OA\Items(
  55. ref: new Model(
  56. type: PaginatedApplicationModel::class,
  57. // groups: ApplicationModel::CONTEXT_LIST
  58. )
  59. )
  60. ),
  61. ),
  62. ]
  63. )]
  64. public function index(#[CurrentUser] User $currentUser, Request $request): Response
  65. {
  66. $query = $request->query;
  67.  
  68. return $this->response(
  69. $this->applicationExternalApiService->getAll(
  70. $currentUser,
  71. $query->get('limit'),
  72. $query->get('offset'),
  73. null,
  74. '',
  75. ApplicationModel::CONTEXT_LIST
  76. ),
  77. ApplicationModel::CONTEXT_LIST
  78. );
  79. }
  80.  
  81. #[Route(
  82. path: '/{id}',
  83. requirements: ['id' => Requirement::UUID_V7],
  84. methods: ['GET']
  85. )]
  86. #[OA\Get(
  87. description: 'Возвращает приложение по его идентификатору',
  88. summary: 'Приложение',
  89. responses: [
  90. new OA\Response(
  91. response: Response::HTTP_OK,
  92. description: 'Возвращает приложение',
  93. content: new OA\JsonContent(
  94. ref: new Model(
  95. type: ApplicationModel::class,
  96. // groups: ApplicationModel::CONTEXT_VIEW
  97. )
  98. )
  99. ),
  100. ]
  101. )]
  102. public function view(#[CurrentUser] User $currentUser, string $id): Response
  103. {
  104. return $this->response(
  105. $this->applicationExternalApiService->get(
  106. $currentUser,
  107. $id,
  108. null,
  109. ApplicationModel::CONTEXT_VIEW
  110. ),
  111. ApplicationModel::CONTEXT_VIEW
  112. );
  113. }
  114.  
  115. #[Route(
  116. path: '/{id}/installed',
  117. requirements: ['id' => Requirement::UUID_V7],
  118. methods: ['GET']
  119. )]
  120. #[OA\Get(
  121. description: 'Возвращает список установленных приложений',
  122. summary: 'Возвращает список установленных приложений',
  123. responses: [
  124. new OA\Response(
  125. response: Response::HTTP_OK,
  126. description: 'Возвращает список установленных приложений',
  127. content: new OA\JsonContent(
  128. ref: new Model(
  129. type: ApplicationModel::class,
  130. // groups: ApplicationModel::CONTEXT_VIEW
  131. )
  132. )
  133. ),
  134. ]
  135. )]
  136. public function installed(#[CurrentUser] User $currentUser, string $id): Response
  137. {
  138.  
  139.  
  140. dd($this->accountApplicationApiService->getSKey($id, $currentUser, []));
  141. return $this->response(
  142.  
  143. $this->applicationExternalApiService->get(
  144. $currentUser,
  145. $id,
  146. null,
  147. ApplicationModel::CONTEXT_VIEW
  148. ),
  149. ApplicationModel::CONTEXT_VIEW
  150. );
  151. }
  152. }
  153.  
Advertisement
Add Comment
Please, Sign In to add comment