From 8503111a4bffd2e503af8aad02ce53467e1906ec Mon Sep 17 00:00:00 2001 From: Matthieu Date: Thu, 12 Mar 2026 17:51:59 +0100 Subject: [PATCH] feat(backend) : add archived field to Task entity Co-Authored-By: Claude Opus 4.6 --- src/Entity/Task.php | 67 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/src/Entity/Task.php b/src/Entity/Task.php index 90045c4..64b419d 100644 --- a/src/Entity/Task.php +++ b/src/Entity/Task.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Entity; +use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter; use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; use ApiPlatform\Metadata\ApiFilter; use ApiPlatform\Metadata\ApiResource; @@ -13,6 +14,7 @@ use ApiPlatform\Metadata\GetCollection; use ApiPlatform\Metadata\Patch; use ApiPlatform\Metadata\Post; use App\Repository\TaskRepository; +use App\State\TaskNumberProcessor; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; @@ -22,7 +24,7 @@ use Symfony\Component\Serializer\Attribute\Groups; operations: [ new GetCollection(), new Get(), - new Post(security: "is_granted('ROLE_ADMIN')"), + new Post(security: "is_granted('ROLE_ADMIN')", processor: TaskNumberProcessor::class), new Patch(security: "is_granted('ROLE_ADMIN')"), new Delete(security: "is_granted('ROLE_ADMIN')"), ], @@ -31,6 +33,7 @@ use Symfony\Component\Serializer\Attribute\Groups; order: ['id' => 'DESC'], )] #[ApiFilter(SearchFilter::class, properties: ['project' => 'exact', 'group' => 'exact'])] +#[ApiFilter(BooleanFilter::class, properties: ['archived'])] #[ORM\Entity(repositoryClass: TaskRepository::class)] class Task { @@ -40,6 +43,10 @@ class Task #[Groups(['task:read'])] private ?int $id = null; + #[ORM\Column(type: 'integer')] + #[Groups(['task:read'])] + private ?int $number = null; + #[ORM\Column(length: 255)] #[Groups(['task:read', 'task:write'])] private ?string $title = null; @@ -78,15 +85,23 @@ class Task #[Groups(['task:read', 'task:write'])] private ?Project $project = null; - /** @var Collection */ - #[ORM\ManyToMany(targetEntity: TaskType::class)] - #[ORM\JoinTable(name: 'task_task_type')] + /** @var Collection */ + #[ORM\ManyToMany(targetEntity: TaskTag::class)] + #[ORM\JoinTable( + name: 'task_task_type', + joinColumns: [new ORM\JoinColumn(name: 'task_id', referencedColumnName: 'id')], + inverseJoinColumns: [new ORM\JoinColumn(name: 'task_type_id', referencedColumnName: 'id')], + )] #[Groups(['task:read', 'task:write'])] - private Collection $types; + private Collection $tags; + + #[ORM\Column(type: 'boolean')] + #[Groups(['task:read', 'task:write'])] + private bool $archived = false; public function __construct() { - $this->types = new ArrayCollection(); + $this->tags = new ArrayCollection(); } public function getId(): ?int @@ -94,6 +109,18 @@ class Task return $this->id; } + public function getNumber(): ?int + { + return $this->number; + } + + public function setNumber(int $number): static + { + $this->number = $number; + + return $this; + } + public function getTitle(): ?string { return $this->title; @@ -190,24 +217,36 @@ class Task return $this; } - /** @return Collection */ - public function getTypes(): Collection + /** @return Collection */ + public function getTags(): Collection { - return $this->types; + return $this->tags; } - public function addType(TaskType $type): static + public function addTag(TaskTag $tag): static { - if (!$this->types->contains($type)) { - $this->types->add($type); + if (!$this->tags->contains($tag)) { + $this->tags->add($tag); } return $this; } - public function removeType(TaskType $type): static + public function removeTag(TaskTag $tag): static { - $this->types->removeElement($type); + $this->tags->removeElement($tag); + + return $this; + } + + public function isArchived(): bool + { + return $this->archived; + } + + public function setArchived(bool $archived): static + { + $this->archived = $archived; return $this; }