ogcore/src/Controller/OgBoot/PxeTemplate/AddClientAction.php

44 lines
1.5 KiB
PHP

<?php
namespace App\Controller\OgBoot\PxeTemplate;
use App\Controller\OgDhcp\AbstractOgDhcpController;
use App\Dto\Input\PxeTemplateAddClientsInput;
use App\Entity\Client;
use App\Entity\PxeTemplate;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
#[AsController]
class AddClientAction extends AbstractOgDhcpController
{
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function __invoke(PxeTemplateAddClientsInput $input, PxeTemplate $pxeTemplate, HttpClientInterface $httpClient): JsonResponse
{
$clients = $input->clients;
foreach ($clients as $client) {
/** @var Client $clientEntity */
$clientEntity = $client->getEntity();
$clientEntity->setTemplate($pxeTemplate);
$this->entityManager->persist($clientEntity);
}
$this->entityManager->flush();
return new JsonResponse(status: Response::HTTP_OK);
}
}