refs #617. Added single classroom integration
parent
07b419016e
commit
5d9b347098
|
@ -113,6 +113,15 @@ resources:
|
||||||
uriTemplate: /og-dhcp/server/{uuid}/delete-host
|
uriTemplate: /og-dhcp/server/{uuid}/delete-host
|
||||||
controller: App\Controller\OgDhcp\Subnet\DeleteHostAction
|
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:
|
properties:
|
||||||
App\Entity\Subnet:
|
App\Entity\Subnet:
|
||||||
id:
|
id:
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,5 +11,5 @@ final class SubnetAddSingleHostInput
|
||||||
{
|
{
|
||||||
#[Assert\NotNull]
|
#[Assert\NotNull]
|
||||||
#[Groups(['subnet:write'])]
|
#[Groups(['subnet:write'])]
|
||||||
public ClientOutput $client;
|
public ?ClientOutput $client = null;
|
||||||
}
|
}
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue