42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Dto\Input;
|
|
|
|
use ApiPlatform\Metadata\ApiProperty;
|
|
use App\Entity\Software;
|
|
use Symfony\Component\Serializer\Annotation\Groups;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
final class SoftwareInput
|
|
{
|
|
#[Assert\NotBlank]
|
|
#[Groups(['software:write'])]
|
|
#[ApiProperty(description: 'The name of the software', example: "Software 1")]
|
|
public ?string $name = null;
|
|
|
|
#[Groups(['software:write'])]
|
|
#[ApiProperty(description: 'The description of the software', example: "Software 1 description")]
|
|
public ?string $description = null;
|
|
|
|
public function __construct(?Software $software = null)
|
|
{
|
|
if (!$software) {
|
|
return;
|
|
}
|
|
|
|
$this->name = $software->getName();
|
|
$this->description = $software->getDescription();
|
|
}
|
|
|
|
public function createOrUpdateEntity(?Software $software = null): Software
|
|
{
|
|
if (!$software) {
|
|
$software = new Software();
|
|
}
|
|
|
|
$software->setName($this->name);
|
|
$software->setDescription($this->description);
|
|
|
|
return $software;
|
|
}
|
|
} |