refs #427. Added position into Client entity

feature/organizational-unit-hierarchy
Manuel Aranda Rosales 2024-07-18 09:00:20 +02:00
parent 14ace8fdbf
commit eb647078ca
4 changed files with 58 additions and 6 deletions

View File

@ -0,0 +1,31 @@
<?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 Version20240718064611 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 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');
}
}

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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;
}
}