ogcore/src/Dto/Input/HardwareProfileInput.php

51 lines
1.7 KiB
PHP

<?php
namespace App\Dto\Input;
use ApiPlatform\Metadata\ApiProperty;
use App\Dto\Output\OrganizationalUnitOutput;
use App\Entity\HardwareProfile;
use Symfony\Component\Serializer\Annotation\Groups;
final class HardwareProfileInput
{
#[Groups(['hardware-profile:write'])]
#[ApiProperty(description: 'The description of the hardware profile', example: "Hardware 1 description")]
public ?string $description = null;
#[Groups(['hardware-profile:write'])]
#[ApiProperty(description: 'Comments of the hardware profile', example: "Hardware 1")]
public ?string $comments = null;
#[Groups(['hardware-profile:write'])]
#[ApiProperty(description: 'The organizational unit of the hardware profile')]
public ?OrganizationalUnitOutput $organizationalUnit = null;
public function __construct(?HardwareProfile $hardwareProfile = null)
{
if (!$hardwareProfile) {
return;
}
$this->description = $hardwareProfile->getDescription();
$this->comments = $hardwareProfile->getComments();
if($hardwareProfile->getOrganizationalUnit()) {
$this->organizationalUnit = new OrganizationalUnitOutput($hardwareProfile->getOrganizationalUnit());
}
}
public function createOrUpdateEntity(?HardwareProfile $hardwareProfile = null): HardwareProfile
{
if (!$hardwareProfile) {
$hardwareProfile = new HardwareProfile();
}
$hardwareProfile->setDescription($this->description);
$hardwareProfile->setComments($this->comments);
if ($this->organizationalUnit) {
$hardwareProfile->setOrganizationalUnit($this->organizationalUnit->getEntity());
}
return $hardwareProfile;
}
}