add orderstuff

This commit is contained in:
lubiana 2025-06-14 22:43:27 +02:00
parent 51fb951b2b
commit d7a61f6d0e
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
9 changed files with 209 additions and 10 deletions

View file

@ -6,6 +6,7 @@ namespace App\Controller;
use App\Repository\DrinkTypeRepository;
use App\Service\DrinkType\FilterLowStockDrinks;
use App\Service\OrderService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
@ -15,13 +16,16 @@ final class Index extends AbstractController
{
public function __invoke(
DrinkTypeRepository $drinkTypeRepository,
FilterLowStockDrinks $filterLowStockDrinks
FilterLowStockDrinks $filterLowStockDrinks,
OrderService $orderService,
): Response {
$wanted = $drinkTypeRepository->findWanted();
$lowStock = $filterLowStockDrinks($wanted);
$orders = $orderService->getActiveOrders();
return $this->render('index.html.twig', [
'drinkTypes' => $lowStock,
'lowStock' => $lowStock,
'orders' => $orders,
]);
}

View file

@ -7,6 +7,7 @@ namespace App\Controller;
use App\Entity\Order;
use App\Form\OrderForm;
use App\Repository\OrderRepository;
use App\Service\DrinkType\CreateNewOrderItems;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
@ -25,9 +26,10 @@ final class OrderController extends AbstractController
}
#[Route('/new', name: 'app_order_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
public function new(Request $request, EntityManagerInterface $entityManager, CreateNewOrderItems $createNewOrderItems): Response
{
$order = new Order();
$createNewOrderItems($order);
$form = $this->createForm(OrderForm::class, $order);
$form->handleRequest($request);
@ -35,7 +37,7 @@ final class OrderController extends AbstractController
$entityManager->persist($order);
$entityManager->flush();
return $this->redirectToRoute('app_order_index', [], Response::HTTP_SEE_OTHER);
return $this->redirectToRoute('app_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('order/new.html.twig', [