use App\Entity\Post; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; class ApiController extends AbstractController { #[Route('/api/posts', methods: ['GET'])] #[IsGranted('ROLE_USER')] public function getPosts(EntityManagerInterface $em): JsonResponse { $posts = $em->getRepository(Post::class)->findAll(); return $this->json($posts); } } 10