@@ -36,27 +36,27 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | class ArticleController extends AbstractController { |
| 38 | 38 | |
| 39 | - private FormFactoryInterface $formFactory; |
|
| 40 | - private RouteProviderInterface $routeProvider; // swp.provider.route |
|
| 41 | - private ArticleRepositoryInterface $articleRepository; //swp.repository.article |
|
| 42 | - private ArticleProviderInterface $articleProvider; //swp.provider.article |
|
| 43 | - private EventDispatcherInterface $eventDispatcher; |
|
| 44 | - private EntityManagerInterface $entityManager; // swp.object_manager.article |
|
| 45 | - private ArticleServiceInterface $articleService; // swp.service.article |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @param FormFactoryInterface $formFactory |
|
| 49 | - * @param RouteProviderInterface $routeProvider |
|
| 50 | - * @param ArticleRepositoryInterface $articleRepository |
|
| 51 | - * @param ArticleProviderInterface $articleProvider |
|
| 52 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 53 | - * @param EntityManagerInterface $entityManager |
|
| 54 | - * @param ArticleServiceInterface $articleService |
|
| 55 | - */ |
|
| 56 | - public function __construct(FormFactoryInterface $formFactory, RouteProviderInterface $routeProvider, |
|
| 57 | - ArticleRepositoryInterface $articleRepository, ArticleProviderInterface $articleProvider, |
|
| 58 | - EventDispatcherInterface $eventDispatcher, EntityManagerInterface $entityManager, |
|
| 59 | - ArticleServiceInterface $articleService) { |
|
| 39 | + private FormFactoryInterface $formFactory; |
|
| 40 | + private RouteProviderInterface $routeProvider; // swp.provider.route |
|
| 41 | + private ArticleRepositoryInterface $articleRepository; //swp.repository.article |
|
| 42 | + private ArticleProviderInterface $articleProvider; //swp.provider.article |
|
| 43 | + private EventDispatcherInterface $eventDispatcher; |
|
| 44 | + private EntityManagerInterface $entityManager; // swp.object_manager.article |
|
| 45 | + private ArticleServiceInterface $articleService; // swp.service.article |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @param FormFactoryInterface $formFactory |
|
| 49 | + * @param RouteProviderInterface $routeProvider |
|
| 50 | + * @param ArticleRepositoryInterface $articleRepository |
|
| 51 | + * @param ArticleProviderInterface $articleProvider |
|
| 52 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 53 | + * @param EntityManagerInterface $entityManager |
|
| 54 | + * @param ArticleServiceInterface $articleService |
|
| 55 | + */ |
|
| 56 | + public function __construct(FormFactoryInterface $formFactory, RouteProviderInterface $routeProvider, |
|
| 57 | + ArticleRepositoryInterface $articleRepository, ArticleProviderInterface $articleProvider, |
|
| 58 | + EventDispatcherInterface $eventDispatcher, EntityManagerInterface $entityManager, |
|
| 59 | + ArticleServiceInterface $articleService) { |
|
| 60 | 60 | $this->formFactory = $formFactory; |
| 61 | 61 | $this->routeProvider = $routeProvider; |
| 62 | 62 | $this->articleRepository = $articleRepository; |
@@ -64,30 +64,30 @@ discard block |
||
| 64 | 64 | $this->eventDispatcher = $eventDispatcher; |
| 65 | 65 | $this->entityManager = $entityManager; |
| 66 | 66 | $this->articleService = $articleService; |
| 67 | - } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles") |
|
| 72 | - * |
|
| 73 | - * @throws \Exception |
|
| 74 | - */ |
|
| 75 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
| 70 | + /** |
|
| 71 | + * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles") |
|
| 72 | + * |
|
| 73 | + * @throws \Exception |
|
| 74 | + */ |
|
| 75 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
| 76 | 76 | $authors = ''; |
| 77 | 77 | if (null !== $request->query->get('author', null)) { |
| 78 | - $authors = explode(', ', $request->query->get('author')); |
|
| 78 | + $authors = explode(', ', $request->query->get('author')); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | if ($request->query->get('route', false) && $request->query->get('includeSubRoutes', false)) { |
| 82 | - $routeObject = $this->routeProvider->getOneById($request->query->get('route')); |
|
| 82 | + $routeObject = $this->routeProvider->getOneById($request->query->get('route')); |
|
| 83 | 83 | |
| 84 | - if (null !== $routeObject) { |
|
| 84 | + if (null !== $routeObject) { |
|
| 85 | 85 | $ids = [$routeObject->getId()]; |
| 86 | 86 | foreach ($routeObject->getChildren() as $child) { |
| 87 | - $ids[] = $child->getId(); |
|
| 87 | + $ids[] = $child->getId(); |
|
| 88 | 88 | } |
| 89 | 89 | $request->query->set('route', $ids); |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | $articles = $this->articleRepository |
@@ -102,25 +102,25 @@ discard block |
||
| 102 | 102 | ]), $request->query->all('sorting'), new PaginationData($request)); |
| 103 | 103 | |
| 104 | 104 | return new ResourcesListResponse($articles); |
| 105 | - } |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @Route("/api/{version}/content/articles/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles", requirements={"id"=".+"}) |
|
| 109 | - */ |
|
| 110 | - public function getAction($id): SingleResourceResponseInterface { |
|
| 107 | + /** |
|
| 108 | + * @Route("/api/{version}/content/articles/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles", requirements={"id"=".+"}) |
|
| 109 | + */ |
|
| 110 | + public function getAction($id): SingleResourceResponseInterface { |
|
| 111 | 111 | $article = $this->articleProvider->getOneById($id); |
| 112 | 112 | |
| 113 | 113 | if (null === $article) { |
| 114 | - throw new NotFoundHttpException('Article was not found'); |
|
| 114 | + throw new NotFoundHttpException('Article was not found'); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | return new SingleResourceResponse($article); |
| 118 | - } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * @Route("/api/{version}/content/article/search-code", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles_by_code", requirements={"code"=".+"}) |
|
| 122 | - */ |
|
| 123 | - public function getByCodeAction(Request $request): SingleResourceResponseInterface { |
|
| 120 | + /** |
|
| 121 | + * @Route("/api/{version}/content/article/search-code", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles_by_code", requirements={"code"=".+"}) |
|
| 122 | + */ |
|
| 123 | + public function getByCodeAction(Request $request): SingleResourceResponseInterface { |
|
| 124 | 124 | // Extract parameters from the request |
| 125 | 125 | $code = $request->query->get('code', ''); |
| 126 | 126 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | ->getOneOrNullResult(); |
| 132 | 132 | |
| 133 | 133 | if (null === $article) { |
| 134 | - throw new NotFoundHttpException('Article was not found'); |
|
| 134 | + throw new NotFoundHttpException('Article was not found'); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | $article->setStatus('new'); |
@@ -152,12 +152,12 @@ discard block |
||
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | return new SingleResourceResponse($article); |
| 155 | - } |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"}) |
|
| 159 | - */ |
|
| 160 | - public function updateAction(Request $request, $id): SingleResourceResponseInterface { |
|
| 157 | + /** |
|
| 158 | + * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"}) |
|
| 159 | + */ |
|
| 160 | + public function updateAction(Request $request, $id): SingleResourceResponseInterface { |
|
| 161 | 161 | $objectManager = $this->entityManager; |
| 162 | 162 | $article = $this->findOr404($id); |
| 163 | 163 | $originalArticleStatus = $article->getStatus(); |
@@ -166,32 +166,32 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | $form->handleRequest($request); |
| 168 | 168 | if ($form->isSubmitted() && $form->isValid()) { |
| 169 | - $this->articleService->reactOnStatusChange($originalArticleStatus, $article); |
|
| 170 | - $objectManager->flush(); |
|
| 171 | - $objectManager->refresh($article); |
|
| 169 | + $this->articleService->reactOnStatusChange($originalArticleStatus, $article); |
|
| 170 | + $objectManager->flush(); |
|
| 171 | + $objectManager->refresh($article); |
|
| 172 | 172 | |
| 173 | - return new SingleResourceResponse($article); |
|
| 173 | + return new SingleResourceResponse($article); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | return new SingleResourceResponse($form, new ResponseContext(500)); |
| 177 | - } |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"}) |
|
| 181 | - */ |
|
| 182 | - public function deleteAction($id): SingleResourceResponseInterface { |
|
| 179 | + /** |
|
| 180 | + * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"}) |
|
| 181 | + */ |
|
| 182 | + public function deleteAction($id): SingleResourceResponseInterface { |
|
| 183 | 183 | $objectManager = $this->entityManager; |
| 184 | 184 | $objectManager->remove($this->findOr404($id)); |
| 185 | 185 | $objectManager->flush(); |
| 186 | 186 | |
| 187 | 187 | return new SingleResourceResponse(null, new ResponseContext(204)); |
| 188 | - } |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - private function findOr404($id) { |
|
| 190 | + private function findOr404($id) { |
|
| 191 | 191 | if (null === $article = $this->articleProvider->getOneById($id)) { |
| 192 | - throw new NotFoundHttpException('Article was not found.'); |
|
| 192 | + throw new NotFoundHttpException('Article was not found.'); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | return $article; |
| 196 | - } |
|
| 196 | + } |
|
| 197 | 197 | } |