From 5dc8ffae8cd8de8b50512a9c8e0ff1cf7008d766 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 29 Oct 2024 16:56:23 +0100 Subject: [PATCH] refs #1083. New entity ImageRepository --- config/api_platform/ImageRepository.yaml | 32 +++++++ migrations/Version20241029112630.php | 31 +++++++ migrations/Version20241029145213.php | 35 ++++++++ src/Dto/Input/ImageRepositoryInput.php | 88 +++++++++++++++++++ src/Dto/Output/ImageRepositoryOutput.php | 8 ++ src/Entity/Image.php | 16 ++++ src/Entity/ImageRepository.php | 86 ++++++++++++++++++ src/Repository/ImageRepository.php | 16 +--- .../Processor/ImageRepositoryProcessor.php | 8 ++ .../Provider/ImageRepositoryProvider.php | 8 ++ 10 files changed, 315 insertions(+), 13 deletions(-) create mode 100644 config/api_platform/ImageRepository.yaml create mode 100644 migrations/Version20241029112630.php create mode 100644 migrations/Version20241029145213.php create mode 100644 src/Dto/Input/ImageRepositoryInput.php create mode 100644 src/Dto/Output/ImageRepositoryOutput.php create mode 100644 src/Entity/ImageRepository.php create mode 100644 src/State/Processor/ImageRepositoryProcessor.php create mode 100644 src/State/Provider/ImageRepositoryProvider.php diff --git a/config/api_platform/ImageRepository.yaml b/config/api_platform/ImageRepository.yaml new file mode 100644 index 0000000..35d8d13 --- /dev/null +++ b/config/api_platform/ImageRepository.yaml @@ -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 \ No newline at end of file diff --git a/migrations/Version20241029112630.php b/migrations/Version20241029112630.php new file mode 100644 index 0000000..49f6115 --- /dev/null +++ b/migrations/Version20241029112630.php @@ -0,0 +1,31 @@ +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'); + } +} diff --git a/migrations/Version20241029145213.php b/migrations/Version20241029145213.php new file mode 100644 index 0000000..f0c874a --- /dev/null +++ b/migrations/Version20241029145213.php @@ -0,0 +1,35 @@ +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'); + } +} diff --git a/src/Dto/Input/ImageRepositoryInput.php b/src/Dto/Input/ImageRepositoryInput.php new file mode 100644 index 0000000..a7b4166 --- /dev/null +++ b/src/Dto/Input/ImageRepositoryInput.php @@ -0,0 +1,88 @@ +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; + } +} \ No newline at end of file diff --git a/src/Dto/Output/ImageRepositoryOutput.php b/src/Dto/Output/ImageRepositoryOutput.php new file mode 100644 index 0000000..1ede3f3 --- /dev/null +++ b/src/Dto/Output/ImageRepositoryOutput.php @@ -0,0 +1,8 @@ +repository; + } + + public function setRepository(?\App\Entity\ImageRepository $repository): static + { + $this->repository = $repository; + + return $this; + } } diff --git a/src/Entity/ImageRepository.php b/src/Entity/ImageRepository.php new file mode 100644 index 0000000..400890e --- /dev/null +++ b/src/Entity/ImageRepository.php @@ -0,0 +1,86 @@ + + */ + #[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 + */ + 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; + } +} diff --git a/src/Repository/ImageRepository.php b/src/Repository/ImageRepository.php index b20b95b..3e6ea6c 100644 --- a/src/Repository/ImageRepository.php +++ b/src/Repository/ImageRepository.php @@ -2,17 +2,7 @@ namespace App\Repository; -use App\Entity\Image; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; - -/** - * @extends ServiceEntityRepository - */ -class ImageRepository extends AbstractRepository +class ImageRepository { - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, Image::class); - } -} + +} \ No newline at end of file diff --git a/src/State/Processor/ImageRepositoryProcessor.php b/src/State/Processor/ImageRepositoryProcessor.php new file mode 100644 index 0000000..a3afb03 --- /dev/null +++ b/src/State/Processor/ImageRepositoryProcessor.php @@ -0,0 +1,8 @@ +