mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-04-16 02:06:23 +02:00
Optimized Controller Draft
This commit is contained in:
parent
bc9c8f02a9
commit
609f156bfd
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Controller\API;
|
namespace App\Controller\API;
|
||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use App\Controller\AbstractController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*/
|
*/
|
||||||
abstract class AbstractAPIController extends Controller implements APIControllerInterface
|
abstract class AbstractAPIController extends AbstractController implements APIControllerInterface
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use App\Controller\API\AbstractAPIController;
|
use App\Controller\API\AbstractAPIController;
|
||||||
|
use App\Entity\Source\PureSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
@ -28,7 +29,7 @@ class SourceApiController extends AbstractAPIController
|
|||||||
/**
|
/**
|
||||||
* @Route("/{_locale}/api/source.{_format}",
|
* @Route("/{_locale}/api/source.{_format}",
|
||||||
* defaults={"_format"="json"} ,
|
* defaults={"_format"="json"} ,
|
||||||
* methods={"POST"}
|
* methods={"POST","GET"}
|
||||||
* )
|
* )
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
@ -36,6 +37,27 @@ class SourceApiController extends AbstractAPIController
|
|||||||
*/
|
*/
|
||||||
public function create(Request $request): Response
|
public function create(Request $request): Response
|
||||||
{
|
{
|
||||||
|
if (Request::METHOD_POST === $request->getMethod()) {
|
||||||
|
$response = new Response();
|
||||||
|
$response->setContent('Post Request!');
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = new Response();
|
||||||
|
$response->setContent('GET Request!');
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
|
||||||
|
$requestedSource = new PureSource();
|
||||||
|
$requestedSource->setSlug(SystemSlugType::IMPRINT);
|
||||||
|
$requestedRight = new Right();
|
||||||
|
$requestedRight->setSource($requestedSource);
|
||||||
|
$requestedRight->setLayer(LayerType::SOURCE);
|
||||||
|
$requestedRight->setType(CRUDType::READ);
|
||||||
|
$sourceResponseManager = new SourceRESTResponseManager($this->getUser(), $entityManager, $requestedRight, $this->getViewHandler());
|
||||||
|
|
||||||
|
return $sourceResponseManager->getResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
12
application/src/Controller/AbstractController.php
Normal file
12
application/src/Controller/AbstractController.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use FOS\RestBundle\Controller\FOSRestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author kevinfrantz
|
||||||
|
*/
|
||||||
|
abstract class AbstractController extends FOSRestController
|
||||||
|
{
|
||||||
|
}
|
@ -1,88 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controller;
|
|
||||||
|
|
||||||
use App\Entity\EntityInterface;
|
|
||||||
use FOS\RestBundle\Controller\FOSRestController;
|
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo Check which of the as deprecated declared functions make sense to remove
|
|
||||||
*
|
|
||||||
* @author kevinfrantz
|
|
||||||
*/
|
|
||||||
abstract class AbstractEntityController extends FOSRestController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $entityName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->setEntityName();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
abstract protected function setEntityName(): void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*
|
|
||||||
* @param int $id
|
|
||||||
*
|
|
||||||
* @return EntityInterface
|
|
||||||
*/
|
|
||||||
protected function loadEntityById(int $id): EntityInterface
|
|
||||||
{
|
|
||||||
$entity = $this->getDoctrine()
|
|
||||||
->getRepository($this->entityName)
|
|
||||||
->find($id);
|
|
||||||
if (!$entity) {
|
|
||||||
throw $this->createNotFoundException('No entity found for id '.$id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*
|
|
||||||
* @param string $slug
|
|
||||||
*
|
|
||||||
* @return EntityInterface
|
|
||||||
*/
|
|
||||||
protected function loadEntityBySlug(string $slug): EntityInterface
|
|
||||||
{
|
|
||||||
$entity = $this->getDoctrine()
|
|
||||||
->getRepository($this->entityName)
|
|
||||||
->findOneBy(['slug' => $slug]);
|
|
||||||
if (!$entity) {
|
|
||||||
throw $this->createNotFoundException('No entity found for slug '.$slug);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*
|
|
||||||
* @param string $route
|
|
||||||
* @param int $id
|
|
||||||
*
|
|
||||||
* @return RedirectResponse
|
|
||||||
*/
|
|
||||||
protected function redirectToRouteById(string $route, int $id): RedirectResponse
|
|
||||||
{
|
|
||||||
return $this->redirectToRoute($route, [
|
|
||||||
'id' => $id,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,7 +18,7 @@ use App\Domain\ResponseManagement\SourceRESTResponseManager;
|
|||||||
*
|
*
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*/
|
*/
|
||||||
final class DefaultController extends AbstractEntityController
|
final class DefaultController extends AbstractController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @todo Optimize function!
|
* @todo Optimize function!
|
||||||
|
22
application/src/Controller/HtmlController.php
Normal file
22
application/src/Controller/HtmlController.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Offers an static webpage with bootstrap.
|
||||||
|
*
|
||||||
|
* @see https://getbootstrap.com/
|
||||||
|
*
|
||||||
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
|
* @todo Write tests!
|
||||||
|
*/
|
||||||
|
final class HtmlController extends AbstractController
|
||||||
|
{
|
||||||
|
public function html(Request $request): Response
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
23
application/src/Controller/SPAController.php
Normal file
23
application/src/Controller/SPAController.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Offers an SPA with Vue.js.
|
||||||
|
*
|
||||||
|
* @see https://vuejs.org/
|
||||||
|
* @see https://de.wikipedia.org/wiki/Single-Page-Webanwendung
|
||||||
|
*
|
||||||
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
|
* @todo Write tests!
|
||||||
|
*/
|
||||||
|
class SPAController extends AbstractController
|
||||||
|
{
|
||||||
|
public function spa(Request $request): Response
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,10 @@ namespace Tests\Integration\Controller;
|
|||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
class UrlIntegrationTest extends KernelTestCase
|
/**
|
||||||
|
* @author kevinfrantz
|
||||||
|
*/
|
||||||
|
class RoutesGetStatusIntegrationTest extends KernelTestCase
|
||||||
{
|
{
|
||||||
const GET_URLS_STATUS = [
|
const GET_URLS_STATUS = [
|
||||||
'login' => 200,
|
'login' => 200,
|
||||||
@ -13,6 +16,7 @@ class UrlIntegrationTest extends KernelTestCase
|
|||||||
'register' => 301,
|
'register' => 301,
|
||||||
'logout' => 302,
|
'logout' => 302,
|
||||||
'profile/edit' => 302,
|
'profile/edit' => 302,
|
||||||
|
'spa' => 200,
|
||||||
];
|
];
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Integration\Controller\API;
|
namespace Tests\Integration\Controller;
|
||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
use App\DBAL\Types\LanguageType;
|
use App\DBAL\Types\LanguageType;
|
||||||
@ -13,14 +13,14 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
*
|
*
|
||||||
* @todo Implement more tests for success etc.
|
* @todo Implement more tests for success etc.
|
||||||
*/
|
*/
|
||||||
class ApiUrlReachableIntegrationTest extends KernelTestCase
|
class RoutesReachableIntegrationTest extends KernelTestCase
|
||||||
{
|
{
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
self::bootKernel();
|
self::bootKernel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAllAPIRoutePossibilities()
|
public function testAllRoutePossibilities()
|
||||||
{
|
{
|
||||||
foreach (LayerType::getChoices() as $layer => $layerDescription) {
|
foreach (LayerType::getChoices() as $layer => $layerDescription) {
|
||||||
$this->controller($layer);
|
$this->controller($layer);
|
||||||
@ -52,8 +52,9 @@ class ApiUrlReachableIntegrationTest extends KernelTestCase
|
|||||||
private function language(string $entity, string $method): void
|
private function language(string $entity, string $method): void
|
||||||
{
|
{
|
||||||
//$this->type('api/'.$entity, $method);
|
//$this->type('api/'.$entity, $method);
|
||||||
foreach (LanguageType::getChoices() as $language => $value) {
|
foreach (LanguageType::getChoices() as $language) {
|
||||||
$this->type("$language/api/$entity", $method);
|
$this->type("$language/api/$entity", $method);
|
||||||
|
$this->type("$language/html/$entity", $method);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user