src/Controller/MainPageController.php line 20

Open in your IDE?
  1. <?php
  2. namespace Seidemann\Hanagud\Controller;
  3. use Seidemann\Hanagud\Entity\WebwareCustomer;
  4. use Seidemann\Hanagud\Http\ApiResponse;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. /**
  10.  * Controller to return the main HTML (ported to Twig from legacy).
  11.  *
  12.  * @IsGranted("ROLE_USER")
  13.  */
  14. class MainPageController extends AbstractController
  15. {
  16.     #[Route(path'/'name'main_page'methods: ['GET'])]
  17.     public function index(): Response
  18.     {
  19.         return $this->render('index.html.twig', [
  20.             'user' => $this->getUser(),
  21.             'is_logged_in' => $this->isGranted('ROLE_USER'),
  22.         ]);
  23.     }
  24.     #[Route(path'/getCustomers'name'get_customers_json'methods: ['GET'], defaults: ['_feature' => 'hanagud_address_switch'])]
  25.     public function getCustomers(): ApiResponse
  26.     {
  27.         $customerRepo $this->getDoctrine()->getRepository(WebwareCustomer::class);
  28.         $customers = [];
  29.         foreach ($customerRepo->findAll() as $customer) {
  30.             $customers[] = [
  31.                 'customerNumber' => $customer->getCustomerNumber(),
  32.                 'name' => $customer->getName(),
  33.             ];
  34.         }
  35.         return new ApiResponse($customers);
  36.     }
  37. }