From 1bd32a32bb9c21f198b35198a53a4408ee5ad3d7 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Mon, 2 Jun 2025 00:10:47 +0200 Subject: [PATCH] refs #2098. Move clients to different OU --- .../ChangeOrganizationalUnitAction.php | 24 +++++++++++++------ .../Input/ChangeOrganizationalUnitInput.php | 7 +++--- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Controller/ChangeOrganizationalUnitAction.php b/src/Controller/ChangeOrganizationalUnitAction.php index 4d0609b..66e3ec1 100644 --- a/src/Controller/ChangeOrganizationalUnitAction.php +++ b/src/Controller/ChangeOrganizationalUnitAction.php @@ -2,7 +2,9 @@ namespace App\Controller; +use App\Controller\OgBoot\PxeBootFile\PostAction; use App\Dto\Input\ChangeOrganizationalUnitInput; +use App\Dto\Output\ClientOutput; use App\Entity\Client; use App\Repository\ClientRepository; use Doctrine\ORM\EntityManagerInterface; @@ -10,29 +12,37 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; class ChangeOrganizationalUnitAction extends AbstractController { public function __construct( - private readonly ClientRepository $clientRepository, - private readonly EntityManagerInterface $entityManager + private readonly EntityManagerInterface $entityManager, + private PostAction $postAction, ) { } + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws ClientExceptionInterface + */ public function __invoke(ChangeOrganizationalUnitInput $input): JsonResponse { foreach ($input->clients as $client) { - /** @var Client $client */ - $clientEntity = $this->clientRepository->find($client->getEntity()->getId()); - if (!$clientEntity) { - throw new NotFoundHttpException('Client not found'); - } + /** @var Client $clientEntity */ + $clientEntity = $client->getEntity(); $organizationalUnit = $input->organizationalUnit->getEntity(); $clientEntity->setOrganizationalUnit($organizationalUnit); $this->entityManager->persist($clientEntity); + $this->postAction->__invoke($clientEntity, $clientEntity->getTemplate()); } $this->entityManager->flush(); diff --git a/src/Dto/Input/ChangeOrganizationalUnitInput.php b/src/Dto/Input/ChangeOrganizationalUnitInput.php index 71f8cec..922e66b 100644 --- a/src/Dto/Input/ChangeOrganizationalUnitInput.php +++ b/src/Dto/Input/ChangeOrganizationalUnitInput.php @@ -2,6 +2,7 @@ namespace App\Dto\Input; +use App\Dto\Output\ClientOutput; use App\Dto\Output\OrganizationalUnitOutput; use App\Entity\Client; use Symfony\Component\Serializer\Annotation\Groups; @@ -10,13 +11,13 @@ use Symfony\Component\Validator\Constraints as Assert; final class ChangeOrganizationalUnitInput { /** - * @var Client[] + * @var ClientOutput[] */ #[Assert\GreaterThan(1)] - #[Groups(['user-group:write'])] + #[Groups(['client:write'])] public ?array $clients = []; #[Assert\NotNull] - #[Groups(['user-group:write'])] + #[Groups(['client:write'])] public ?OrganizationalUnitOutput $organizationalUnit = null; } \ No newline at end of file