mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-10 06:27:24 +01:00
Implemented draft for CRUD management
This commit is contained in:
parent
eb55d4ef0b
commit
edf0a34e59
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\API;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface APIControllerInterface
|
||||
{
|
||||
/**
|
||||
* @param Request $request HTTP Method GET with filtering parameters
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function list(Request $request): Response;
|
||||
}
|
@ -5,20 +5,21 @@ namespace App\Controller\API;
|
||||
use App\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use App\Domain\SecureCRUDManagement\SecureCRUDFactoryService;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
* @todo Implement!
|
||||
* @see https://de.wikipedia.org/wiki/CRUD
|
||||
*/
|
||||
abstract class AbstractAPIController extends AbstractController implements APIControllerInterface
|
||||
abstract class AbstractAPIController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Request $request HTTP Method POST with the object attributes as parameters
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
abstract public function create(Request $request): Response;
|
||||
abstract public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response;
|
||||
|
||||
/**
|
||||
* @param Request $request HTTP Method GET
|
||||
@ -43,4 +44,11 @@ abstract class AbstractAPIController extends AbstractController implements APICo
|
||||
* @return Response
|
||||
*/
|
||||
abstract public function delete(Request $request, $identifier): Response;
|
||||
|
||||
/**
|
||||
* @param Request $request HTTP Method GET with filtering parameters
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
abstract public function list(Request $request): Response;
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\API;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Moved functions to
|
||||
* @see AbstractAPIController
|
||||
* @author kevinfrantz
|
||||
* @deprecated Feel free to delete this interface!
|
||||
* @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;
|
||||
}
|
@ -5,14 +5,20 @@ namespace App\Controller\API\Meta;
|
||||
use App\Controller\API\AbstractAPIController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use App\Domain\SecureCRUDManagement\SecureCRUDFactoryService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
* @todo Implement!
|
||||
*/
|
||||
class HeredityApiController extends AbstractAPIController
|
||||
{
|
||||
public function read(Request $request, $identifier): Response
|
||||
{
|
||||
}
|
||||
|
||||
public function create(Request $request): Response
|
||||
public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,11 @@ namespace App\Controller\API\Meta;
|
||||
use App\Controller\API\AbstractAPIController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use App\Domain\SecureCRUDManagement\SecureCRUDFactoryService;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
* @todo Implement!
|
||||
*/
|
||||
class LawApiController extends AbstractAPIController
|
||||
{
|
||||
@ -15,7 +17,7 @@ class LawApiController extends AbstractAPIController
|
||||
{
|
||||
}
|
||||
|
||||
public function create(Request $request): Response
|
||||
public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -5,14 +5,20 @@ namespace App\Controller\API\Meta;
|
||||
use App\Controller\API\AbstractAPIController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use App\Domain\SecureCRUDManagement\SecureCRUDFactoryService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
* @todo Implement!
|
||||
*/
|
||||
class MemberApiController extends AbstractAPIController
|
||||
{
|
||||
public function read(Request $request, $identifier): Response
|
||||
{
|
||||
}
|
||||
|
||||
public function create(Request $request): Response
|
||||
public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -5,14 +5,20 @@ namespace App\Controller\API\Meta;
|
||||
use App\Controller\API\AbstractAPIController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use App\Domain\SecureCRUDManagement\SecureCRUDFactoryService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
* @todo Implement!
|
||||
*/
|
||||
class RightApiController extends AbstractAPIController
|
||||
{
|
||||
public function read(Request $request, $identifier): Response
|
||||
{
|
||||
}
|
||||
|
||||
public function create(Request $request): Response
|
||||
public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -7,9 +7,12 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use App\Controller\API\AbstractAPIController;
|
||||
use App\Entity\Source\PureSource;
|
||||
use App\Domain\SecureCRUDManagement\SecureCRUDFactoryService;
|
||||
use App\Domain\SecureCRUDManagement\Create\SecureSourceCreatorInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
* @todo Implement!
|
||||
*/
|
||||
class SourceApiController extends AbstractAPIController
|
||||
{
|
||||
@ -20,7 +23,7 @@ class SourceApiController extends AbstractAPIController
|
||||
* )
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Controller\API\CRUDControllerInterface::read()
|
||||
* @see \App\Controller\API\AbstractAPIController::read()
|
||||
*/
|
||||
public function read(Request $request, $identifier): Response
|
||||
{
|
||||
@ -33,31 +36,43 @@ class SourceApiController extends AbstractAPIController
|
||||
* )
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Controller\API\CRUDControllerInterface::create()
|
||||
* @see \App\Controller\API\AbstractAPIController::create()
|
||||
*/
|
||||
public function create(Request $request): Response
|
||||
public function create(Request $request, SecureCRUDFactoryService $crudFactory): Response
|
||||
{
|
||||
$response = new Response();
|
||||
if (!$this->getUser()) {
|
||||
//throw $this->createAccessDeniedException('The user must be logged in!');
|
||||
}
|
||||
|
||||
if (Request::METHOD_POST === $request->getMethod()) {
|
||||
$response = new Response();
|
||||
$response->setContent('Post Request!');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response = new Response();
|
||||
$response->setContent('GET Request!');
|
||||
/**
|
||||
* @var SecureSourceCreatorInterface
|
||||
*/
|
||||
$sourceCreator = $crudFactory->create();
|
||||
$response->setContent($sourceCreator->create()->getText());
|
||||
|
||||
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());
|
||||
// $response = new Response();
|
||||
// $response->setContent('GET Request!');
|
||||
|
||||
return $sourceResponseManager->getResponse();
|
||||
// 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();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,7 +82,7 @@ class SourceApiController extends AbstractAPIController
|
||||
* )
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Controller\API\CRUDControllerInterface::update()
|
||||
* @see \App\Controller\API\AbstractAPIController::update()
|
||||
*/
|
||||
public function update(Request $request, $identifier): Response
|
||||
{
|
||||
@ -80,7 +95,7 @@ class SourceApiController extends AbstractAPIController
|
||||
* )
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Controller\API\APIControllerInterface::list()
|
||||
* @see \App\Controller\API\AbstractAPIController::list()
|
||||
*/
|
||||
public function list(Request $request): Response
|
||||
{
|
||||
@ -93,7 +108,7 @@ class SourceApiController extends AbstractAPIController
|
||||
* )
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Controller\API\CRUDControllerInterface::delete()
|
||||
* @see \App\Controller\API\AbstractAPIController::delete()
|
||||
*/
|
||||
public function delete(Request $request, $identifier): Response
|
||||
{
|
||||
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
* @todo Implement!
|
||||
*/
|
||||
abstract class AbstractSecureCRUD implements SecureCRUDInterface
|
||||
{
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\Create;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
* @todo Implement!
|
||||
*/
|
||||
abstract class AbstractSecureCreator implements SecureCreatorInterface
|
||||
{
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\Create;
|
||||
|
||||
use App\Domain\SecureCRUDManagement\SecureCRUDInterface;
|
||||
use App\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* @todo Implement!
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
interface SecureCreatorInterface extends SecureCRUDInterface
|
||||
{
|
||||
/**
|
||||
* @return EntityInterface The created entity
|
||||
*/
|
||||
public function create(): EntityInterface;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\Create;
|
||||
|
||||
use App\Entity\EntityInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use App\Entity\Source\Primitive\Text\TextSource;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Implement!
|
||||
*/
|
||||
class SecureSourceCreator extends AbstractSecureCreator implements SecureSourceCreatorInterface
|
||||
{
|
||||
public function __construct(Request $request, Security $security)
|
||||
{
|
||||
}
|
||||
|
||||
public function create(): EntityInterface
|
||||
{
|
||||
$source = new TextSource();
|
||||
$source->setText('Hello World!');
|
||||
|
||||
return $source;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement\Create;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
* @todo Implement!
|
||||
*/
|
||||
interface SecureSourceCreatorInterface extends SecureCreatorInterface
|
||||
{
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement;
|
||||
|
||||
use App\Entity\Meta\RightInterface;
|
||||
use App\Domain\SecureCRUDManagement\Create\SecureSourceCreator;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
* @todo Implement!
|
||||
* @todo substitute through child classes!
|
||||
*/
|
||||
class SecureCRUDFactoryService
|
||||
{
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* @var Security
|
||||
*/
|
||||
private $security;
|
||||
|
||||
public function __construct(RequestStack $requestStack, Security $security)
|
||||
{
|
||||
$this->request = $requestStack->getCurrentRequest();
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RightInterface $requestedRight
|
||||
*/
|
||||
public function create(?RightInterface $requestedRight = null)
|
||||
{
|
||||
return new SecureSourceCreator($this->request, $this->security);
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\SecureCRUDManagement;
|
||||
|
||||
/**
|
||||
* @todo Implement!
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
interface SecureCRUDInterface
|
||||
{
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Controller\API\Source;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class SourceControllerTest extends KernelTestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Optimize test!
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
$url = '/en/api/source.json';
|
||||
$request = new Request([], [], [], [], [], [
|
||||
'REQUEST_URI' => $url,
|
||||
]);
|
||||
$request->setMethod(Request::METHOD_GET);
|
||||
$response = static::$kernel->handle($request);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user