From 6d3604565b3ef83780c0eb1b4ad2143ed996e46b Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Mon, 3 Feb 2025 13:08:24 +0100 Subject: [PATCH] Updated repo deleted endpoint --- config/services/api_platform.yaml | 12 +++++++ migrations/Version20250203113932.php | 31 +++++++++++++++++++ .../Image/DeletePermanentAction.php | 6 +++- .../OgRepository/Image/DeleteTrashAction.php | 4 +++ src/Dto/Input/ImageInput.php | 7 +++++ src/Dto/Output/ImageOutput.php | 4 +++ src/Entity/Image.php | 15 +++++++++ 7 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 migrations/Version20250203113932.php diff --git a/config/services/api_platform.yaml b/config/services/api_platform.yaml index cc3b13b..528f3a1 100644 --- a/config/services/api_platform.yaml +++ b/config/services/api_platform.yaml @@ -178,6 +178,18 @@ services: arguments: [ { 'id': 'exact', 'name': 'partial', } ] tags: [ 'api_platform.filter' ] + api_platform.filter.repository.order: + parent: 'api_platform.doctrine.orm.order_filter' + arguments: + $properties: { 'id': ~, 'name': ~ } + $orderParameterName: 'order' + tags: [ 'api_platform.filter' ] + + api_platform.filter.repository.search: + parent: 'api_platform.doctrine.orm.search_filter' + arguments: [ { 'id': 'exact', 'name': 'partial'} ] + tags: [ 'api_platform.filter' ] + api_platform.filter.software.order: parent: 'api_platform.doctrine.orm.order_filter' arguments: diff --git a/migrations/Version20250203113932.php b/migrations/Version20250203113932.php new file mode 100644 index 0000000..f9e3246 --- /dev/null +++ b/migrations/Version20250203113932.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE image ADD is_global TINYINT(1) NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE image DROP is_global'); + } +} diff --git a/src/Controller/OgRepository/Image/DeletePermanentAction.php b/src/Controller/OgRepository/Image/DeletePermanentAction.php index de36d77..815f87e 100644 --- a/src/Controller/OgRepository/Image/DeletePermanentAction.php +++ b/src/Controller/OgRepository/Image/DeletePermanentAction.php @@ -29,7 +29,11 @@ class DeletePermanentAction extends AbstractOgRepositoryController throw new ValidatorException('Fullsum is required'); } - $content = $this->createRequest( 'DELETE', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/images/'.$data->getImageFullsum().'?method=trash'); + $this->logger->info('Deleting image', ['image' => $data->getName()]); + + $content = $this->createRequest( 'DELETE', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/images/'.$data->getImageFullsum().'?method=permanent'); + + $this->logger->info('Image deleted', ['image' => $data->getName()]); $this->entityManager->remove($data); $this->entityManager->flush(); diff --git a/src/Controller/OgRepository/Image/DeleteTrashAction.php b/src/Controller/OgRepository/Image/DeleteTrashAction.php index 80a5c76..e4635ee 100644 --- a/src/Controller/OgRepository/Image/DeleteTrashAction.php +++ b/src/Controller/OgRepository/Image/DeleteTrashAction.php @@ -30,8 +30,12 @@ class DeleteTrashAction extends AbstractOgRepositoryController throw new ValidatorException('Fullsum is required'); } + $this->logger->info('Deleting image', ['image' => $data->getName()]); + $content = $this->createRequest('DELETE', 'http://'.$data->getRepository()->getIp().':8006/ogrepository/v1/images/'.$data->getImageFullsum().'?method=trash'); + $this->logger->info('Image deleted', ['image' => $data->getName()]); + $data->setStatus(ImageStatus::TRASH); $this->entityManager->persist($data); $this->entityManager->flush(); diff --git a/src/Dto/Input/ImageInput.php b/src/Dto/Input/ImageInput.php index f270ac9..98c8e7b 100644 --- a/src/Dto/Input/ImageInput.php +++ b/src/Dto/Input/ImageInput.php @@ -66,6 +66,11 @@ final class ImageInput #[ApiProperty(description: 'The remote pc of the image')] public ?bool $remotePc = false; + #[Groups(['image:write'])] + #[ApiProperty(description: 'The global property of the image')] + public ?bool $isGlobal = false; + + public function __construct(?Image $image = null) { if (!$image) { @@ -77,6 +82,7 @@ final class ImageInput $this->comments = $image->getComments(); $this->type = $image->getType(); $this->remotePc = $image->isRemotePc(); + $this->isGlobal = $image->isGlobal(); $this->status = $image->getStatus(); if ($image->getSoftwareProfile()) { @@ -124,6 +130,7 @@ final class ImageInput } $image->setRemotePc($this->remotePc); + $image->setIsGlobal($this->isGlobal); $image->setCreated(false); $partitionInfo = []; diff --git a/src/Dto/Output/ImageOutput.php b/src/Dto/Output/ImageOutput.php index 235e88b..54ecbd0 100644 --- a/src/Dto/Output/ImageOutput.php +++ b/src/Dto/Output/ImageOutput.php @@ -36,6 +36,9 @@ final class ImageOutput extends AbstractOutput #[Groups(['image:read'])] public ?bool $remotePc = null; + #[Groups(['image:read'])] + public ?bool $isGlobal = null; + #[Groups(['image:read'])] public ?bool $created = null; @@ -78,6 +81,7 @@ final class ImageOutput extends AbstractOutput $this->imageRepository = $image->getRepository() ? new ImageRepositoryOutput($image->getRepository()) : null; $this->partitionInfo = json_decode($image->getPartitionInfo(), true); $this->remotePc = $image->isRemotePc(); + $this->isGlobal = $image->isGlobal(); $this->created = $image->isCreated(); $this->createdAt = $image->getCreatedAt(); $this->createdBy = $image->getCreatedBy(); diff --git a/src/Entity/Image.php b/src/Entity/Image.php index dc2c8ba..694102b 100644 --- a/src/Entity/Image.php +++ b/src/Entity/Image.php @@ -65,6 +65,9 @@ class Image extends AbstractEntity #[ORM\Column(length: 255)] private ?string $status = null; + #[ORM\Column] + private ?bool $isGlobal = null; + public function __construct() { @@ -262,4 +265,16 @@ class Image extends AbstractEntity return $this; } + + public function isGlobal(): ?bool + { + return $this->isGlobal; + } + + public function setIsGlobal(bool $isGlobal): static + { + $this->isGlobal = $isGlobal; + + return $this; + } }