add orm and tests

This commit is contained in:
lubiana 2024-06-10 20:22:44 +02:00
parent a32bf4ce7d
commit a541338909
No known key found for this signature in database
23 changed files with 1666 additions and 23 deletions

View file

@ -0,0 +1,81 @@
<?php
namespace App\Controller;
use App\Entity\FoodVendor;
use App\Form\FoodVendorType;
use App\Repository\FoodVendorRepository;
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/vendor')]
class FoodVendorController extends AbstractController
{
#[Route('/', name: 'app_food_vendor_index', methods: ['GET'])]
public function index(FoodVendorRepository $foodVendorRepository): Response
{
return $this->render('food_vendor/index.html.twig', [
'food_vendors' => $foodVendorRepository->findAll(),
]);
}
#[Route('/new', name: 'app_food_vendor_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$foodVendor = new FoodVendor();
$form = $this->createForm(FoodVendorType::class, $foodVendor);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($foodVendor);
$entityManager->flush();
return $this->redirectToRoute('app_food_vendor_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('food_vendor/new.html.twig', [
'food_vendor' => $foodVendor,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_food_vendor_show', methods: ['GET'])]
public function show(FoodVendor $foodVendor): Response
{
return $this->render('food_vendor/show.html.twig', [
'food_vendor' => $foodVendor,
]);
}
#[Route('/{id}/edit', name: 'app_food_vendor_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, FoodVendor $foodVendor, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(FoodVendorType::class, $foodVendor);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('app_food_vendor_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('food_vendor/edit.html.twig', [
'food_vendor' => $foodVendor,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_food_vendor_delete', methods: ['POST'])]
public function delete(Request $request, FoodVendor $foodVendor, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete'.$foodVendor->getId(), $request->getPayload()->getString('_token'))) {
$entityManager->remove($foodVendor);
$entityManager->flush();
}
return $this->redirectToRoute('app_food_vendor_index', [], Response::HTTP_SEE_OTHER);
}
}