Use [#MapEntity()] attribute to inject entity into method + for now set controller_resolver.auto_mapping to true

This commit is contained in:
2025-05-28 14:58:59 +02:00
parent f282ffbfd4
commit 8ec18a6fb8
24 changed files with 120 additions and 117 deletions

View File

@@ -19,6 +19,7 @@ use Chill\MainBundle\Security\Authorization\NotificationVoter;
use Chill\MainBundle\Serializer\Model\Collection;
use Chill\MainBundle\Serializer\Model\Counter;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
@@ -32,13 +33,13 @@ class NotificationApiController
public function __construct(private readonly EntityManagerInterface $entityManager, private readonly NotificationRepository $notificationRepository, private readonly PaginatorFactory $paginatorFactory, private readonly Security $security, private readonly SerializerInterface $serializer) {}
#[Route(path: '/{id}/mark/read', name: 'chill_api_main_notification_mark_read', methods: ['POST'])]
public function markAsRead(Notification $notification): JsonResponse
public function markAsRead(#[MapEntity(id: 'id')] Notification $notification): JsonResponse
{
return $this->markAs('read', $notification);
}
#[Route(path: '/{id}/mark/unread', name: 'chill_api_main_notification_mark_unread', methods: ['POST'])]
public function markAsUnread(Notification $notification): JsonResponse
public function markAsUnread(#[MapEntity(id: 'id')] Notification $notification): JsonResponse
{
return $this->markAs('unread', $notification);
}