feat(backend) : add archived field to Task entity

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-12 17:51:59 +01:00
parent 6801dae0f2
commit 8503111a4b

View File

@@ -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<int, TaskType> */
#[ORM\ManyToMany(targetEntity: TaskType::class)]
#[ORM\JoinTable(name: 'task_task_type')]
/** @var Collection<int, TaskTag> */
#[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<int, TaskType> */
public function getTypes(): Collection
/** @return Collection<int, TaskTag> */
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;
}