refs #1083. New entity ImageRepository

pull/13/head
Manuel Aranda Rosales 2024-10-29 16:56:23 +01:00
parent 45fd79d2bc
commit 5dc8ffae8c
10 changed files with 315 additions and 13 deletions

View File

@ -0,0 +1,32 @@
resources:
App\Entity\Repository:
processor: App\State\Processor\RepositoryProcessor
input: App\Dto\Input\RepositoryInput
output: App\Dto\Output\RepositoryOutput
orderBy:
RepositoryNumber: 'ASC'
normalizationContext:
groups: ['default', 'repository:read']
denormalizationContext:
groups: ['repository:write']
operations:
ApiPlatform\Metadata\GetCollection:
provider: App\State\Provider\RepositoryProvider
filters:
- 'api_platform.filter.repository.order'
- 'api_platform.filter.repository.search'
ApiPlatform\Metadata\Get:
provider: App\State\Provider\RepositoryProvider
ApiPlatform\Metadata\Put:
provider: App\State\Provider\RepositoryProvider
ApiPlatform\Metadata\Patch:
provider: App\State\Provider\RepositoryProvider
ApiPlatform\Metadata\Post: ~
ApiPlatform\Metadata\Delete: ~
properties:
App\Entity\Repository:
id:
identifier: false
uuid:
identifier: true

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 Version20241029112630 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('CREATE TABLE image_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 VARCHAR(255) NOT NULL, comments VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_302040FBD17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE image_repository');
}
}

View File

@ -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 Version20241029145213 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 image ADD repository_id INT NOT NULL');
$this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F50C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id)');
$this->addSql('CREATE INDEX IDX_C53D045F50C9D4F7 ON image (repository_id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045F50C9D4F7');
$this->addSql('DROP INDEX IDX_C53D045F50C9D4F7 ON image');
$this->addSql('ALTER TABLE image DROP repository_id');
}
}

View File

@ -0,0 +1,88 @@
<?php
namespace App\Dto\Input;
use ApiPlatform\Metadata\ApiProperty;
use App\Dto\Output\ClientOutput;
use App\Dto\Output\ImageOutput;
use App\Dto\Output\OperativeSystemOutput;
use App\Dto\Output\OrganizationalUnitOutput;
use App\Entity\HardwareProfile;
use App\Entity\Menu;
use App\Entity\Partition;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
final class RepositoryInput
{
#[Groups(['partition:write'])]
#[ApiProperty(description: 'The disk number of the partition', example: 1)]
public ?int $diskNumber = null;
#[Groups(['partition:write'])]
#[ApiProperty(description: 'The number of the partition', example: 1)]
public ?int $partitionNumber = null;
#[Groups(['partition:write'])]
#[ApiProperty(description: 'The code of the partition', example: "code")]
public ?string $partitionCode = null;
#[Assert\NotNull()]
#[Groups(['partition:write'])]
#[ApiProperty(description: 'The size of the partition', example: 100)]
public ?int $size = null;
public function __construct(?Repository $partition = null)
{
if (!$partition) {
return;
}
$this->diskNumber = $partition->getDiskNumber();
$this->partitionNumber = $partition->getPartitionNumber();
$this->partitionCode = $partition->getPartitionCode();
$this->size = $partition->getSize();
$this->cacheContent = $partition->getCacheContent();
$this->filesystem = $partition->getFilesystem();
if ($partition->getOperativeSystem()) {
$this->operativeSystem = new OperativeSystemOutput($partition->getOperativeSystem());
}
if ($partition->getClient()) {
$this->client = new ClientOutput($partition->getClient());
}
$this->memoryUsage = $partition->getMemoryUsage();
if ($partition->getImage()) {
$this->image = new ImageOutput($partition->getImage());
}
}
public function createOrUpdateEntity(?Partition $partition = null): Partition
{
if (!$partition) {
$partition = new Partition();
}
$partition->setDiskNumber($this->diskNumber);
$partition->setPartitionNumber($this->partitionNumber);
$partition->setPartitionCode($this->partitionCode);
$partition->setSize($this->size * 1024);
$partition->setCacheContent($this->cacheContent);
$partition->setFilesystem($this->filesystem);
if ($this->operativeSystem) {
$partition->setOperativeSystem($this->operativeSystem->getEntity());
}
$partition->setClient($this->client->getEntity());
$partition->setMemoryUsage($this->memoryUsage * 100);
if ($this->image) {
$partition->setImage($this->image->getEntity());
}
return $partition;
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace App\Dto\Output;
class ImageRepositoryOutput
{
}

View File

@ -46,6 +46,10 @@ class Image extends AbstractEntity
#[ORM\Column]
private ?bool $remotePc = null;
#[ORM\ManyToOne(inversedBy: 'images')]
#[ORM\JoinColumn(nullable: false)]
private ?\App\Entity\ImageRepository $repository = null;
public function __construct()
{
parent::__construct();
@ -189,4 +193,16 @@ class Image extends AbstractEntity
return $this;
}
public function getRepository(): ?\App\Entity\ImageRepository
{
return $this->repository;
}
public function setRepository(?\App\Entity\ImageRepository $repository): static
{
$this->repository = $repository;
return $this;
}
}

View File

@ -0,0 +1,86 @@
<?php
namespace App\Entity;
use App\Repository\ImageRepositoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ImageRepositoryRepository::class)]
class ImageRepository extends AbstractEntity
{
use NameableTrait;
#[ORM\Column(length: 255)]
private ?string $ip = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $comments = null;
/**
* @var Collection<int, Image>
*/
#[ORM\OneToMany(mappedBy: 'repository', targetEntity: Image::class)]
private Collection $images;
public function __construct()
{
parent::__construct();
$this->images = new ArrayCollection();
}
public function getIp(): ?string
{
return $this->ip;
}
public function setIp(string $ip): static
{
$this->ip = $ip;
return $this;
}
public function getComments(): ?string
{
return $this->comments;
}
public function setComments(?string $comments): static
{
$this->comments = $comments;
return $this;
}
/**
* @return Collection<int, Image>
*/
public function getImages(): Collection
{
return $this->images;
}
public function addImage(Image $image): static
{
if (!$this->images->contains($image)) {
$this->images->add($image);
$image->setRepository($this);
}
return $this;
}
public function removeImage(Image $image): static
{
if ($this->images->removeElement($image)) {
// set the owning side to null (unless already changed)
if ($image->getRepository() === $this) {
$image->setRepository(null);
}
}
return $this;
}
}

View File

@ -2,17 +2,7 @@
namespace App\Repository;
use App\Entity\Image;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Image>
*/
class ImageRepository extends AbstractRepository
class ImageRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Image::class);
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace App\State\Processor;
class ImageRepositoryProcessor
{
}

View File

@ -0,0 +1,8 @@
<?php
namespace App\State\Provider;
class ImageRepositoryProvider
{
}