From f8bfffebf110897b775bcbff8d7ca8f28af5ef40 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 15 Oct 2024 07:37:05 +0200 Subject: [PATCH] Updated partition and image input --- src/Dto/Input/ImageInput.php | 15 ++++++++++++--- src/Dto/Input/PartitionInput.php | 16 ++++++++++++---- src/Dto/Output/ImageOutput.php | 6 +++--- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/Dto/Input/ImageInput.php b/src/Dto/Input/ImageInput.php index 7bab121..badbdc0 100644 --- a/src/Dto/Input/ImageInput.php +++ b/src/Dto/Input/ImageInput.php @@ -72,9 +72,18 @@ final class ImageInput $this->revision = $image->getRevision(); $this->info = $image->getInfo(); $this->size = $image->getSize(); - $this->client = new ClientOutput($image->getClient()); - $this->softwareProfile = new SoftwareProfileOutput($image->getSoftwareProfile()); - $this->organizationalUnit = new OrganizationalUnitOutput($image->getOrganizationalUnit()); + + if ($image->getClient()) { + $this->client = new ClientOutput($image->getClient()); + } + + if ($image->getSoftwareProfile()) { + $this->softwareProfile = new SoftwareProfileOutput($image->getSoftwareProfile()); + } + + if ($image->getOrganizationalUnit()) { + $this->organizationalUnit = new OrganizationalUnitOutput($image->getOrganizationalUnit()); + } } public function createOrUpdateEntity(?Image $image = null): Image diff --git a/src/Dto/Input/PartitionInput.php b/src/Dto/Input/PartitionInput.php index c7477a5..7bc7538 100644 --- a/src/Dto/Input/PartitionInput.php +++ b/src/Dto/Input/PartitionInput.php @@ -40,7 +40,6 @@ final class PartitionInput #[ApiProperty(description: 'The filesystem of the partition', example: "filesystem")] public ?string $filesystem = null; - #[Assert\NotNull()] #[Groups(['partition:write'])] #[ApiProperty(description: 'The operative system name of the partition', example: "Ubuntu")] public ?OperativeSystemOutput $operativeSystem = null; @@ -71,10 +70,19 @@ final class PartitionInput $this->size = $partition->getSize(); $this->cacheContent = $partition->getCacheContent(); $this->filesystem = $partition->getFilesystem(); - $this->operativeSystem = new OperativeSystemOutput($partition->getOperativeSystem()); - $this->client = new ClientOutput($partition->getClient()); + + if ($partition->getOperativeSystem()) { + $this->operativeSystem = new OperativeSystemOutput($partition->getOperativeSystem()); + } + + if ($partition->getClient()) { + $this->client = new ClientOutput($partition->getClient()); + } $this->memoryUsage = $partition->getMemoryUsage(); - $this->image = new ImageOutput($partition->getImage()); + + if ($partition->getImage()) { + $this->image = new ImageOutput($partition->getImage()); + } } public function createOrUpdateEntity(?Partition $partition = null): Partition diff --git a/src/Dto/Output/ImageOutput.php b/src/Dto/Output/ImageOutput.php index acbdff7..3f7df0c 100644 --- a/src/Dto/Output/ImageOutput.php +++ b/src/Dto/Output/ImageOutput.php @@ -54,8 +54,8 @@ final class ImageOutput extends AbstractOutput $this->revision = $image->getRevision(); $this->info = $image->getInfo(); $this->size = $image->getSize(); - $this->clientOutput = new ClientOutput($image->getClient()); - $this->softwareProfile = new SoftwareProfileOutput($image->getSoftwareProfile()); - $this->organizationalUnit = new OrganizationalUnitOutput($image->getOrganizationalUnit()); + $this->clientOutput = $image->getClient() ? new ClientOutput($image->getClient()) : null; + $this->softwareProfile = $image->getSoftwareProfile() ? new SoftwareProfileOutput($image->getSoftwareProfile()) : null; + $this->organizationalUnit = $image->getOrganizationalUnit() ? new OrganizationalUnitOutput($image->getOrganizationalUnit()) : null; } } \ No newline at end of file