34 lines
839 B
PHP
34 lines
839 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\State;
|
|
|
|
use ApiPlatform\Metadata\Operation;
|
|
use ApiPlatform\State\ProviderInterface;
|
|
use App\Entity\Notification;
|
|
use App\Repository\NotificationRepository;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
|
|
/**
|
|
* @implements ProviderInterface<Notification>
|
|
*/
|
|
final readonly class NotificationProvider implements ProviderInterface
|
|
{
|
|
public function __construct(
|
|
private Security $security,
|
|
private NotificationRepository $notificationRepository,
|
|
) {}
|
|
|
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): array|object
|
|
{
|
|
$user = $this->security->getUser();
|
|
|
|
return $this->notificationRepository->findBy(
|
|
['user' => $user],
|
|
['createdAt' => 'DESC'],
|
|
30,
|
|
);
|
|
}
|
|
}
|