mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 09:19:08 +00:00 
			
		
		
		
	Implemented draft for API
This commit is contained in:
		
							
								
								
									
										19
									
								
								application/src/Controller/API/APIControllerInterface.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								application/src/Controller/API/APIControllerInterface.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Controller\API; | ||||
|  | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
| use Symfony\Component\HttpFoundation\Response; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface APIControllerInterface extends CRUDControllerInterface | ||||
| { | ||||
|     /** | ||||
|      * @param Request $request HTTP Method GET with filtering parameters | ||||
|      * | ||||
|      * @return Response | ||||
|      */ | ||||
|     public function list(Request $request): Response; | ||||
| } | ||||
							
								
								
									
										10
									
								
								application/src/Controller/API/AbstractAPIController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								application/src/Controller/API/AbstractAPIController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Controller\API; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| abstract class AbstractAPIController implements APIControllerInterface | ||||
| { | ||||
| } | ||||
							
								
								
									
										45
									
								
								application/src/Controller/API/CRUDControllerInterface.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								application/src/Controller/API/CRUDControllerInterface.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,45 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Controller\API; | ||||
|  | ||||
| use Symfony\Component\HttpFoundation\Response; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  * | ||||
|  * @see https://de.wikipedia.org/wiki/CRUD | ||||
|  */ | ||||
| interface CRUDControllerInterface | ||||
| { | ||||
|     /** | ||||
|      * @param Request $request HTTP Method POST with the object attributes as parameters | ||||
|      * | ||||
|      * @return Response | ||||
|      */ | ||||
|     public function create(Request $request): Response; | ||||
|  | ||||
|     /** | ||||
|      * @param Request    $request    HTTP Method GET | ||||
|      * @param int|string $identifier The slug or id of the object | ||||
|      * | ||||
|      * @return Response | ||||
|      */ | ||||
|     public function read(Request $request, $identifier): Response; | ||||
|  | ||||
|     /** | ||||
|      * @param Request    $request    HTTP Method PUT | ||||
|      * @param int|string $identifier The slug or id of the object | ||||
|      * | ||||
|      * @return Response | ||||
|      */ | ||||
|     public function update(Request $request, $identifier): Response; | ||||
|  | ||||
|     /** | ||||
|      * @param Request    $request    HTTP Method DELETE with the object attributes as parameters | ||||
|      * @param int|string $identifier The slug or id of the object | ||||
|      * | ||||
|      * @return Response | ||||
|      */ | ||||
|     public function delete(Request $request, $identifier): Response; | ||||
| } | ||||
							
								
								
									
										33
									
								
								application/src/Controller/API/Meta/LawApiController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								application/src/Controller/API/Meta/LawApiController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Controller\API\Meta; | ||||
|  | ||||
| use App\Controller\API\AbstractAPIController; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
| use Symfony\Component\HttpFoundation\Response; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| class LawApiController extends AbstractAPIController | ||||
| { | ||||
|     public function read(Request $request, $identifier): Response | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     public function create(Request $request): Response | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     public function update(Request $request, $identifier): Response | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     public function list(Request $request): Response | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     public function delete(Request $request, $identifier): Response | ||||
|     { | ||||
|     } | ||||
| } | ||||
							
								
								
									
										30
									
								
								application/src/Controller/API/Meta/RightApiController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								application/src/Controller/API/Meta/RightApiController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Controller\API\Meta; | ||||
