From e7b303cc11a5facc8ac7dfd243fcd82a9b742058 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Thu, 29 Aug 2024 09:00:05 +0200 Subject: [PATCH] refs #614. Itnegration ogDhcp. Change some params --- config/api_platform/Subnet.yaml | 2 +- src/Controller/OgDhcp/Subnet/DeleteAction.php | 2 +- src/Controller/OgDhcp/Subnet/PostHostAction.php | 13 +++++++------ src/Controller/OgDhcp/Subnet/PutAction.php | 4 ++-- src/Controller/OgDhcp/Subnet/PutHostAction.php | 9 +++++---- src/Dto/Input/SubnetAddHostInput.php | 5 ----- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/config/api_platform/Subnet.yaml b/config/api_platform/Subnet.yaml index 747efb9..1755518 100644 --- a/config/api_platform/Subnet.yaml +++ b/config/api_platform/Subnet.yaml @@ -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 diff --git a/src/Controller/OgDhcp/Subnet/DeleteAction.php b/src/Controller/OgDhcp/Subnet/DeleteAction.php index 0344240..8f687c5 100644 --- a/src/Controller/OgDhcp/Subnet/DeleteAction.php +++ b/src/Controller/OgDhcp/Subnet/DeleteAction.php @@ -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); } } \ No newline at end of file diff --git a/src/Controller/OgDhcp/Subnet/PostHostAction.php b/src/Controller/OgDhcp/Subnet/PostHostAction.php index d2bdbb3..d1c15c9 100644 --- a/src/Controller/OgDhcp/Subnet/PostHostAction.php +++ b/src/Controller/OgDhcp/Subnet/PostHostAction.php @@ -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 = [ diff --git a/src/Controller/OgDhcp/Subnet/PutAction.php b/src/Controller/OgDhcp/Subnet/PutAction.php index 252343d..f57b282 100644 --- a/src/Controller/OgDhcp/Subnet/PutAction.php +++ b/src/Controller/OgDhcp/Subnet/PutAction.php @@ -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(); diff --git a/src/Controller/OgDhcp/Subnet/PutHostAction.php b/src/Controller/OgDhcp/Subnet/PutHostAction.php index 55d7f6f..3815ca4 100644 --- a/src/Controller/OgDhcp/Subnet/PutHostAction.php +++ b/src/Controller/OgDhcp/Subnet/PutHostAction.php @@ -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' => '', diff --git a/src/Dto/Input/SubnetAddHostInput.php b/src/Dto/Input/SubnetAddHostInput.php index c5b10aa..bc5015e 100644 --- a/src/Dto/Input/SubnetAddHostInput.php +++ b/src/Dto/Input/SubnetAddHostInput.php @@ -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[] */