87 lines
3.0 KiB
PHP
87 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Dto\Input;
|
|
|
|
use ApiPlatform\Metadata\ApiProperty;
|
|
use App\Dto\Output\HardwareProfileOutput;
|
|
use App\Dto\Output\OrganizationalUnitOutput;
|
|
use App\Entity\Client;
|
|
use Symfony\Component\Serializer\Annotation\Groups;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
final class ClientInput
|
|
{
|
|
#[Assert\NotBlank]
|
|
#[Groups(['client:write'])]
|
|
#[ApiProperty(description: 'The name of the client', example: "Client 1")]
|
|
public ?string $name = null;
|
|
|
|
#[Groups(['client:write'])]
|
|
#[ApiProperty(description: 'The serial number of the client', example: "123456")]
|
|
public ?string $serialNumber = null;
|
|
|
|
#[Groups(['client:write'])]
|
|
#[ApiProperty(description: 'The network interface of the client', example: "eth0")]
|
|
public ?string $netiface = null;
|
|
|
|
#[Groups(['client:write'])]
|
|
#[ApiProperty(description: 'The network driver of the client', example: "e1000e")]
|
|
public ?string $netDriver = null;
|
|
|
|
#[Groups(['client:write'])]
|
|
#[ApiProperty(description: 'The MAC address of the client', example: "00:11:22:33:44:55")]
|
|
public ?string $mac = null;
|
|
|
|
#[Groups(['client:write'])]
|
|
#[ApiProperty(description: 'The IP address of the client', example: "127.0.0.1")]
|
|
public ?string $ip = null;
|
|
|
|
#[Groups(['client:write'])]
|
|
public ?string $status = null;
|
|
|
|
#[Assert\NotNull]
|
|
#[Groups(['client:write', 'client:patch'])]
|
|
#[ApiProperty(description: 'The organizational unit of the client')]
|
|
public ?OrganizationalUnitOutput $organizationalUnit = null;
|
|
|
|
#[Assert\NotNull]
|
|
#[Groups(['client:write', 'client:patch'])]
|
|
#[ApiProperty(description: 'The hardware profile of the client')]
|
|
public ?HardwareProfileOutput $hardwareProfile = null;
|
|
|
|
public function __construct(?Client $client = null)
|
|
{
|
|
if (!$client) {
|
|
return;
|
|
}
|
|
|
|
$this->name = $client->getName();
|
|
$this->serialNumber = $client->getSerialNumber();
|
|
$this->netiface = $client->getNetiface();
|
|
$this->organizationalUnit = new OrganizationalUnitOutput($client->getOrganizationalUnit());
|
|
$this->hardwareProfile = new HardwareProfileOutput($client->getHardwareProfile());
|
|
$this->netDriver = $client->getNetDriver();
|
|
$this->mac = $client->getMac();
|
|
$this->ip = $client->getIp();
|
|
$this->status = $client->getStatus();
|
|
}
|
|
|
|
public function createOrUpdateEntity(?Client $client = null): Client
|
|
{
|
|
if (!$client) {
|
|
$client = new Client();
|
|
}
|
|
|
|
$client->setName($this->name);
|
|
$client->setSerialNumber($this->serialNumber);
|
|
$client->setNetiface($this->netiface);
|
|
$client->setOrganizationalUnit($this->organizationalUnit->getEntity());
|
|
$client->setHardwareProfile($this->hardwareProfile->getEntity());
|
|
$client->setNetDriver($this->netDriver);
|
|
$client->setMac($this->mac);
|
|
$client->setIp($this->ip);
|
|
$client->setStatus($this->status);
|
|
|
|
return $client;
|
|
}
|
|
} |