|  | ||||
| use App\Controller\API\AbstractAPIController; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
| use Symfony\Component\HttpFoundation\Response; | ||||
|  | ||||
| class RightApiController extends AbstractAPIController | ||||
| { | ||||
|     public function read(Request $request, $identifier): Response | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     public function create(Request $request): Response | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     public function update(Request $request, $identifier): Response | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     public function list(Request $request): Response | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     public function delete(Request $request, $identifier): Response | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,79 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Controller\API\Source; | ||||
|  | ||||
| use Symfony\Component\HttpFoundation\Response; | ||||
| use Symfony\Component\Routing\Annotation\Route; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
| use App\Controller\API\AbstractAPIController; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| class SourceApiController extends AbstractAPIController | ||||
| { | ||||
|     /** | ||||
|      * @Route("/api/{_locale}/source/{identifier}.{_format}", | ||||
|      * defaults={"_format"="json"} , | ||||
|      * methods={"GET"} | ||||
|      * ) | ||||
|      * {@inheritdoc} | ||||
|      * | ||||
|      * @see \App\Controller\API\CRUDControllerInterface::read() | ||||
|      */ | ||||
|     public function read(Request $request, $identifier): Response | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @Route("/api/{_locale}/source/.{_format}", | ||||
|      * defaults={"_format"="json"} , | ||||
|      * methods={"POST"} | ||||
|      * ) | ||||
|      * {@inheritdoc} | ||||
|      * | ||||
|      * @see \App\Controller\API\CRUDControllerInterface::create() | ||||
|      */ | ||||
|     public function create(Request $request): Response | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @Route("/api/{_locale}/source/{identifier}.{_format}", | ||||
|      * defaults={"_format"="json"} , | ||||
|      * methods={"PUT"} | ||||
|      * ) | ||||
|      * {@inheritdoc} | ||||
|      * | ||||
|      * @see \App\Controller\API\CRUDControllerInterface::update() | ||||
|      */ | ||||
|     public function update(Request $request, $identifier): Response | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @Route("/api/{_locale}/sources/.{_format}", | ||||
|      * defaults={"_format"="json"} , | ||||
|      * methods={"GET"} | ||||
|      * ) | ||||
|      * {@inheritdoc} | ||||
|      * | ||||
|      * @see \App\Controller\API\APIControllerInterface::list() | ||||
|      */ | ||||
|     public function list(Request $request): Response | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @Route("/api/{_locale}/source/{identifier}.{_format}", | ||||
|      * defaults={"_format"="json"} , | ||||
|      * methods={"DELETE"} | ||||
|      * ) | ||||
|      * {@inheritdoc} | ||||
|      * | ||||
|      * @see \App\Controller\API\CRUDControllerInterface::delete() | ||||
|      */ | ||||
|     public function delete(Request $request, $identifier): Response | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -1,60 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Controller; | ||||
|  | ||||
| use Symfony\Component\HttpFoundation\Response; | ||||
| use Symfony\Component\HttpFoundation\RedirectResponse; | ||||
| use Symfony\Component\Routing\Annotation\Route; | ||||
| use App\Entity\Meta\Law; | ||||
| use App\Entity\Meta\LawInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  * | ||||
|  * @todo Implement security! | ||||
|  */ | ||||
| class LawController extends AbstractEntityController | ||||
| { | ||||
|     /** | ||||
|      * @Route("/law/{id}.{_format}", defaults={"_format"="html"}) | ||||
|      */ | ||||
|     public function show(int $id): Response | ||||
|     { | ||||
|         /** | ||||
|          * @var LawInterface | ||||
|          */ | ||||
|         $law = $this->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; | ||||
|     } | ||||
| } | ||||
| @@ -1,82 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Controller; | ||||
|  | ||||
| use Symfony\Component\HttpFoundation\Response; | ||||
| use Symfony\Component\Routing\Annotation\Route; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
| use App\Creator\Factory\Template\Source\SourceTemplateFactory; | ||||
| use App\Entity\Source\SourceInterface; | ||||
| use App\Creator\Factory\Template\Source\SourceTemplateFormFactory; | ||||
| use App\Creator\Factory\Form\Source\SourceFormFactory; | ||||
| use Symfony\Component\HttpFoundation\RedirectResponse; | ||||
| use App\Entity\Source\AbstractSource; | ||||
| use App\Entity\Meta\RelationInterface; | ||||
|  | ||||
| /** | ||||
|  * @todo IMPLEMENT SECURITY! | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| class SourceController extends AbstractEntityController | ||||
| { | ||||
|     /** | ||||
|      * @Route("/source/{id}.{_format}", defaults={"_format"="html"}) | ||||
|      */ | ||||
|     public function show(Request $request, int $id): Response | ||||
|     { | ||||
|         $source = $this->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; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user