From 23a4e1c679f48f796d6c4ac664a410eb8f6feb92 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sat, 5 Jan 2019 15:34:02 +0100 Subject: [PATCH] Implemented draft for API --- administration/test-everything.sh | 2 +- .../Controller/API/APIControllerInterface.php | 19 +++++ .../Controller/API/AbstractAPIController.php | 10 +++ .../API/CRUDControllerInterface.php | 45 ++++++++++ .../Controller/API/Meta/LawApiController.php | 33 ++++++++ .../API/Meta/RightApiController.php | 30 +++++++ .../API/Source/SourceApiController.php | 79 ++++++++++++++++++ application/src/Controller/LawController.php | 60 -------------- .../src/Controller/SourceController.php | 82 ------------------- 9 files changed, 217 insertions(+), 143 deletions(-) create mode 100644 application/src/Controller/API/APIControllerInterface.php create mode 100644 application/src/Controller/API/AbstractAPIController.php create mode 100644 application/src/Controller/API/CRUDControllerInterface.php create mode 100644 application/src/Controller/API/Meta/LawApiController.php create mode 100644 application/src/Controller/API/Meta/RightApiController.php create mode 100644 application/src/Controller/API/Source/SourceApiController.php delete mode 100644 application/src/Controller/LawController.php delete mode 100644 application/src/Controller/SourceController.php diff --git a/administration/test-everything.sh b/administration/test-everything.sh index df55d66..233d119 100644 --- a/administration/test-everything.sh +++ b/administration/test-everything.sh @@ -3,5 +3,5 @@ cd "$(dirname "$(readlink -f "${0}")")/" && bash ./clear.sh && bash ./schema-validate.sh && bash ./test.sh && -bash ./test-code-format.sh +bash ./test-code-format.sh && bash ./shellcheck.sh diff --git a/application/src/Controller/API/APIControllerInterface.php b/application/src/Controller/API/APIControllerInterface.php new file mode 100644 index 0000000..e98e9fe --- /dev/null +++ b/application/src/Controller/API/APIControllerInterface.php @@ -0,0 +1,19 @@ +loadEntityById($id); - $view = $this->view($law, 200) - ->setTemplate('law/view/standard.html.twig') - ->setTemplateVar('law'); - - return $this->handleView($view); - } - - /** - * @Route("/law/{id}/right.{_format}", defaults={"_format"="html"}) - */ - public function right(int $id): RedirectResponse - { - /* - * - * @todo Implement function! - */ - } - - /** - * @Route("/law/{id}/node.{_format}", defaults={"_format"="html"}) - */ - public function node(int $id): RedirectResponse - { - /* - * - * @todo Implement function! - */ - } - - protected function setEntityName(): void - { - $this->entityName = Law::class; - } -} diff --git a/application/src/Controller/SourceController.php b/application/src/Controller/SourceController.php deleted file mode 100644 index 54f3fb2..0000000 --- a/application/src/Controller/SourceController.php +++ /dev/null @@ -1,82 +0,0 @@ -loadEntityById($id); - // $assembler = $this->get(SourceDTOAssember::class); - // $dto = $assembler->build($source, $this->getUser()); - $view = $this->view($source, 200) - ->setTemplate((new SourceTemplateFactory($source, $request))->getTemplatePath()) - ->setTemplateVar('source'); - - return $this->handleView($view); - } - - /** - * @Route("/source/{id}/edit.{_format}", defaults={"_format"="html"}) - */ - public function edit(Request $request, int $id): Response - { - $source = $this->loadEntityById($id); - $form = $this->createForm((new SourceFormFactory($source))->getNamespace(), $source); - $form->handleRequest($request); - if ($form->isSubmitted() && $form->isValid()) { - $source = $form->getData(); - $this->saveSource($source); - } - - return $this->render((new SourceTemplateFormFactory($source, $request))->getTemplatePath(), [ - 'form' => $form->createView(), - ]); - } - - /** - * @Route("/source/{id}/node.{_format}", defaults={"_format"="html"}) - */ - public function node(int $id): RedirectResponse - { - $nodeId = $this->loadNodeById($id)->getId(); - - return $this->redirectToRouteById('app_node_show', $nodeId); - } - - private function loadNodeById(int $id): RelationInterface - { - return $this->loadEntityById($id)->getNode(); - } - - private function saveSource(SourceInterface $source): void - { - $entityManager = $this->getDoctrine()->getManager(); - $entityManager->persist($source); - $entityManager->flush(); - } - - protected function setEntityName(): void - { - $this->entityName = AbstractSource::class; - } -}