diff --git a/src/State/EntityStateProcessor.php b/src/State/EntityStateProcessor.php new file mode 100644 index 0000000..6cbe456 --- /dev/null +++ b/src/State/EntityStateProcessor.php @@ -0,0 +1,32 @@ +deleteProcessor->process($data, $operation, $uriVariables, $context); + } + + return $this->persistProcessor->process($data, $operation, $uriVariables, $context); + } +} diff --git a/src/State/Project/ProjectStateProcessor.php b/src/State/Project/ProjectStateProcessor.php index c3d64de..29784db 100644 --- a/src/State/Project/ProjectStateProcessor.php +++ b/src/State/Project/ProjectStateProcessor.php @@ -2,25 +2,19 @@ namespace App\State\Project; -use ApiPlatform\Doctrine\Common\State\PersistProcessor; -use ApiPlatform\Doctrine\Common\State\RemoveProcessor; -use ApiPlatform\Metadata\DeleteOperationInterface; use ApiPlatform\Metadata\Operation; use ApiPlatform\State\ProcessorInterface; use App\ApiResource\Project\ProjectApiResource; use App\Entity\Project\Project; use App\Mapping\AutoMapper; use App\Service\Auth\AuthService; -use Symfony\Component\DependencyInjection\Attribute\Autowire; +use App\State\EntityStateProcessor; use Symfony\Component\Security\Core\Exception\AuthenticationException; class ProjectStateProcessor implements ProcessorInterface { public function __construct( - #[Autowire(service: RemoveProcessor::class)] - private ProcessorInterface $deleteProcessor, - #[Autowire(service: PersistProcessor::class)] - private ProcessorInterface $persistProcessor, + private EntityStateProcessor $entityStateProcessor, private AutoMapper $autoMapper, private AuthService $authService, ) {} @@ -45,13 +39,7 @@ class ProjectStateProcessor implements ProcessorInterface $project->setOwner($owner); } - if ($operation instanceof DeleteOperationInterface) { - $this->deleteProcessor->process($project, $operation, $uriVariables, $context); - - return null; - } - - $this->persistProcessor->process($project, $operation, $uriVariables, $context); + $project = $this->entityStateProcessor->process($project, $operation, $uriVariables, $context); return $this->autoMapper->map($project, $data); }