refs #617. Added single classroom integration

feature/integration-dhcp
Manuel Aranda Rosales 2024-09-04 16:20:48 +02:00
parent 07b419016e
commit 5d9b347098
4 changed files with 79 additions and 1 deletions

View File

@ -113,6 +113,15 @@ resources:
uriTemplate: /og-dhcp/server/{uuid}/delete-host
controller: App\Controller\OgDhcp\Subnet\DeleteHostAction
add_single_organizational_unit:
shortName: Subnet Server Organizational Units
description: Add Single Organizational Unit to Subnet
class: ApiPlatform\Metadata\Post
method: POST
input: App\Dto\Input\SubnetAddSingleOrganizationalUnitInput
uriTemplate: /og-dhcp/server/{uuid}/add-single-organizational-unit
controller: App\Controller\OgDhcp\Subnet\AddSingleOrganizationalUnitAction
properties:
App\Entity\Subnet:
id:

View File

@ -0,0 +1,54 @@
<?php
namespace App\Controller\OgDhcp\Subnet;
use App\Controller\OgDhcp\AbstractOgDhcpController;
use App\Dto\Input\SubnetAddSingleHostInput;
use App\Dto\Input\SubnetAddSingleOrganizationalUnitInput;
use App\Entity\Client;
use App\Entity\OrganizationalUnit;
use App\Entity\Subnet;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Validator\Exception\ValidatorException;
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 AddSingleOrganizationalUnitAction extends AbstractOgDhcpController
{
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function __invoke(SubnetAddSingleOrganizationalUnitInput $input, Subnet $subnet, HttpClientInterface $httpClient): JsonResponse
{
$ou = $input->organizationalUnitOutput;
/** @var OrganizationalUnit $organizationalUnitEntity */
$organizationalUnitEntity = $ou->getEntity();
$params = [
'json' => [
'name' => $organizationalUnitEntity->getId(),
'nextServer' => $organizationalUnitEntity->getNetworkSettings()?->getNextServer(),
'bootFileName' => $organizationalUnitEntity->getNetworkSettings()?->getBootFileName(),
]
];
$content = $this->createRequest($httpClient, 'POST', $this->ogDhcpApiUrl.'/ogdhcp/v1/subnets/'.$subnet->getId().'/classroom', $params);
if ($content->getStatusCode() === 200) {
$subnet->addOrganizationalUnit($organizationalUnitEntity);
$this->entityManager->persist($subnet);
$this->entityManager->flush();
}
return new JsonResponse(data: $content, status: Response::HTTP_OK);
}
}

View File

@ -11,5 +11,5 @@ final class SubnetAddSingleHostInput
{
#[Assert\NotNull]
#[Groups(['subnet:write'])]
public ClientOutput $client;
public ?ClientOutput $client = null;
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Dto\Input;
use ApiPlatform\Metadata\ApiProperty;
use App\Dto\Output\OrganizationalUnitOutput;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
final class SubnetAddSingleOrganizationalUnitInput
{
#[Assert\NotNull]
#[Groups(['subnet:write'])]
public ?OrganizationalUnitOutput $organizationalUnitOutput = null;
}