add order

This commit is contained in:
lubiana 2024-06-14 17:41:00 +02:00
parent 7663f684a4
commit 1dc5306967
No known key found for this signature in database
37 changed files with 1060 additions and 113 deletions

View file

@ -0,0 +1,72 @@
<?php declare(strict_types=1);
namespace App\Controller;
use App\Entity\FoodOrder;
use App\Form\FoodOrderType;
use App\Repository\FoodOrderRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
#[Route('/food/order')]
final class FoodOrderController extends AbstractController
{
#[Route('/', name: 'app_food_order_index', methods: ['GET'])]
public function index(FoodOrderRepository $foodOrderRepository): Response
{
return $this->render('food_order/index.html.twig', [
'food_orders' => $foodOrderRepository->findAll(),
]);
}
#[Route('/new', name: 'app_food_order_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$foodOrder = new FoodOrder;
$form = $this->createForm(FoodOrderType::class, $foodOrder, [
'action' => $this->generateUrl('app_food_order_new'),
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($foodOrder);
$entityManager->flush();
return $this->redirectToRoute('app_food_order_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('food_order/new.html.twig', [
'food_order' => $foodOrder,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_food_order_show', methods: ['GET'])]
public function show(FoodOrder $foodOrder): Response
{
return $this->render('food_order/show.html.twig', [
'food_order' => $foodOrder,
]);
}
#[Route('/{id}/close', name: 'app_food_order_close', methods: ['GET'])]
public function close(FoodOrder $foodOrder, FoodOrderRepository $repository): Response
{
$repository->save($foodOrder->close());
return $this->redirectToRoute('app_food_order_show', [
'id' => $foodOrder->getId(),
], Response::HTTP_SEE_OTHER);
}
#[Route('/{id}/open', name: 'app_food_order_open', methods: ['GET'])]
public function open(FoodOrder $foodOrder, FoodOrderRepository $repository): Response
{
$repository->save($foodOrder->open());
return $this->redirectToRoute('app_food_order_show', [
'id' => $foodOrder->getId(),
], Response::HTTP_SEE_OTHER);
}
}