65 lines
2.1 KiB
PHP
65 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Dto\Input;
|
|
|
|
use ApiPlatform\Metadata\ApiProperty;
|
|
use App\Entity\BootServer;
|
|
use Symfony\Component\Serializer\Annotation\Groups;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
final class BootServerInput
|
|
{
|
|
#[Assert\NotBlank(message: 'El nombre es obligatorio')]
|
|
#[Groups(['boot-server:write'])]
|
|
#[ApiProperty(description: 'The name of the boot server', example: "Servidor Boot 1")]
|
|
public ?string $name = null;
|
|
|
|
#[Assert\NotBlank(message: 'La IP es obligatoria')]
|
|
#[Assert\Ip(message: 'La IP no es válida')]
|
|
#[Groups(['boot-server:write'])]
|
|
#[ApiProperty(description: 'The IP address of the boot server', example: "192.168.1.10")]
|
|
public ?string $ip = null;
|
|
|
|
#[Assert\NotBlank(message: 'El puerto API es obligatorio')]
|
|
#[Groups(['boot-server:write'])]
|
|
#[ApiProperty(description: 'The API port of the boot server', example: 8082)]
|
|
public ?int $apiPort = 8082;
|
|
|
|
#[Assert\NotBlank(message: 'El puerto PXE es obligatorio')]
|
|
#[Groups(['boot-server:write'])]
|
|
#[ApiProperty(description: 'The PXE port of the boot server', example: 8082)]
|
|
public ?int $pxePort = 8082;
|
|
|
|
#[Groups(['boot-server:write'])]
|
|
#[ApiProperty(description: 'Comments or description for the boot server', example: "Servidor principal")]
|
|
public ?string $comments = null;
|
|
|
|
public function __construct(?BootServer $bootServer = null)
|
|
{
|
|
if (!$bootServer) {
|
|
return;
|
|
}
|
|
|
|
$this->name = $bootServer->getName();
|
|
$this->ip = $bootServer->getIp();
|
|
$this->apiPort = $bootServer->getApiPort();
|
|
$this->pxePort = $bootServer->getPxePort();
|
|
$this->comments = $bootServer->getComments();
|
|
}
|
|
|
|
public function createOrUpdateEntity(?BootServer $bootServer = null): BootServer
|
|
{
|
|
if (!$bootServer) {
|
|
$bootServer = new BootServer();
|
|
}
|
|
|
|
$bootServer->setName($this->name);
|
|
$bootServer->setIp($this->ip);
|
|
$bootServer->setApiPort((int)$this->apiPort);
|
|
$bootServer->setPxePort((int)$this->pxePort);
|
|
$bootServer->setComments($this->comments);
|
|
|
|
return $bootServer;
|
|
}
|
|
}
|