diff --git a/config/services/api_platform.yaml b/config/services/api_platform.yaml index 7ef6df7..a9eed1a 100644 --- a/config/services/api_platform.yaml +++ b/config/services/api_platform.yaml @@ -213,7 +213,7 @@ services: api_platform.filter.pxe_template.boolean: parent: 'api_platform.doctrine.orm.boolean_filter' - arguments: [ { 'synchronized': ~ } ] + arguments: [ { 'synchronized': ~, 'isDefault': ~ } ] tags: [ 'api_platform.filter' ] api_platform.filter.remote_calendar.order: diff --git a/migrations/Version20250506141057.php b/migrations/Version20250506141057.php new file mode 100644 index 0000000..0fd654f --- /dev/null +++ b/migrations/Version20250506141057.php @@ -0,0 +1,33 @@ +addSql('ALTER TABLE client DROP FOREIGN KEY FK_C74404555DA0FB8'); + $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C74404555DA0FB8 FOREIGN KEY (template_id) REFERENCES pxe_template (id) ON DELETE SET NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C74404555DA0FB8'); + $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C74404555DA0FB8 FOREIGN KEY (template_id) REFERENCES pxe_template (id)'); + } +} diff --git a/src/Dto/Input/PxeTemplateInput.php b/src/Dto/Input/PxeTemplateInput.php index 3474781..58d4946 100644 --- a/src/Dto/Input/PxeTemplateInput.php +++ b/src/Dto/Input/PxeTemplateInput.php @@ -18,6 +18,10 @@ final class PxeTemplateInput #[ApiProperty(description: 'The content of the pxeTemplate', example: "content of the pxeTemplate 1")] public ?string $templateContent = null; + #[Groups(['pxe-template:write'])] + #[ApiProperty(description: 'The default pxeTemplate', example: "true")] + public ?bool $isDefault = null; + public function __construct(?PxeTemplate $pxeTemplate = null) { if (!$pxeTemplate) { @@ -26,6 +30,7 @@ final class PxeTemplateInput $this->name = $pxeTemplate->getName(); $this->templateContent = $pxeTemplate->getTemplateContent(); + $this->isDefault = $pxeTemplate->isDefault(); } public function createOrUpdateEntity(?PxeTemplate $pxeTemplate = null): PxeTemplate @@ -36,6 +41,7 @@ final class PxeTemplateInput $pxeTemplate->setName($this->name); $pxeTemplate->setTemplateContent($this->templateContent); + $pxeTemplate->setDefault($this->isDefault); return $pxeTemplate; } diff --git a/src/Dto/Output/PxeTemplateOutput.php b/src/Dto/Output/PxeTemplateOutput.php index 41cbbe0..f625215 100644 --- a/src/Dto/Output/PxeTemplateOutput.php +++ b/src/Dto/Output/PxeTemplateOutput.php @@ -20,6 +20,9 @@ final class PxeTemplateOutput extends AbstractOutput #[Groups(['pxe-template:read'])] public ?string $templateContent = ''; + #[Groups(['pxe-template:read'])] + public ?bool $isDefault = null; + #[Groups(['pxe-template:read'])] public ?int $clientsLength = 0; @@ -37,6 +40,7 @@ final class PxeTemplateOutput extends AbstractOutput $this->synchronized = $pxeTemplate->isSynchronized(); $this->templateContent = $pxeTemplate->getTemplateContent(); $this->clientsLength = $pxeTemplate->getClients()->count(); + $this->isDefault = $pxeTemplate->isDefault(); $this->createdAt = $pxeTemplate->getCreatedAt(); $this->createdBy = $pxeTemplate->getCreatedBy(); } diff --git a/src/Entity/PxeTemplate.php b/src/Entity/PxeTemplate.php index 5a3efaa..bfd9745 100644 --- a/src/Entity/PxeTemplate.php +++ b/src/Entity/PxeTemplate.php @@ -26,6 +26,9 @@ class PxeTemplate extends AbstractEntity #[ORM\OneToMany(mappedBy: 'template', targetEntity: Client::class)] private Collection $clients; + #[ORM\Column(nullable: true)] + private ?bool $isDefault = null; + public function __construct() { parent::__construct(); @@ -82,4 +85,16 @@ class PxeTemplate extends AbstractEntity return $this; } + + public function isDefault(): ?bool + { + return $this->isDefault; + } + + public function setDefault(?bool $isDefault): static + { + $this->isDefault = $isDefault; + + return $this; + } }