From eb647078cae8b24941526d0439a678cb3d238410 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Thu, 18 Jul 2024 09:00:20 +0200 Subject: [PATCH 1/2] refs #427. Added position into Client entity --- migrations/Version20240718064611.php | 31 ++++++++++++++++++++++++++++ src/Dto/Input/ClientInput.php | 13 +++++++----- src/Dto/Output/ClientOutput.php | 5 ++++- src/Entity/Client.php | 15 ++++++++++++++ 4 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 migrations/Version20240718064611.php diff --git a/migrations/Version20240718064611.php b/migrations/Version20240718064611.php new file mode 100644 index 0000000..fedb106 --- /dev/null +++ b/migrations/Version20240718064611.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE client ADD position JSON DEFAULT NULL COMMENT \'(DC2Type:json)\''); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE client DROP position'); + } +} diff --git a/src/Dto/Input/ClientInput.php b/src/Dto/Input/ClientInput.php index 2b124dd..df1a9c0 100644 --- a/src/Dto/Input/ClientInput.php +++ b/src/Dto/Input/ClientInput.php @@ -38,9 +38,6 @@ final class ClientInput #[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')] @@ -52,6 +49,12 @@ final class ClientInput #[Groups(['client:write'])] public ?HardwareProfileOutput $hardwareProfile = null; + #[Groups(['client:write'])] + #[ApiProperty( + description: 'descriptions.client.validation' + )] + public ?array $position = ['x' => 0, 'y' => 0]; + public function __construct(?Client $client = null) { if (!$client) { @@ -65,7 +68,7 @@ final class ClientInput $this->netDriver = $client->getNetDriver(); $this->mac = $client->getMac(); $this->ip = $client->getIp(); - $this->status = $client->getStatus(); + $this->position = $client->getPosition(); if ($client->getMenu()) { $this->menu = new MenuOutput($client->getMenu()); @@ -89,9 +92,9 @@ final class ClientInput $client->setNetDriver($this->netDriver); $client->setMac($this->mac); $client->setIp($this->ip); - $client->setStatus($this->status); $client->setMenu($this->menu?->getEntity()); $client->setHardwareProfile($this->hardwareProfile?->getEntity()); + $client->setPosition($this->position); return $client; } diff --git a/src/Dto/Output/ClientOutput.php b/src/Dto/Output/ClientOutput.php index a7b49e3..97c0b5a 100644 --- a/src/Dto/Output/ClientOutput.php +++ b/src/Dto/Output/ClientOutput.php @@ -48,6 +48,9 @@ final class ClientOutput extends AbstractOutput #[ApiProperty(readableLink: true )] public ?HardwareProfileOutput $hardwareProfile = null; + #[Groups(['client:read'])] + public ?array $position = ['x' => 0, 'y' => 0]; + #[Groups(['client:read'])] public \DateTime $createdAt; @@ -74,8 +77,8 @@ final class ClientOutput extends AbstractOutput )->toArray(); $this->menu = $client->getMenu() ? new MenuOutput($client->getMenu()) : null; + $this->position = $client->getPosition(); $this->hardwareProfile = $client->getHardwareProfile() ? new HardwareProfileOutput($client->getHardwareProfile()) : null; - $this->createdAt = $client->getCreatedAt(); $this->createdBy = $client->getCreatedBy(); } diff --git a/src/Entity/Client.php b/src/Entity/Client.php index 867fa3c..638ee48 100644 --- a/src/Entity/Client.php +++ b/src/Entity/Client.php @@ -54,6 +54,9 @@ class Client extends AbstractEntity #[ORM\Column(nullable: true)] private ?bool $validation = null; + #[ORM\Column(nullable: true)] + private ?array $position = ['x' => 0, 'y' => 0]; + public function __construct() { parent::__construct(); @@ -209,4 +212,16 @@ class Client extends AbstractEntity return $this; } + + public function getPosition(): ?array + { + return $this->position; + } + + public function setPosition(?array $position): static + { + $this->position = $position; + + return $this; + } } From 56003409e69f04bf9ffa1152deca9ba2682b6e06 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Mon, 29 Jul 2024 09:07:11 +0200 Subject: [PATCH 2/2] Change migration name --- src/Command/Migration/MigrateClientsCommand.php | 1 + .../Migration/MigrateHardwareAndHardwareProfileCommand.php | 2 +- .../Migration/MigrateSoftwareAndSoftwareProfileCommand.php | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Command/Migration/MigrateClientsCommand.php b/src/Command/Migration/MigrateClientsCommand.php index 1dc517c..b5117a4 100644 --- a/src/Command/Migration/MigrateClientsCommand.php +++ b/src/Command/Migration/MigrateClientsCommand.php @@ -62,6 +62,7 @@ class MigrateClientsCommand extends Command $clientEntity->setNetdriver($client['netdriver']); $clientEntity->setMac($client['mac']); $clientEntity->setIp($client['ip']); + $clientEntity->setPosition(['x' => 0, 'y' => 0]); } $migrationId = $client['ordenadores.grupoid'] === 0 ? $client['ordenadores.idaula'] : $client['ordenadores.grupoid']; diff --git a/src/Command/Migration/MigrateHardwareAndHardwareProfileCommand.php b/src/Command/Migration/MigrateHardwareAndHardwareProfileCommand.php index 0fdfd04..e71b417 100644 --- a/src/Command/Migration/MigrateHardwareAndHardwareProfileCommand.php +++ b/src/Command/Migration/MigrateHardwareAndHardwareProfileCommand.php @@ -14,7 +14,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -#[AsCommand(name: 'opengnsys:migrate-hardware-profile', description: 'Migrate hardware and hardware profile data')] +#[AsCommand(name: 'opengnsys:migration:hardware-profile', description: 'Migrate hardware and hardware profile data')] class MigrateHardwareAndHardwareProfileCommand extends Command { public function __construct( diff --git a/src/Command/Migration/MigrateSoftwareAndSoftwareProfileCommand.php b/src/Command/Migration/MigrateSoftwareAndSoftwareProfileCommand.php index 6daf869..667de64 100644 --- a/src/Command/Migration/MigrateSoftwareAndSoftwareProfileCommand.php +++ b/src/Command/Migration/MigrateSoftwareAndSoftwareProfileCommand.php @@ -13,7 +13,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -#[AsCommand(name: 'opengnsys:migrate-software-profile', description: 'Migrate software and software profile data')] +#[AsCommand(name: 'opengnsys:migration:software-profile', description: 'Migrate software and software profile data')] class MigrateSoftwareAndSoftwareProfileCommand extends Command { public function __construct(