Optimized implementation of create

This commit is contained in:
Kevin Frantz
2019-02-25 20:45:15 +01:00
parent 6d146c8478
commit 90b14a1ef5
6 changed files with 35 additions and 14 deletions

View File

@@ -16,9 +16,7 @@ use Infinito\DBAL\Types\ActionType;
* @see https://symfony.com/blog/new-in-symfony-4-1-prefix-imported-route-names
* @see https://symfony.com/blog/new-in-symfony-4-1-internationalized-routing
* @Route(
* {
* "en":"/api/rest/{layer}/{identity}.{_format}",
* },
* "/api/rest/{layer}",
* defaults={
* "identity"="",
* "_format"="json"
@@ -29,6 +27,25 @@ final class LayerController extends AbstractAPIController
{
/**
* @Route(
* ".{_format}",
* methods={"GET","POST"}
* )
* {@inheritdoc}
*
* @see \Infinito\Controller\API\AbstractAPIController::read()
*/
public function create(MVCRoutineServiceInterface $mvcRoutineService, RequestedActionServiceInterface $requestedActionService, string $layer, $identity): Response
{
$requestedActionService->setActionType(ActionType::CREATE);
$requestedActionService->setLayer($layer);
$view = $mvcRoutineService->process();
return $this->handleView($view);
}
/**
* @Route(
* "/{identity}.{_format}",
* methods={"GET"}
* )
* {@inheritdoc}

View File

@@ -11,6 +11,7 @@ use Infinito\DBAL\Types\ActionType;
use Infinito\Domain\FormManagement\RequestedActionFormBuilderServiceInterface;
use Infinito\Domain\RequestManagement\Action\RequestedActionServiceInterface;
use Infinito\Domain\SecureManagement\SecureRequestedRightCheckerServiceInterface;
use Infinito\Entity\Source\Primitive\Text\TextSource;
/**
* @author kevinfrantz
@@ -90,7 +91,7 @@ final class MVCRoutineService implements MVCRoutineServiceInterface
public function process(): View
{
if (!$this->actionType) {
if ($this->requestedActionService->hasRequestedEntity()) {
if ($this->requestedActionService->hasRequestedEntity() && $this->requestedActionService->getRequestedEntity()->hasIdentity()) {
//READ
$this->requestedActionService->setActionType(ActionType::READ);
if ($this->secureRequestedRightCheckerService->check($this->requestedActionService)) {
@@ -108,6 +109,7 @@ final class MVCRoutineService implements MVCRoutineServiceInterface
} else {
//CREATE
$this->requestedActionService->setActionType(ActionType::CREATE);
$this->requestedActionService->getRequestedEntity()->setClass(TextSource::class);
$updateForm = $this->requestedActionFormBuilderService->createByService()->getForm()->createView();
$this->actionTemplateDataStore->setData(ActionType::CREATE, $updateForm);
}

View File

@@ -8,7 +8,6 @@ use Infinito\Exception\NotSetException;
use Infinito\DBAL\Types\ActionType;
use Infinito\Exception\NotDefinedException;
use Infinito\Exception\NoValidChoiceException;
use Infinito\Form\AbstractType;
use Infinito\Entity\EntityInterface;
use Infinito\Exception\NotCorrectInstanceException;
use Doctrine\Common\Collections\Collection;
@@ -23,7 +22,7 @@ final class ActionTemplateDataStoreService implements ActionTemplateDataStoreSer
* @var array|string[] Maps the action to an return type
*/
const ACTION_DATA_MAPPING = [
ActionType::CREATE => AbstractType::class,
ActionType::CREATE => FormView::class,
ActionType::READ => EntityInterface::class, // Mayber change this to refection later!
ActionType::UPDATE => FormView::class,
ActionType::DELETE => EntityInterface::class,