refs #617. DHCP new changes in API
parent
e7b303cc11
commit
2cf6730fbb
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20240902124157 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE network_settings ADD next_server VARCHAR(255) DEFAULT NULL, ADD boot_file_name VARCHAR(255) DEFAULT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE network_settings ADD og_live_id INT DEFAULT NULL, DROP next_server, DROP boot_file_name');
|
||||
$this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B54F7E54CF3 FOREIGN KEY (og_live_id) REFERENCES og_live (id)');
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20240903081001 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE organizational_unit ADD subnet_id INT DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE organizational_unit ADD CONSTRAINT FK_749AEB2DC9CF9478 FOREIGN KEY (subnet_id) REFERENCES subnet (id)');
|
||||
$this->addSql('CREATE INDEX IDX_749AEB2DC9CF9478 ON organizational_unit (subnet_id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE organizational_unit DROP FOREIGN KEY FK_749AEB2DC9CF9478');
|
||||
$this->addSql('DROP INDEX IDX_749AEB2DC9CF9478 ON organizational_unit');
|
||||
$this->addSql('ALTER TABLE organizational_unit DROP subnet_id');
|
||||
}
|
||||
}
|
|
@ -15,6 +15,12 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
|
||||
class NetworkSettingsInput
|
||||
{
|
||||
#[Groups(['organizational-unit:write'])]
|
||||
public ?string $nextServer = null;
|
||||
|
||||
#[Groups(['organizational-unit:write'])]
|
||||
public ?string $bootFileName = null;
|
||||
|
||||
#[Groups(['organizational-unit:write'])]
|
||||
public ?string $proxy = null;
|
||||
|
||||
|
@ -71,6 +77,8 @@ class NetworkSettingsInput
|
|||
return;
|
||||
}
|
||||
|
||||
$this->nextServer = $networkSettings->getNextServer();
|
||||
$this->bootFileName = $networkSettings->getBootFileName();
|
||||
$this->proxy = $networkSettings->getProxy();
|
||||
$this->dns = $networkSettings->getDns();
|
||||
$this->netmask = $networkSettings->getNetmask();
|
||||
|
@ -100,6 +108,8 @@ class NetworkSettingsInput
|
|||
$networkSettings = new NetworkSettings();
|
||||
}
|
||||
|
||||
$networkSettings->setNextServer($this->nextServer);
|
||||
$networkSettings->setBootFileName($this->bootFileName);
|
||||
$networkSettings->setProxy($this->proxy);
|
||||
$networkSettings->setDns($this->dns);
|
||||
$networkSettings->setNetmask($this->netmask);
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Dto\Input;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use App\Dto\Output\OrganizationalUnitOutput;
|
||||
use App\Dto\Output\SubnetOutput;
|
||||
use App\Entity\Subnet;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
@ -34,6 +36,13 @@ final class SubnetInput
|
|||
#[ApiProperty(description: 'The boot file name of the subnet', example: "")]
|
||||
public ?string $bootFileName = null;
|
||||
|
||||
/**
|
||||
* @var OrganizationalUnitOutput[]
|
||||
*/
|
||||
#[Groups('user:write')]
|
||||
#[ApiProperty(readableLink: false, writableLink: false)]
|
||||
public array $organizationalUnits = [];
|
||||
|
||||
public function __construct(?Subnet $subnet = null)
|
||||
{
|
||||
if (!$subnet) {
|
||||
|
@ -45,6 +54,12 @@ final class SubnetInput
|
|||
$this->ipAddress = $subnet->getIpAddress();
|
||||
$this->nextServer = $subnet->getNextServer();
|
||||
$this->bootFileName = $subnet->getBootFileName();
|
||||
|
||||
if ($subnet->getOrganizationalUnits()) {
|
||||
foreach ($subnet->getOrganizationalUnits() as $organizationalUnit) {
|
||||
$this->organizationalUnits[] = new OrganizationalUnitOutput($organizationalUnit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function createOrUpdateEntity(?Subnet $subnet = null): Subnet
|
||||
|
@ -59,6 +74,11 @@ final class SubnetInput
|
|||
$subnet->setNextServer($this->nextServer);
|
||||
$subnet->setBootFileName($this->bootFileName);
|
||||
|
||||
foreach ($this->organizationalUnits as $organizationalUnit) {
|
||||
$organizationalUnitToAdd[] = $organizationalUnit->getEntity();
|
||||
}
|
||||
$subnet->setOrganizationalUnits($organizationalUnitToAdd ?? [] );
|
||||
|
||||
return $subnet;
|
||||
}
|
||||
}
|
|
@ -9,6 +9,12 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
|||
#[Get(shortName: 'NetworkSettings')]
|
||||
final class NetworkSettingsOutput extends AbstractOutput
|
||||
{
|
||||
#[Groups(['network-settings:read', "organizational-unit:read", "client:read"])]
|
||||
public ?string $nextServer = null;
|
||||
|
||||
#[Groups(['network-settings:read', "organizational-unit:read", "client:read"])]
|
||||
public ?string $bootFileName = null;
|
||||
|
||||
#[Groups(['network-settings:read', "organizational-unit:read", "client:read"])]
|
||||
public ?string $proxy = null;
|
||||
|
||||
|
@ -61,6 +67,8 @@ final class NetworkSettingsOutput extends AbstractOutput
|
|||
{
|
||||
parent::__construct($networkSettings);
|
||||
|
||||
$this->nextServer = $networkSettings->getNextServer();
|
||||
$this->bootFileName = $networkSettings->getBootFileName();
|
||||
$this->proxy = $networkSettings->getProxy();
|
||||
$this->dns = $networkSettings->getDns();
|
||||
$this->netmask = $networkSettings->getNetmask();
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Dto\Output;
|
|||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Entity\OrganizationalUnit;
|
||||
use App\Entity\Subnet;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
|
@ -25,6 +26,9 @@ final class SubnetOutput extends AbstractOutput
|
|||
#[Groups(['subnet:read'])]
|
||||
public string $bootFileName;
|
||||
|
||||
#[Groups(['subnet:read'])]
|
||||
public array $organizationalUnits;
|
||||
|
||||
#[Groups(['subnet:read'])]
|
||||
public \DateTime $createdAt;
|
||||
|
||||
|
@ -40,6 +44,12 @@ final class SubnetOutput extends AbstractOutput
|
|||
$this->ipAddress = $subnet->getIpAddress();
|
||||
$this->nextServer = $subnet->getNextServer();
|
||||
$this->bootFileName = $subnet->getBootFileName();
|
||||
|
||||
|
||||
$this->organizationalUnits = $subnet->getOrganizationalUnits()->map(
|
||||
fn(OrganizationalUnit $organizationalUnit) => new OrganizationalUnitOutput($organizationalUnit)
|
||||
)->toArray();
|
||||
|
||||
$this->createdAt = $subnet->getCreatedAt();
|
||||
$this->createdBy = $subnet->getCreatedBy();
|
||||
}
|
||||
|
|
|
@ -10,6 +10,12 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
#[ORM\Entity(repositoryClass: NetworkSettingsRepository::class)]
|
||||
class NetworkSettings extends AbstractEntity
|
||||
{
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $nextServer = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $bootFileName = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $proxy = null;
|
||||
|
||||
|
@ -69,9 +75,26 @@ class NetworkSettings extends AbstractEntity
|
|||
$this->organizationalUnits = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
public function getNextServer(): ?string
|
||||
{
|
||||
return $this->id;
|
||||
return $this->nextServer;
|
||||
}
|
||||
|
||||
public function setNextServer(?string $nextServer): void
|
||||
{
|
||||
$this->nextServer = $nextServer;
|
||||
}
|
||||
|
||||
public function getBootFileName(): ?string
|
||||
{
|
||||
return $this->bootFileName;
|
||||
}
|
||||
|
||||
public function setBootFileName(?string $bootFileName): static
|
||||
{
|
||||
$this->bootFileName = $bootFileName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProxy(): ?string
|
||||
|
|
|
@ -84,6 +84,9 @@ class OrganizationalUnit extends AbstractEntity
|
|||
#[ORM\OneToMany(mappedBy: 'organizationalUnit', targetEntity: SoftwareProfile::class)]
|
||||
private Collection $softwareProfiles;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'organizationalUnits')]
|
||||
private ?Subnet $subnet = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
@ -368,4 +371,16 @@ class OrganizationalUnit extends AbstractEntity
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSubnet(): ?Subnet
|
||||
{
|
||||
return $this->subnet;
|
||||
}
|
||||
|
||||
public function setSubnet(?Subnet $subnet): static
|
||||
{
|
||||
$this->subnet = $subnet;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Entity;
|
||||
|
||||
use App\Repository\SubnetRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: SubnetRepository::class)]
|
||||
|
@ -22,6 +24,18 @@ class Subnet extends AbstractEntity
|
|||
#[ORM\Column(length: 255)]
|
||||
private ?string $bootFileName = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, OrganizationalUnit>
|
||||
*/
|
||||
#[ORM\OneToMany(mappedBy: 'subnet', targetEntity: OrganizationalUnit::class)]
|
||||
private Collection $organizationalUnits;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->organizationalUnits = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getNetmask(): ?string
|
||||
{
|
||||
return $this->netmask;
|
||||
|
@ -69,4 +83,45 @@ class Subnet extends AbstractEntity
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, OrganizationalUnit>
|
||||
*/
|
||||
public function getOrganizationalUnits(): Collection
|
||||
{
|
||||
return $this->organizationalUnits;
|
||||
}
|
||||
|
||||
public function setOrganizationalUnits(array $organizationalUnits): static
|
||||
{
|
||||
$this->organizationalUnits->clear();
|
||||
|
||||
foreach ($organizationalUnits as $organizationalUnit){
|
||||
$this->addOrganizationalUnit($organizationalUnit);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addOrganizationalUnit(OrganizationalUnit $organizationalUnit): static
|
||||
{
|
||||
if (!$this->organizationalUnits->contains($organizationalUnit)) {
|
||||
$this->organizationalUnits->add($organizationalUnit);
|
||||
$organizationalUnit->setSubnet($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeOrganizationalUnit(OrganizationalUnit $organizationalUnit): static
|
||||
{
|
||||
if ($this->organizationalUnits->removeElement($organizationalUnit)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($organizationalUnit->getSubnet() === $this) {
|
||||
$organizationalUnit->setSubnet(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue