refactor(core) : point user relations to the shared contract via resolve_target_entities

This commit is contained in:
Matthieu
2026-06-19 16:04:14 +02:00
parent f8fc4d6bd9
commit d70925b812
7 changed files with 44 additions and 37 deletions
+5 -4
View File
@@ -10,6 +10,7 @@ use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use App\Enum\AbsenceType;
use App\Repository\AbsenceBalanceRepository;
use App\Shared\Domain\Contract\UserInterface;
use App\State\AbsenceBalanceProvider;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
@@ -45,10 +46,10 @@ class AbsenceBalance
#[Groups(['absence_balance:read'])]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\ManyToOne(targetEntity: UserInterface::class)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[Groups(['absence_balance:read'])]
private ?User $user = null;
private ?UserInterface $user = null;
#[ORM\Column(type: Types::STRING, length: 32, enumType: AbsenceType::class)]
#[Groups(['absence_balance:read'])]
@@ -110,12 +111,12 @@ class AbsenceBalance
return $this->id;
}
public function getUser(): ?User
public function getUser(): ?UserInterface
{
return $this->user;
}
public function setUser(?User $user): static
public function setUser(?UserInterface $user): static
{
$this->user = $user;
+9 -8
View File
@@ -14,6 +14,7 @@ use App\Enum\AbsenceStatus;
use App\Enum\AbsenceType;
use App\Enum\HalfDay;
use App\Repository\AbsenceRequestRepository;
use App\Shared\Domain\Contract\UserInterface;
use App\State\AbsenceCancelProcessor;
use App\State\AbsenceRequestProcessor;
use App\State\AbsenceRequestProvider;
@@ -73,10 +74,10 @@ class AbsenceRequest
#[Groups(['absence_request:read'])]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\ManyToOne(targetEntity: UserInterface::class)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[Groups(['absence_request:read'])]
private ?User $user = null;
private ?UserInterface $user = null;
#[ORM\Column(type: Types::STRING, length: 32, enumType: AbsenceType::class)]
#[Groups(['absence_request:read', 'absence_request:write'])]
@@ -130,10 +131,10 @@ class AbsenceRequest
#[Groups(['absence_request:read'])]
private ?DateTimeImmutable $reviewedAt = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\ManyToOne(targetEntity: UserInterface::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
#[Groups(['absence_request:read'])]
private ?User $reviewedBy = null;
private ?UserInterface $reviewedBy = null;
#[Groups(['absence_request:read'])]
public function getLabel(): ?string
@@ -156,12 +157,12 @@ class AbsenceRequest
return $this->id;
}
public function getUser(): ?User
public function getUser(): ?UserInterface
{
return $this->user;
}
public function setUser(?User $user): static
public function setUser(?UserInterface $user): static
{
$this->user = $user;
@@ -312,12 +313,12 @@ class AbsenceRequest
return $this;
}
public function getReviewedBy(): ?User
public function getReviewedBy(): ?UserInterface
{
return $this->reviewedBy;
}
public function setReviewedBy(?User $reviewedBy): static
public function setReviewedBy(?UserInterface $reviewedBy): static
{
$this->reviewedBy = $reviewedBy;
+5 -4
View File
@@ -8,6 +8,7 @@ use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use App\Repository\NotificationRepository;
use App\Shared\Domain\Contract\UserInterface;
use App\State\NotificationProvider;
use DateTimeImmutable;
use Doctrine\DBAL\Types\Types;
@@ -39,10 +40,10 @@ class Notification
#[Groups(['notification:read'])]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\ManyToOne(targetEntity: UserInterface::class)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[Groups(['notification:read'])]
private ?User $user = null;
private ?UserInterface $user = null;
#[ORM\Column(length: 50)]
#[Groups(['notification:read'])]
@@ -69,12 +70,12 @@ class Notification
return $this->id;
}
public function getUser(): ?User
public function getUser(): ?UserInterface
{
return $this->user;
}
public function setUser(?User $user): static
public function setUser(?UserInterface $user): static
{
$this->user = $user;
+10 -9
View File
@@ -16,6 +16,7 @@ use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\Repository\TaskRepository;
use App\Shared\Domain\Contract\UserInterface;
use App\State\TaskCalendarProcessor;
use App\State\TaskNumberProcessor;
use DateTimeImmutable;
@@ -80,13 +81,13 @@ class Task
#[Groups(['task:read', 'task:write'])]
private ?TaskPriority $priority = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\ManyToOne(targetEntity: UserInterface::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
#[Groups(['task:read', 'task:write'])]
private ?User $assignee = null;
private ?UserInterface $assignee = null;
/** @var Collection<int, User> */
#[ORM\ManyToMany(targetEntity: User::class)]
/** @var Collection<int, UserInterface> */
#[ORM\ManyToMany(targetEntity: UserInterface::class)]
#[ORM\JoinTable(
name: 'task_collaborator',
joinColumns: [new ORM\JoinColumn(name: 'task_id', referencedColumnName: 'id', onDelete: 'CASCADE')],
@@ -239,25 +240,25 @@ class Task
return $this;
}
public function getAssignee(): ?User
public function getAssignee(): ?UserInterface
{
return $this->assignee;
}
public function setAssignee(?User $assignee): static
public function setAssignee(?UserInterface $assignee): static
{
$this->assignee = $assignee;
return $this;
}
/** @return Collection<int, User> */
/** @return Collection<int, UserInterface> */
public function getCollaborators(): Collection
{
return $this->collaborators;
}
public function addCollaborator(User $user): static
public function addCollaborator(UserInterface $user): static
{
if (!$this->collaborators->contains($user)) {
$this->collaborators->add($user);
@@ -266,7 +267,7 @@ class Task
return $this;
}
public function removeCollaborator(User $user): static
public function removeCollaborator(UserInterface $user): static
{
$this->collaborators->removeElement($user);
+5 -4
View File
@@ -12,6 +12,7 @@ use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use App\EventListener\TaskDocumentListener;
use App\Shared\Domain\Contract\UserInterface;
use App\State\TaskDocumentProcessor;
use App\State\TaskDocumentProvider;
use DateTimeImmutable;
@@ -77,10 +78,10 @@ class TaskDocument
#[Groups(['task_document:read', 'task:read'])]
private ?DateTimeImmutable $createdAt = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\ManyToOne(targetEntity: UserInterface::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
#[Groups(['task_document:read', 'task:read'])]
private ?User $uploadedBy = null;
private ?UserInterface $uploadedBy = null;
public function getId(): ?int
{
@@ -176,12 +177,12 @@ class TaskDocument
return $this;
}
public function getUploadedBy(): ?User
public function getUploadedBy(): ?UserInterface
{
return $this->uploadedBy;
}
public function setUploadedBy(?User $uploadedBy): static
public function setUploadedBy(?UserInterface $uploadedBy): static
{
$this->uploadedBy = $uploadedBy;
+5 -4
View File
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Entity;
use App\Repository\TaskMailLinkRepository;
use App\Shared\Domain\Contract\UserInterface;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
@@ -29,9 +30,9 @@ class TaskMailLink
#[ORM\Column(type: 'datetimetz_immutable')]
private DateTimeImmutable $linkedAt;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\ManyToOne(targetEntity: UserInterface::class)]
#[ORM\JoinColumn(name: 'linked_by_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
private ?User $linkedBy = null;
private ?UserInterface $linkedBy = null;
public function getId(): ?int
{
@@ -74,12 +75,12 @@ class TaskMailLink
return $this;
}
public function getLinkedBy(): ?User
public function getLinkedBy(): ?UserInterface
{
return $this->linkedBy;
}
public function setLinkedBy(?User $linkedBy): static
public function setLinkedBy(?UserInterface $linkedBy): static
{
$this->linkedBy = $linkedBy;
+5 -4
View File
@@ -14,6 +14,7 @@ use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\Repository\TimeEntryRepository;
use App\Shared\Domain\Contract\UserInterface;
use App\State\ActiveTimeEntryProvider;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
@@ -77,10 +78,10 @@ class TimeEntry
#[Groups(['time_entry:read', 'time_entry:write'])]
private ?DateTimeImmutable $stoppedAt = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\ManyToOne(targetEntity: UserInterface::class)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[Groups(['time_entry:read', 'time_entry:write'])]
private ?User $user = null;
private ?UserInterface $user = null;
#[ORM\ManyToOne(targetEntity: Project::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
@@ -160,12 +161,12 @@ class TimeEntry
return $this;
}
public function getUser(): ?User
public function getUser(): ?UserInterface
{
return $this->user;
}
public function setUser(?User $user): static
public function setUser(?UserInterface $user): static
{
$this->user = $user;