diff --git a/migrations/Version20240812135824.php b/migrations/Version20240812135824.php new file mode 100644 index 0000000..5bd9784 --- /dev/null +++ b/migrations/Version20240812135824.php @@ -0,0 +1,43 @@ +addSql('CREATE TABLE og_repository (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, ip_address VARCHAR(255) NOT NULL, description VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_2E0FDA37D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE client ADD repository_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C744045550C9D4F7 FOREIGN KEY (repository_id) REFERENCES og_repository (id)'); + $this->addSql('CREATE INDEX IDX_C744045550C9D4F7 ON client (repository_id)'); + $this->addSql('ALTER TABLE network_settings ADD repository_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B5450C9D4F7 FOREIGN KEY (repository_id) REFERENCES og_repository (id)'); + $this->addSql('CREATE INDEX IDX_48869B5450C9D4F7 ON network_settings (repository_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C744045550C9D4F7'); + $this->addSql('ALTER TABLE network_settings DROP FOREIGN KEY FK_48869B5450C9D4F7'); + $this->addSql('DROP TABLE og_repository'); + $this->addSql('DROP INDEX IDX_48869B5450C9D4F7 ON network_settings'); + $this->addSql('ALTER TABLE network_settings DROP repository_id'); + $this->addSql('DROP INDEX IDX_C744045550C9D4F7 ON client'); + $this->addSql('ALTER TABLE client DROP repository_id'); + } +} diff --git a/src/Controller/OgBoot/PxeBootFile/GetAction.php b/src/Controller/OgBoot/PxeBootFile/GetAction.php new file mode 100644 index 0000000..766da38 --- /dev/null +++ b/src/Controller/OgBoot/PxeBootFile/GetAction.php @@ -0,0 +1,43 @@ +request('GET', $this->ogBootApiUrl.'/ogboot/v1/pxes/'.$data->getName(), [ + 'headers' => [ + 'accept' => 'application/json', + ], + ]); + } catch (TransportExceptionInterface $e) { + return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); + } + + $data = json_decode($response->getContent(), true); + + return new JsonResponse( data: $data, status: Response::HTTP_OK); + } +} \ No newline at end of file diff --git a/src/Dto/Input/ClientInput.php b/src/Dto/Input/ClientInput.php index ec4a2c2..065e7a2 100644 --- a/src/Dto/Input/ClientInput.php +++ b/src/Dto/Input/ClientInput.php @@ -7,6 +7,7 @@ use App\Dto\Output\HardwareProfileOutput; use App\Dto\Output\MenuOutput; use App\Dto\Output\OrganizationalUnitOutput; use App\Entity\Client; +use App\Entity\OgRepository; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; @@ -77,10 +78,16 @@ final class ClientInput #[Groups(['client:write'])] #[ApiProperty( - description: 'descriptions.client.validation' + description: 'La posición del cliente dentro del aula' )] public ?array $position = ['x' => 0, 'y' => 0]; + #[Groups(['client:write'])] + #[ApiProperty( + description: 'descriptions.client.validation' + )] + public ?OgRepository $repository = null; + public function __construct(?Client $client = null) { if (!$client) { diff --git a/src/Entity/Client.php b/src/Entity/Client.php index 80ef646..82f5cac 100644 --- a/src/Entity/Client.php +++ b/src/Entity/Client.php @@ -60,6 +60,9 @@ class Client extends AbstractEntity #[ORM\ManyToOne(inversedBy: 'clients')] private ?PxeBootFile $pxeBootFile = null; + #[ORM\ManyToOne(inversedBy: 'clients')] + private ?OgRepository $repository = null; + public function __construct() { parent::__construct(); @@ -239,4 +242,16 @@ class Client extends AbstractEntity return $this; } + + public function getRepository(): ?OgRepository + { + return $this->repository; + } + + public function setRepository(?OgRepository $repository): static + { + $this->repository = $repository; + + return $this; + } } diff --git a/src/Entity/NetworkSettings.php b/src/Entity/NetworkSettings.php index faf7002..de3b9c9 100644 --- a/src/Entity/NetworkSettings.php +++ b/src/Entity/NetworkSettings.php @@ -60,6 +60,9 @@ class NetworkSettings extends AbstractEntity #[ORM\Column(nullable: true)] private ?bool $validation = null; + #[ORM\ManyToOne] + private ?OgRepository $repository = null; + public function __construct() { parent::__construct(); @@ -268,4 +271,16 @@ class NetworkSettings extends AbstractEntity return $this; } + + public function getRepository(): ?OgRepository + { + return $this->repository; + } + + public function setRepository(?OgRepository $repository): static + { + $this->repository = $repository; + + return $this; + } } diff --git a/src/Entity/OgRepository.php b/src/Entity/OgRepository.php new file mode 100644 index 0000000..9aaaa74 --- /dev/null +++ b/src/Entity/OgRepository.php @@ -0,0 +1,86 @@ + + */ + #[ORM\OneToMany(mappedBy: 'repository', targetEntity: Client::class)] + private Collection $clients; + + public function __construct() + { + parent::__construct(); + $this->clients = new ArrayCollection(); + } + + public function getIpAddress(): ?string + { + return $this->ipAddress; + } + + public function setIpAddress(string $ipAddress): static + { + $this->ipAddress = $ipAddress; + + return $this; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function setDescription(?string $description): static + { + $this->description = $description; + + return $this; + } + + /** + * @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->setRepository($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->getRepository() === $this) { + $client->setRepository(null); + } + } + + return $this; + } +} diff --git a/src/Repository/OgRepositoryRepository.php b/src/Repository/OgRepositoryRepository.php new file mode 100644 index 0000000..0db2b01 --- /dev/null +++ b/src/Repository/OgRepositoryRepository.php @@ -0,0 +1,18 @@ + + */ +class OgRepositoryRepository extends AbstractRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, self::class); + } +}