From fa2ee36cb9263c3604401d461167e8bec8c56423 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 20 Aug 2024 08:44:28 +0200 Subject: [PATCH] refs #632. Create new fields and updated API --- migrations/Version20240820063513.php | 41 +++++++++++++++++++ migrations/Version20240820064106.php | 31 ++++++++++++++ src/Dto/Input/ClientInput.php | 12 ++++++ src/Dto/Input/NetworkSettingsInput.php | 13 ++++++ src/Dto/Output/ClientOutput.php | 5 +++ src/Dto/Output/NetworkSettingsOutput.php | 7 ++++ src/Dto/Output/OgLiveOutput.php | 4 +- src/Entity/Client.php | 15 +++++++ src/Entity/NetworkSettings.php | 15 +++++++ src/Entity/OgLive.php | 52 +++++++++++++++++++++--- 10 files changed, 188 insertions(+), 7 deletions(-) create mode 100644 migrations/Version20240820063513.php create mode 100644 migrations/Version20240820064106.php diff --git a/migrations/Version20240820063513.php b/migrations/Version20240820063513.php new file mode 100644 index 0000000..42803dd --- /dev/null +++ b/migrations/Version20240820063513.php @@ -0,0 +1,41 @@ +addSql('ALTER TABLE client ADD og_live_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455F7E54CF3 FOREIGN KEY (og_live_id) REFERENCES og_live (id)'); + $this->addSql('CREATE INDEX IDX_C7440455F7E54CF3 ON client (og_live_id)'); + $this->addSql('ALTER TABLE network_settings ADD og_live_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B54F7E54CF3 FOREIGN KEY (og_live_id) REFERENCES og_live (id)'); + $this->addSql('CREATE INDEX IDX_48869B54F7E54CF3 ON network_settings (og_live_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE network_settings DROP FOREIGN KEY FK_48869B54F7E54CF3'); + $this->addSql('DROP INDEX IDX_48869B54F7E54CF3 ON network_settings'); + $this->addSql('ALTER TABLE network_settings DROP og_live_id'); + $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455F7E54CF3'); + $this->addSql('DROP INDEX IDX_C7440455F7E54CF3 ON client'); + $this->addSql('ALTER TABLE client DROP og_live_id'); + } +} diff --git a/migrations/Version20240820064106.php b/migrations/Version20240820064106.php new file mode 100644 index 0000000..2e387f6 --- /dev/null +++ b/migrations/Version20240820064106.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE og_live CHANGE `default` is_default TINYINT(1) DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE og_live CHANGE is_default `default` TINYINT(1) DEFAULT NULL'); + } +} diff --git a/src/Dto/Input/ClientInput.php b/src/Dto/Input/ClientInput.php index 065e7a2..fbc5bf9 100644 --- a/src/Dto/Input/ClientInput.php +++ b/src/Dto/Input/ClientInput.php @@ -5,6 +5,7 @@ namespace App\Dto\Input; use ApiPlatform\Metadata\ApiProperty; use App\Dto\Output\HardwareProfileOutput; use App\Dto\Output\MenuOutput; +use App\Dto\Output\OgLiveOutput; use App\Dto\Output\OrganizationalUnitOutput; use App\Entity\Client; use App\Entity\OgRepository; @@ -76,6 +77,12 @@ final class ClientInput )] public ?HardwareProfileOutput $hardwareProfile = null; + #[Groups(['client:write'])] + #[ApiProperty( + description: 'OgLive del cliente' + )] + public ?OgLiveOutput $ogLive = null; + #[Groups(['client:write'])] #[ApiProperty( description: 'La posición del cliente dentro del aula' @@ -107,6 +114,10 @@ final class ClientInput $this->menu = new MenuOutput($client->getMenu()); } + if ($client->getOgLive()) { + $this->ogLive = new OgLiveOutput($client->getOgLive()); + } + if ($client->getHardwareProfile()) { $this->hardwareProfile = new HardwareProfileOutput($client->getHardwareProfile()); } @@ -126,6 +137,7 @@ final class ClientInput $client->setMac($this->mac); $client->setIp($this->ip); $client->setMenu($this->menu?->getEntity()); + $client->setOgLive($this->ogLive?->getEntity()); $client->setHardwareProfile($this->hardwareProfile?->getEntity()); $client->setPosition($this->position); diff --git a/src/Dto/Input/NetworkSettingsInput.php b/src/Dto/Input/NetworkSettingsInput.php index e32c732..899a495 100644 --- a/src/Dto/Input/NetworkSettingsInput.php +++ b/src/Dto/Input/NetworkSettingsInput.php @@ -2,8 +2,10 @@ namespace App\Dto\Input; +use ApiPlatform\Metadata\ApiProperty; use App\Dto\Output\HardwareProfileOutput; use App\Dto\Output\MenuOutput; +use App\Dto\Output\OgLiveOutput; use App\Entity\HardwareProfile; use App\Entity\Menu; use App\Entity\NetworkSettings; @@ -62,6 +64,9 @@ class NetworkSettingsInput #[Groups(['organizational-unit:write'])] public ?HardwareProfileOutput $hardwareProfile = null; + #[Groups(['organizational-unit:write'])] + public ?OgLiveOutput $ogLive = null; + #[Groups(['organizational-unit:write'])] public ?bool $validation = null; @@ -91,6 +96,10 @@ class NetworkSettingsInput $this->hardwareProfile = new HardwareProfileOutput($networkSettings->getHardwareProfile()); } + if ($networkSettings->getOgLive()) { + $this->ogLive = new OgLiveOutput($networkSettings->getOgLive()); + } + $this->validation = $networkSettings->getValidation(); } @@ -120,6 +129,10 @@ class NetworkSettingsInput $networkSettings->setHardwareProfile($this->hardwareProfile->getEntity()); } + if ($this->ogLive) { + $networkSettings->setOgLive($this->ogLive->getEntity()); + } + $networkSettings->setValidation($this->validation); return $networkSettings; diff --git a/src/Dto/Output/ClientOutput.php b/src/Dto/Output/ClientOutput.php index 97c0b5a..2fe5ff3 100644 --- a/src/Dto/Output/ClientOutput.php +++ b/src/Dto/Output/ClientOutput.php @@ -48,6 +48,10 @@ final class ClientOutput extends AbstractOutput #[ApiProperty(readableLink: true )] public ?HardwareProfileOutput $hardwareProfile = null; + #[Groups(['client:read'])] + #[ApiProperty(readableLink: true )] + public ?OgLiveOutput $ogLive = null; + #[Groups(['client:read'])] public ?array $position = ['x' => 0, 'y' => 0]; @@ -79,6 +83,7 @@ final class ClientOutput extends AbstractOutput $this->menu = $client->getMenu() ? new MenuOutput($client->getMenu()) : null; $this->position = $client->getPosition(); $this->hardwareProfile = $client->getHardwareProfile() ? new HardwareProfileOutput($client->getHardwareProfile()) : null; + $this->ogLive = $client->getOgLive() ? new OgLiveOutput($client->getOgLive()) : null; $this->createdAt = $client->getCreatedAt(); $this->createdBy = $client->getCreatedBy(); } diff --git a/src/Dto/Output/NetworkSettingsOutput.php b/src/Dto/Output/NetworkSettingsOutput.php index 9c0b66d..1b90e03 100644 --- a/src/Dto/Output/NetworkSettingsOutput.php +++ b/src/Dto/Output/NetworkSettingsOutput.php @@ -48,6 +48,9 @@ final class NetworkSettingsOutput extends AbstractOutput #[Groups(['network-settings:read', "organizational-unit:read", "client:read"])] public ?HardwareProfileOutput $hardwareProfile = null; + #[Groups(['network-settings:read', "organizational-unit:read", "client:read"])] + public ?OgLiveOutput $ogLive = null; + #[Groups(['network-settings:read', "organizational-unit:read", "client:read"])] public ?bool $validation = null; @@ -81,6 +84,10 @@ final class NetworkSettingsOutput extends AbstractOutput $this->hardwareProfile = new HardwareProfileOutput($networkSettings->getHardwareProfile()); } + if ($networkSettings->getOgLive()) { + $this->ogLive = new OgLiveOutput($networkSettings->getOgLive()); + } + $this->validation = $networkSettings->getValidation(); $this->createdAt = $networkSettings->getCreatedAt(); $this->createdBy = $networkSettings->getCreatedBy(); diff --git a/src/Dto/Output/OgLiveOutput.php b/src/Dto/Output/OgLiveOutput.php index 28e117e..bc9fc32 100644 --- a/src/Dto/Output/OgLiveOutput.php +++ b/src/Dto/Output/OgLiveOutput.php @@ -20,7 +20,7 @@ final class OgLiveOutput extends AbstractOutput public ?bool $installed = false; #[Groups(['og-live:read'])] - public ?bool $default = false; + public ?bool $isDefault = false; #[Groups(['og-live:read'])] public ?string $downloadUrl = ''; @@ -38,7 +38,7 @@ final class OgLiveOutput extends AbstractOutput $this->name = $ogLive->getName(); $this->synchronized = $ogLive->isSynchronized(); $this->installed = $ogLive->isInstalled(); - $this->default = $ogLive->isDefault(); + $this->isDefault = $ogLive->getIsDefault(); $this->downloadUrl = $ogLive->getDownloadUrl(); $this->createdAt = $ogLive->getCreatedAt(); $this->createdBy = $ogLive->getCreatedBy(); diff --git a/src/Entity/Client.php b/src/Entity/Client.php index 82f5cac..f0aa640 100644 --- a/src/Entity/Client.php +++ b/src/Entity/Client.php @@ -63,6 +63,9 @@ class Client extends AbstractEntity #[ORM\ManyToOne(inversedBy: 'clients')] private ?OgRepository $repository = null; + #[ORM\ManyToOne(inversedBy: 'clients')] + private ?OgLive $ogLive = null; + public function __construct() { parent::__construct(); @@ -254,4 +257,16 @@ class Client extends AbstractEntity return $this; } + + public function getOgLive(): ?OgLive + { + return $this->ogLive; + } + + public function setOgLive(?OgLive $ogLive): static + { + $this->ogLive = $ogLive; + + return $this; + } } diff --git a/src/Entity/NetworkSettings.php b/src/Entity/NetworkSettings.php index de3b9c9..586386a 100644 --- a/src/Entity/NetworkSettings.php +++ b/src/Entity/NetworkSettings.php @@ -63,6 +63,9 @@ class NetworkSettings extends AbstractEntity #[ORM\ManyToOne] private ?OgRepository $repository = null; + #[ORM\ManyToOne] + private ?OgLive $ogLive = null; + public function __construct() { parent::__construct(); @@ -283,4 +286,16 @@ class NetworkSettings extends AbstractEntity return $this; } + + public function getOgLive(): ?OgLive + { + return $this->ogLive; + } + + public function setOgLive(?OgLive $ogLive): static + { + $this->ogLive = $ogLive; + + return $this; + } } diff --git a/src/Entity/OgLive.php b/src/Entity/OgLive.php index 2ecb106..4375882 100644 --- a/src/Entity/OgLive.php +++ b/src/Entity/OgLive.php @@ -3,6 +3,8 @@ namespace App\Entity; use App\Repository\OgLiveRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; @@ -42,7 +44,19 @@ class OgLive extends AbstractEntity private ?bool $installed = null; #[ORM\Column(nullable: true)] - private ?bool $default = null; + private ?bool $isDefault = null; + + /** + * @var Collection + */ + #[ORM\OneToMany(mappedBy: 'ogLive', targetEntity: Client::class)] + private Collection $clients; + + public function __construct() + { + parent::__construct(); + $this->clients = new ArrayCollection(); + } public function getDownloadUrl(): ?string { @@ -152,14 +166,42 @@ class OgLive extends AbstractEntity return $this; } - public function isDefault(): ?bool + public function getIsDefault(): ?bool { - return $this->default; + return $this->isDefault; } - public function setDefault(?bool $default): static + public function setIsDefault(?bool $isDefault): void { - $this->default = $default; + $this->isDefault = $isDefault; + } + + /** + * @return Collection + */ + public function getClients(): Collection + { + return $this->clients; + } + + public function addClient(Client $client): static + { + if (!$this->clients->contains($client)) { + $this->clients->add($client); + $client->setOgLive($this); + } + + return $this; + } + + public function removeClient(Client $client): static + { + if ($this->clients->removeElement($client)) { + // set the owning side to null (unless already changed) + if ($client->getOgLive() === $this) { + $client->setOgLive(null); + } + } return $this; }