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,

View File

@ -0,0 +1,6 @@
{% set icon_class = layer_icon_class_map.getIconClass(layer) %}
<i class="{{ icon_class }}"></i>
<a href="{{
path('infinito_api_rest_layer_create',{'layer':layer,'_format':'html'})}}">
{{ layer|trans|capitalize }}
</a>

View File

@ -1,9 +1,3 @@
{% set icon_class = layer_icon_class_map.getIconClass(layer) %}
<i class="{{ icon_class }}"></i>
{# <a href="{{
path('infinito_api_rest_layer_read',{'layer':layer,'_format':'html'})}}">
#}
{{ layer|trans|capitalize }}: {# </a>#}
{% if slug is defined and slug%}
<a
href="{{ path('infinito_api_rest_layer_read',{'identity':slug,'layer':layer,'_format':'html'}) }}">

View File

@ -2,7 +2,7 @@
{% extends "frames/default.html.twig" %}
{% set layer = requested_action_service.getLayer()%}
{% set headline = (layer|trans|capitalize)~': ' %}
{% if requested_action_service.hasRequestedEntity()%}
{% if requested_action_service.hasRequestedEntity() and requested_action_service.getRequestedEntity().hasIdentity() %}
{% set entity = requested_action_service.getRequestedEntity().getEntity() %}
{% if entity.hasSlug is defined and entity.hasSlug %}
{% set headline = headline~entity.slug %}
@ -14,7 +14,10 @@
{% endblock %}
{% block content %}
<h1>
{% include "element/link/_layer_link.html.twig" with {'id':entity.getId(),'layer':layer,'slug':((entity.hasSlug() is defined and entity.hasSlug())?entity.getSlug():null)} %}
{% include "element/link/_layer_create_link.html.twig" with {'layer':layer} %}
{% if entity is defined%}
:{% include "element/link/_layer_read_link.html.twig" with {'id':entity.getId(),'layer':layer,'slug':((entity.hasSlug() is defined and entity.hasSlug())?entity.getSlug():null)} %}
{% endif %}
</h1>
{% if action_template_data_store_service.getAllStoredData().count() > 0 %}
<div id="accordion">