feat(core) : move notification into core and expose notifier contract
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\State;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\Pagination\Pagination;
|
||||
use ApiPlatform\State\Pagination\TraversablePaginator;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Entity\Notification;
|
||||
use App\Repository\NotificationRepository;
|
||||
use ArrayIterator;
|
||||
use Doctrine\ORM\Tools\Pagination\Paginator as DoctrinePaginator;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* @implements ProviderInterface<Notification>
|
||||
*/
|
||||
final readonly class NotificationProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private Security $security,
|
||||
private NotificationRepository $notificationRepository,
|
||||
private Pagination $pagination,
|
||||
) {}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object
|
||||
{
|
||||
$user = $this->security->getUser();
|
||||
|
||||
[$page, $offset, $limit] = $this->pagination->getPagination($operation, $context);
|
||||
|
||||
$queryBuilder = $this->notificationRepository
|
||||
->createUserNotificationsQueryBuilder($user)
|
||||
->setFirstResult($offset)
|
||||
->setMaxResults($limit)
|
||||
;
|
||||
|
||||
$doctrinePaginator = new DoctrinePaginator($queryBuilder);
|
||||
|
||||
return new TraversablePaginator(
|
||||
new ArrayIterator(iterator_to_array($doctrinePaginator, false)),
|
||||
$page,
|
||||
$limit,
|
||||
(float) count($doctrinePaginator),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user