refs #614. Itnegration ogDhcp. Change some params
parent
a232d5cbd7
commit
e7b303cc11
|
@ -80,7 +80,7 @@ resources:
|
|||
get_hosts:
|
||||
shortName: Subnet Server Hosts
|
||||
description: Get Hosts of Subnet
|
||||
class: ApiPlatform\Metadata\GetCollection
|
||||
class: ApiPlatform\Metadata\Get
|
||||
method: GET
|
||||
input: false
|
||||
uriTemplate: /og-dhcp/server/{uuid}/get-hosts
|
||||
|
|
|
@ -34,6 +34,6 @@ class DeleteAction extends AbstractOgDhcpController
|
|||
$this->entityManager->remove($data);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new JsonResponse(status: Response::HTTP_OK);
|
||||
return new JsonResponse(data: $content, status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ namespace App\Controller\OgDhcp\Subnet;
|
|||
|
||||
use App\Controller\OgDhcp\AbstractOgDhcpController;
|
||||
use App\Dto\Input\SubnetAddHostInput;
|
||||
use App\Dto\Output\ClientOutput;
|
||||
use App\Entity\Client;
|
||||
use App\Entity\Subnet;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
@ -25,17 +26,17 @@ class PostHostAction extends AbstractOgDhcpController
|
|||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(SubnetAddHostInput $input, HttpClientInterface $httpClient): JsonResponse
|
||||
public function __invoke(SubnetAddHostInput $input, Subnet $subnet, HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
$subnet = $input->subnet->getEntity();
|
||||
$clients = $input->clients;
|
||||
|
||||
/** @var Client $client */
|
||||
foreach ($clients as $client) {
|
||||
/** @var Client $clientEntity */
|
||||
$clientEntity = $client->getEntity();
|
||||
$data = [
|
||||
'host' => $client->getName(),
|
||||
'macAddress' => $client->getMac(),
|
||||
'address' => $client->getIp(),
|
||||
'host' => $clientEntity->getName(),
|
||||
'macAddress' => $clientEntity->getMac(),
|
||||
'address' => $clientEntity->getIp(),
|
||||
];
|
||||
|
||||
$params = [
|
||||
|
|
|
@ -25,7 +25,7 @@ class PutAction extends AbstractOgDhcpController
|
|||
*/
|
||||
public function __invoke(Subnet $data, HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
if (null === $data->getId()) {
|
||||
if (!$data->getId()) {
|
||||
throw new ValidatorException('Id is required');
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ class PutAction extends AbstractOgDhcpController
|
|||
]
|
||||
];
|
||||
|
||||
$content = $this->createRequest($httpClient, 'POST', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getId(), $params);
|
||||
$content = $this->createRequest($httpClient, 'PUT', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$data->getId(), $params);
|
||||
|
||||
$this->entityManager->persist($data);
|
||||
$this->entityManager->flush();
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Controller\OgDhcp\Subnet;
|
|||
use App\Controller\OgDhcp\AbstractOgDhcpController;
|
||||
use App\Dto\Input\SubnetAddHostInput;
|
||||
use App\Entity\Client;
|
||||
use App\Entity\Subnet;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
|
@ -23,15 +24,15 @@ class PutHostAction extends AbstractOgDhcpController
|
|||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(SubnetAddHostInput $input, HttpClientInterface $httpClient): JsonResponse
|
||||
public function __invoke(SubnetAddHostInput $input, Subnet $subnet, HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
$subnet = $input->subnet->getEntity();
|
||||
$clients = $input->clients;
|
||||
|
||||
/** @var Client $client */
|
||||
foreach ($clients as $client) {
|
||||
/** @var Client $clientEntity */
|
||||
$clientEntity = $client->getEntity();
|
||||
$data = [
|
||||
'host' => $client->getName(),
|
||||
'host' => $clientEntity->getName(),
|
||||
'oldMacAddress' => '',
|
||||
'macAddress' => '',
|
||||
'address' => '',
|
||||
|
|
|
@ -12,11 +12,6 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
|
||||
final class SubnetAddHostInput
|
||||
{
|
||||
#[Assert\NotNull(message: 'validators.subnet_add_host.subnet.not_null')]
|
||||
#[Groups(['subnet:write'])]
|
||||
#[ApiProperty(description: 'The subnet of the pxeBootFile', example: "Subnet 1")]
|
||||
public ?SubnetOutput $subnet = null;
|
||||
|
||||
/**
|
||||
* @var ClientOutput[]
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue