<?php
namespace Seidemann\Hanagud\Controller;
use Seidemann\Hanagud\Entity\WebwareCustomer;
use Seidemann\Hanagud\Http\ApiResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* Controller to return the main HTML (ported to Twig from legacy).
*
* @IsGranted("ROLE_USER")
*/
class MainPageController extends AbstractController
{
#[Route(path: '/', name: 'main_page', methods: ['GET'])]
public function index(): Response
{
return $this->render('index.html.twig', [
'user' => $this->getUser(),
'is_logged_in' => $this->isGranted('ROLE_USER'),
]);
}
#[Route(path: '/getCustomers', name: 'get_customers_json', methods: ['GET'], defaults: ['_feature' => 'hanagud_address_switch'])]
public function getCustomers(): ApiResponse
{
$customerRepo = $this->getDoctrine()->getRepository(WebwareCustomer::class);
$customers = [];
foreach ($customerRepo->findAll() as $customer) {
$customers[] = [
'customerNumber' => $customer->getCustomerNumber(),
'name' => $customer->getName(),
];
}
return new ApiResponse($customers);
}
}