feat(time-tracking) : add ActiveTimeEntryProvider, fixtures, and serialization groups
- ActiveTimeEntryProvider returns active timer for current user - TimeEntry fixtures with 10 sample entries for the SIRH project - Add time_entry:read group to Project, User, and TaskType for embedded serialization Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,10 @@ use App\Entity\TaskGroup;
|
|||||||
use App\Entity\TaskPriority;
|
use App\Entity\TaskPriority;
|
||||||
use App\Entity\TaskStatus;
|
use App\Entity\TaskStatus;
|
||||||
use App\Entity\TaskType;
|
use App\Entity\TaskType;
|
||||||
|
use App\Entity\TimeEntry;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use DateTimeZone;
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
use Doctrine\Persistence\ObjectManager;
|
use Doctrine\Persistence\ObjectManager;
|
||||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||||
@@ -250,6 +253,35 @@ class AppFixtures extends Fixture
|
|||||||
$task6->addType($typeAuth);
|
$task6->addType($typeAuth);
|
||||||
$manager->persist($task6);
|
$manager->persist($task6);
|
||||||
|
|
||||||
|
// --- Time Entries (SIRH project, admin user) ---
|
||||||
|
$timeEntryData = [
|
||||||
|
['title' => 'Réunion', 'project' => $projectSirh, 'type' => $typeAuth, 'start' => '09:00', 'stop' => '09:45', 'day' => 1],
|
||||||
|
['title' => 'Page accueil', 'project' => $projectSirh, 'type' => $typePassword, 'start' => '10:00', 'stop' => '12:00', 'day' => 0],
|
||||||
|
['title' => 'Design admin', 'project' => $projectSirh, 'type' => $typeAuth, 'start' => '09:30', 'stop' => '11:00', 'day' => 2],
|
||||||
|
['title' => 'Page accueil', 'project' => $projectSirh, 'type' => $typePassword, 'start' => '10:30', 'stop' => '12:15', 'day' => 1],
|
||||||
|
['title' => 'System os', 'project' => $projectSirh, 'type' => $typeCalendar, 'start' => '13:00', 'stop' => '15:30', 'day' => 0],
|
||||||
|
['title' => 'Login', 'project' => $projectSirh, 'type' => $typePassword, 'start' => '13:00', 'stop' => '15:00', 'day' => 1],
|
||||||
|
['title' => 'Script vault', 'project' => $projectSirh, 'type' => $typeCalendar, 'start' => '10:00', 'stop' => '12:00', 'day' => 3],
|
||||||
|
['title' => 'Script backup BDD', 'project' => $projectSirh, 'type' => $typeAuth, 'start' => '13:30', 'stop' => '15:00', 'day' => 3],
|
||||||
|
['title' => 'Maquette', 'project' => $projectSirh, 'type' => null, 'start' => '09:00', 'stop' => '11:00', 'day' => 4],
|
||||||
|
['title' => 'PC compta', 'project' => $projectSirh, 'type' => null, 'start' => '13:30', 'stop' => '15:30', 'day' => 4],
|
||||||
|
];
|
||||||
|
|
||||||
|
$monday = new DateTimeImmutable('monday this week', new DateTimeZone('UTC'));
|
||||||
|
|
||||||
|
foreach ($timeEntryData as $data) {
|
||||||
|
$entry = new TimeEntry();
|
||||||
|
$entry->setTitle($data['title']);
|
||||||
|
$entry->setUser($admin);
|
||||||
|
$entry->setProject($data['project']);
|
||||||
|
$entry->setStartedAt($monday->modify("+{$data['day']} days")->modify($data['start']));
|
||||||
|
$entry->setStoppedAt($monday->modify("+{$data['day']} days")->modify($data['stop']));
|
||||||
|
if ($data['type']) {
|
||||||
|
$entry->addType($data['type']);
|
||||||
|
}
|
||||||
|
$manager->persist($entry);
|
||||||
|
}
|
||||||
|
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ class Project
|
|||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\GeneratedValue]
|
#[ORM\GeneratedValue]
|
||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
#[Groups(['project:read'])]
|
#[Groups(['project:read', 'time_entry:read'])]
|
||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
#[Groups(['project:read', 'project:write'])]
|
#[Groups(['project:read', 'project:write', 'time_entry:read'])]
|
||||||
private ?string $name = null;
|
private ?string $name = null;
|
||||||
|
|
||||||
#[ORM\Column(type: 'text', nullable: true)]
|
#[ORM\Column(type: 'text', nullable: true)]
|
||||||
@@ -44,7 +44,7 @@ class Project
|
|||||||
private ?string $description = null;
|
private ?string $description = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 7)]
|
#[ORM\Column(length: 7)]
|
||||||
#[Groups(['project:read', 'project:write'])]
|
#[Groups(['project:read', 'project:write', 'time_entry:read'])]
|
||||||
private ?string $color = '#222783';
|
private ?string $color = '#222783';
|
||||||
|
|
||||||
#[ORM\ManyToOne(targetEntity: Client::class, inversedBy: 'projects')]
|
#[ORM\ManyToOne(targetEntity: Client::class, inversedBy: 'projects')]
|
||||||
|
|||||||
@@ -32,15 +32,15 @@ class TaskType
|
|||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\GeneratedValue]
|
#[ORM\GeneratedValue]
|
||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
#[Groups(['task_type:read', 'task:read'])]
|
#[Groups(['task_type:read', 'task:read', 'time_entry:read'])]
|
||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
#[Groups(['task_type:read', 'task_type:write', 'task:read'])]
|
#[Groups(['task_type:read', 'task_type:write', 'task:read', 'time_entry:read'])]
|
||||||
private ?string $label = null;
|
private ?string $label = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 7)]
|
#[ORM\Column(length: 7)]
|
||||||
#[Groups(['task_type:read', 'task_type:write', 'task:read'])]
|
#[Groups(['task_type:read', 'task_type:write', 'task:read', 'time_entry:read'])]
|
||||||
private ?string $color = '#222783';
|
private ?string $color = '#222783';
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
|
|||||||
@@ -46,11 +46,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\GeneratedValue]
|
#[ORM\GeneratedValue]
|
||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
#[Groups(['me:read', 'task:read', 'user:list'])]
|
#[Groups(['me:read', 'task:read', 'user:list', 'time_entry:read'])]
|
||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 180, unique: true)]
|
#[ORM\Column(length: 180, unique: true)]
|
||||||
#[Groups(['me:read', 'task:read', 'user:list', 'user:write'])]
|
#[Groups(['me:read', 'task:read', 'user:list', 'user:write', 'time_entry:read'])]
|
||||||
private ?string $username = null;
|
private ?string $username = null;
|
||||||
|
|
||||||
/** @var list<string> */
|
/** @var list<string> */
|
||||||
|
|||||||
33
src/State/ActiveTimeEntryProvider.php
Normal file
33
src/State/ActiveTimeEntryProvider.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\State;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use ApiPlatform\State\ProviderInterface;
|
||||||
|
use App\Entity\TimeEntry;
|
||||||
|
use App\Repository\TimeEntryRepository;
|
||||||
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @implements ProviderInterface<TimeEntry>
|
||||||
|
*/
|
||||||
|
final readonly class ActiveTimeEntryProvider implements ProviderInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private Security $security,
|
||||||
|
private TimeEntryRepository $timeEntryRepository,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?TimeEntry
|
||||||
|
{
|
||||||
|
$user = $this->security->getUser();
|
||||||
|
|
||||||
|
if (!$user) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->timeEntryRepository->findActiveByUser($user);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user