refs #2098. Move clients to different OU
parent
d99493ac46
commit
1bd32a32bb
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue