refs #2098. Move clients to different OU
parent
d99493ac46
commit
1bd32a32bb
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Controller\OgBoot\PxeBootFile\PostAction;
|
||||||
use App\Dto\Input\ChangeOrganizationalUnitInput;
|
use App\Dto\Input\ChangeOrganizationalUnitInput;
|
||||||
|
use App\Dto\Output\ClientOutput;
|
||||||
use App\Entity\Client;
|
use App\Entity\Client;
|
||||||
use App\Repository\ClientRepository;
|
use App\Repository\ClientRepository;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
@ -10,29 +12,37 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
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
|
class ChangeOrganizationalUnitAction extends AbstractController
|
||||||
{
|
{
|
||||||
public function __construct(
|
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
|
public function __invoke(ChangeOrganizationalUnitInput $input): JsonResponse
|
||||||
{
|
{
|
||||||
foreach ($input->clients as $client) {
|
foreach ($input->clients as $client) {
|
||||||
/** @var Client $client */
|
/** @var Client $clientEntity */
|
||||||
$clientEntity = $this->clientRepository->find($client->getEntity()->getId());
|
$clientEntity = $client->getEntity();
|
||||||
if (!$clientEntity) {
|
|
||||||
throw new NotFoundHttpException('Client not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
$organizationalUnit = $input->organizationalUnit->getEntity();
|
$organizationalUnit = $input->organizationalUnit->getEntity();
|
||||||
$clientEntity->setOrganizationalUnit($organizationalUnit);
|
$clientEntity->setOrganizationalUnit($organizationalUnit);
|
||||||
|
|
||||||
$this->entityManager->persist($clientEntity);
|
$this->entityManager->persist($clientEntity);
|
||||||
|
$this->postAction->__invoke($clientEntity, $clientEntity->getTemplate());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Dto\Input;
|
namespace App\Dto\Input;
|
||||||
|
|
||||||
|
use App\Dto\Output\ClientOutput;
|
||||||
use App\Dto\Output\OrganizationalUnitOutput;
|
use App\Dto\Output\OrganizationalUnitOutput;
|
||||||
use App\Entity\Client;
|
use App\Entity\Client;
|
||||||
use Symfony\Component\Serializer\Annotation\Groups;
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
|
@ -10,13 +11,13 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||||
final class ChangeOrganizationalUnitInput
|
final class ChangeOrganizationalUnitInput
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Client[]
|
* @var ClientOutput[]
|
||||||
*/
|
*/
|
||||||
#[Assert\GreaterThan(1)]
|
#[Assert\GreaterThan(1)]
|
||||||
#[Groups(['user-group:write'])]
|
#[Groups(['client:write'])]
|
||||||
public ?array $clients = [];
|
public ?array $clients = [];
|
||||||
|
|
||||||
#[Assert\NotNull]
|
#[Assert\NotNull]
|
||||||
#[Groups(['user-group:write'])]
|
#[Groups(['client:write'])]
|
||||||
public ?OrganizationalUnitOutput $organizationalUnit = null;
|
public ?OrganizationalUnitOutput $organizationalUnit = null;
|
||||||
}
|
}
|
Loading…
Reference in New Issue