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:
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