@@ -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 | //$tenantCode = $request->query->get('tenant_code', ''); |
@@ -134,16 +134,16 @@ discard block |
||
134 | 134 | ->getOneOrNullResult(); |
135 | 135 | |
136 | 136 | if (null === $article) { |
137 | - throw new NotFoundHttpException('Article was not found'); |
|
137 | + throw new NotFoundHttpException('Article was not found'); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | return new SingleResourceResponse($article); |
141 | - } |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"}) |
|
145 | - */ |
|
146 | - public function updateAction(Request $request, $id): SingleResourceResponseInterface { |
|
143 | + /** |
|
144 | + * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"}) |
|
145 | + */ |
|
146 | + public function updateAction(Request $request, $id): SingleResourceResponseInterface { |
|
147 | 147 | $objectManager = $this->entityManager; |
148 | 148 | $article = $this->findOr404($id); |
149 | 149 | $originalArticleStatus = $article->getStatus(); |
@@ -152,32 +152,32 @@ discard block |
||
152 | 152 | |
153 | 153 | $form->handleRequest($request); |
154 | 154 | if ($form->isSubmitted() && $form->isValid()) { |
155 | - $this->articleService->reactOnStatusChange($originalArticleStatus, $article); |
|
156 | - $objectManager->flush(); |
|
157 | - $objectManager->refresh($article); |
|
155 | + $this->articleService->reactOnStatusChange($originalArticleStatus, $article); |
|
156 | + $objectManager->flush(); |
|
157 | + $objectManager->refresh($article); |
|
158 | 158 | |
159 | - return new SingleResourceResponse($article); |
|
159 | + return new SingleResourceResponse($article); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | return new SingleResourceResponse($form, new ResponseContext(500)); |
163 | - } |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"}) |
|
167 | - */ |
|
168 | - public function deleteAction($id): SingleResourceResponseInterface { |
|
165 | + /** |
|
166 | + * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"}) |
|
167 | + */ |
|
168 | + public function deleteAction($id): SingleResourceResponseInterface { |
|
169 | 169 | $objectManager = $this->entityManager; |
170 | 170 | $objectManager->remove($this->findOr404($id)); |
171 | 171 | $objectManager->flush(); |
172 | 172 | |
173 | 173 | return new SingleResourceResponse(null, new ResponseContext(204)); |
174 | - } |
|
174 | + } |
|
175 | 175 | |
176 | - private function findOr404($id) { |
|
176 | + private function findOr404($id) { |
|
177 | 177 | if (null === $article = $this->articleProvider->getOneById($id)) { |
178 | - throw new NotFoundHttpException('Article was not found.'); |
|
178 | + throw new NotFoundHttpException('Article was not found.'); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | return $article; |
182 | - } |
|
182 | + } |
|
183 | 183 | } |