Compare commits
2 commits
bbc56a9af7
...
8ebf229d62
Author | SHA1 | Date | |
---|---|---|---|
8ebf229d62 | |||
1f9562d36b |
15 changed files with 2013 additions and 1349 deletions
|
@ -15,7 +15,6 @@
|
||||||
"doctrine/orm": "^3.4.0",
|
"doctrine/orm": "^3.4.0",
|
||||||
"nelmio/cors-bundle": "^2.5",
|
"nelmio/cors-bundle": "^2.5",
|
||||||
"phpdocumentor/reflection-docblock": "^5.6.2",
|
"phpdocumentor/reflection-docblock": "^5.6.2",
|
||||||
"phpstan/phpdoc-parser": "^1.33",
|
|
||||||
"psr/clock": "^1.0",
|
"psr/clock": "^1.0",
|
||||||
"symfony/asset": "7.3.*",
|
"symfony/asset": "7.3.*",
|
||||||
"symfony/asset-mapper": "7.3.*",
|
"symfony/asset-mapper": "7.3.*",
|
||||||
|
@ -42,7 +41,7 @@
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"doctrine/doctrine-fixtures-bundle": "^4.1",
|
"doctrine/doctrine-fixtures-bundle": "^4.1",
|
||||||
"liip/test-fixtures-bundle": "^3.4",
|
"liip/test-fixtures-bundle": "^3.4",
|
||||||
"lubiana/code-quality": "^1.7.2",
|
"lubiana/code-quality": "1.7.3",
|
||||||
"pestphp/pest": "^3.8.2",
|
"pestphp/pest": "^3.8.2",
|
||||||
"symfony/browser-kit": "7.3.*",
|
"symfony/browser-kit": "7.3.*",
|
||||||
"symfony/css-selector": "7.3.*",
|
"symfony/css-selector": "7.3.*",
|
||||||
|
|
2471
composer.lock
generated
2471
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -48,13 +48,13 @@ return [
|
||||||
'dev' => true,
|
'dev' => true,
|
||||||
'test' => true,
|
'test' => true,
|
||||||
],
|
],
|
||||||
ApiPlatformBundle::class => [
|
|
||||||
'all' => true,
|
|
||||||
],
|
|
||||||
TwigExtraBundle::class => [
|
TwigExtraBundle::class => [
|
||||||
'all' => true,
|
'all' => true,
|
||||||
],
|
],
|
||||||
MonologBundle::class => [
|
MonologBundle::class => [
|
||||||
'all' => true,
|
'all' => true,
|
||||||
],
|
],
|
||||||
|
ApiPlatformBundle::class => [
|
||||||
|
'all' => true,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
|
@ -14,22 +14,6 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||||
#[Route('/food/order')]
|
#[Route('/food/order')]
|
||||||
final class FoodOrderController extends AbstractController
|
final class FoodOrderController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route(
|
|
||||||
path: '/list',
|
|
||||||
name: 'app_food_order_index',
|
|
||||||
methods: ['GET']
|
|
||||||
)]
|
|
||||||
public function index(FoodOrderRepository $foodOrderRepository): Response
|
|
||||||
{
|
|
||||||
|
|
||||||
return $this->render('food_order/index.html.twig', [
|
|
||||||
'food_orders' => $foodOrderRepository->findLatestEntries(days: 3),
|
|
||||||
'current_page' => 0,
|
|
||||||
'next_page' => 0,
|
|
||||||
'prev_page' => 0,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Route(
|
#[Route(
|
||||||
path: '/list/archive/{page}',
|
path: '/list/archive/{page}',
|
||||||
name: 'app_food_order_archive',
|
name: 'app_food_order_archive',
|
||||||
|
@ -60,6 +44,32 @@ final class FoodOrderController extends AbstractController
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route('/{id}/close', name: 'app_food_order_close', methods: ['GET'])]
|
||||||
|
public function close(FoodOrder $foodOrder, FoodOrderRepository $repository): Response
|
||||||
|
{
|
||||||
|
$foodOrder->close();
|
||||||
|
$repository->save();
|
||||||
|
return $this->redirectToRoute('app_food_order_show', [
|
||||||
|
'id' => $foodOrder->getId(),
|
||||||
|
], Response::HTTP_SEE_OTHER);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route(
|
||||||
|
path: '/list',
|
||||||
|
name: 'app_food_order_index',
|
||||||
|
methods: ['GET']
|
||||||
|
)]
|
||||||
|
public function index(FoodOrderRepository $foodOrderRepository): Response
|
||||||
|
{
|
||||||
|
|
||||||
|
return $this->render('food_order/index.html.twig', [
|
||||||
|
'food_orders' => $foodOrderRepository->findLatestEntries(days: 3),
|
||||||
|
'current_page' => 0,
|
||||||
|
'next_page' => 0,
|
||||||
|
'prev_page' => 0,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
#[Route('/new', name: 'app_food_order_new', methods: ['GET', 'POST'])]
|
#[Route('/new', name: 'app_food_order_new', methods: ['GET', 'POST'])]
|
||||||
public function new(Request $request, EntityManagerInterface $entityManager): Response
|
public function new(Request $request, EntityManagerInterface $entityManager): Response
|
||||||
{
|
{
|
||||||
|
@ -84,24 +94,6 @@ final class FoodOrderController extends AbstractController
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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
|
|
||||||
{
|
|
||||||
$foodOrder->close();
|
|
||||||
$repository->save();
|
|
||||||
return $this->redirectToRoute('app_food_order_show', [
|
|
||||||
'id' => $foodOrder->getId(),
|
|
||||||
], Response::HTTP_SEE_OTHER);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Route('/{id}/open', name: 'app_food_order_open', methods: ['GET'])]
|
#[Route('/{id}/open', name: 'app_food_order_open', methods: ['GET'])]
|
||||||
public function open(FoodOrder $foodOrder, FoodOrderRepository $repository): Response
|
public function open(FoodOrder $foodOrder, FoodOrderRepository $repository): Response
|
||||||
{
|
{
|
||||||
|
@ -111,4 +103,12 @@ final class FoodOrderController extends AbstractController
|
||||||
'id' => $foodOrder->getId(),
|
'id' => $foodOrder->getId(),
|
||||||
], Response::HTTP_SEE_OTHER);
|
], Response::HTTP_SEE_OTHER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,23 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||||
#[Route('/food/vendor')]
|
#[Route('/food/vendor')]
|
||||||
final class FoodVendorController extends AbstractController
|
final class FoodVendorController extends AbstractController
|
||||||
{
|
{
|
||||||
|
#[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', [
|
||||||
|
'form' => $form,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
#[Route('/', name: 'app_food_vendor_index', methods: ['GET'])]
|
#[Route('/', name: 'app_food_vendor_index', methods: ['GET'])]
|
||||||
public function index(FoodVendorRepository $foodVendorRepository): Response
|
public function index(FoodVendorRepository $foodVendorRepository): Response
|
||||||
{
|
{
|
||||||
|
@ -51,21 +68,4 @@ final class FoodVendorController extends AbstractController
|
||||||
'food_vendor' => $foodVendor,
|
'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', [
|
|
||||||
'form' => $form,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,18 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||||
#[Route('/menu/item')]
|
#[Route('/menu/item')]
|
||||||
final class MenuItemController extends AbstractController
|
final class MenuItemController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route('/{id}', name: 'app_menu_item_show', methods: ['GET'])]
|
#[Route('/{id}', name: 'app_menu_item_delete', methods: ['POST'])]
|
||||||
public function show(MenuItem $menuItem): Response
|
public function delete(Request $request, MenuItem $menuItem, EntityManagerInterface $entityManager): Response
|
||||||
{
|
{
|
||||||
return $this->render('menu_item/show.html.twig', [
|
if ($this->isCsrfTokenValid('delete' . $menuItem->getId(), $request->getPayload()->getString('_token'))) {
|
||||||
'menu_item' => $menuItem,
|
$menuItem->delete();
|
||||||
]);
|
$entityManager->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->redirectToRoute('app_food_vendor_show', [
|
||||||
|
'id' => $menuItem->getFoodVendor()
|
||||||
|
->getId(),
|
||||||
|
], Response::HTTP_SEE_OTHER);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/{id}/edit', name: 'app_menu_item_edit', methods: ['GET', 'POST'])]
|
#[Route('/{id}/edit', name: 'app_menu_item_edit', methods: ['GET', 'POST'])]
|
||||||
|
@ -52,17 +58,11 @@ final class MenuItemController extends AbstractController
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/{id}', name: 'app_menu_item_delete', methods: ['POST'])]
|
#[Route('/{id}', name: 'app_menu_item_show', methods: ['GET'])]
|
||||||
public function delete(Request $request, MenuItem $menuItem, EntityManagerInterface $entityManager): Response
|
public function show(MenuItem $menuItem): Response
|
||||||
{
|
{
|
||||||
if ($this->isCsrfTokenValid('delete' . $menuItem->getId(), $request->getPayload()->getString('_token'))) {
|
return $this->render('menu_item/show.html.twig', [
|
||||||
$menuItem->delete();
|
'menu_item' => $menuItem,
|
||||||
$entityManager->flush();
|
]);
|
||||||
}
|
|
||||||
|
|
||||||
return $this->redirectToRoute('app_food_vendor_show', [
|
|
||||||
'id' => $menuItem->getFoodVendor()
|
|
||||||
->getId(),
|
|
||||||
], Response::HTTP_SEE_OTHER);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,62 +16,6 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||||
#[Route('/order/item')]
|
#[Route('/order/item')]
|
||||||
final class OrderItemController extends AbstractController
|
final class OrderItemController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route('/new/{foodOrder}', name: 'app_order_item_new', methods: ['GET', 'POST'])]
|
|
||||||
public function new(Request $request, FoodOrder $foodOrder, EntityManagerInterface $entityManager, MenuItemRepository $menuItemRepository): Response
|
|
||||||
{
|
|
||||||
if ($foodOrder->isClosed()) {
|
|
||||||
return $this->redirectToRoute('app_food_order_show', [
|
|
||||||
'id' => $foodOrder->getId(),
|
|
||||||
], Response::HTTP_SEE_OTHER);
|
|
||||||
}
|
|
||||||
|
|
||||||
$orderItem = new OrderItem;
|
|
||||||
$username = $request->cookies->get('username', 'nobody');
|
|
||||||
$orderItem->setCreatedBy($username);
|
|
||||||
|
|
||||||
$form = $this->createForm(OrderItemType::class, $orderItem);
|
|
||||||
$form->handleRequest($request);
|
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
|
||||||
$menuItem = $menuItemRepository->findOneBy([
|
|
||||||
'name' => $orderItem->getName(),
|
|
||||||
'foodVendor' => $foodOrder->getFoodVendor(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($menuItem === null) {
|
|
||||||
$menuItem = new MenuItem;
|
|
||||||
$menuItem->setName($orderItem->getName());
|
|
||||||
$menuItem->setFoodVendor($foodOrder->getFoodVendor());
|
|
||||||
$entityManager->persist($menuItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($menuItem->getAliasOf() !== null) {
|
|
||||||
$menuItem = $menuItem->getAliasOf();
|
|
||||||
$orderItem->setName($menuItem->getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
$orderItem->setMenuItem($menuItem);
|
|
||||||
$orderItem->setFoodOrder($foodOrder);
|
|
||||||
$entityManager->persist($orderItem);
|
|
||||||
$entityManager->flush();
|
|
||||||
|
|
||||||
return $this->redirectToRoute('app_food_order_show', [
|
|
||||||
'id' => $foodOrder->getId(),
|
|
||||||
], Response::HTTP_SEE_OTHER);
|
|
||||||
}
|
|
||||||
$menuItems = $menuItemRepository->findBy([
|
|
||||||
'foodVendor' => $foodOrder->getFoodVendor(),
|
|
||||||
'deletedAt' => null,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $this->render('order_item/new.html.twig', [
|
|
||||||
'order_item' => $orderItem,
|
|
||||||
'food_order' => $foodOrder,
|
|
||||||
'form' => $form,
|
|
||||||
'menuItems' => $menuItems,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Route('/{id}/copy', name: 'app_order_item_copy', methods: ['GET'])]
|
#[Route('/{id}/copy', name: 'app_order_item_copy', methods: ['GET'])]
|
||||||
public function copy(OrderItem $orderItem, EntityManagerInterface $entityManager): Response
|
public function copy(OrderItem $orderItem, EntityManagerInterface $entityManager): Response
|
||||||
{
|
{
|
||||||
|
@ -95,6 +39,23 @@ final class OrderItemController extends AbstractController
|
||||||
], Response::HTTP_SEE_OTHER);
|
], Response::HTTP_SEE_OTHER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route('/delete/{id}', name: 'app_order_item_delete')]
|
||||||
|
public function delete(OrderItem $orderItem, EntityManagerInterface $entityManager): Response
|
||||||
|
{
|
||||||
|
$foodOrder = $orderItem->getFoodOrder();
|
||||||
|
if ($foodOrder->isClosed()) {
|
||||||
|
return $this->redirectToRoute('app_food_order_show', [
|
||||||
|
'id' => $foodOrder->getId(),
|
||||||
|
], Response::HTTP_SEE_OTHER);
|
||||||
|
}
|
||||||
|
$entityManager->remove($orderItem);
|
||||||
|
$entityManager->flush();
|
||||||
|
return $this->redirectToRoute('app_food_order_show', [
|
||||||
|
'id' => $orderItem->getFoodOrder()
|
||||||
|
->getId(),
|
||||||
|
], Response::HTTP_SEE_OTHER);
|
||||||
|
}
|
||||||
|
|
||||||
#[Route('/{id}/edit', name: 'app_order_item_edit', methods: ['GET', 'POST'])]
|
#[Route('/{id}/edit', name: 'app_order_item_edit', methods: ['GET', 'POST'])]
|
||||||
public function edit(
|
public function edit(
|
||||||
Request $request,
|
Request $request,
|
||||||
|
@ -143,20 +104,59 @@ final class OrderItemController extends AbstractController
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/delete/{id}', name: 'app_order_item_delete')]
|
#[Route('/new/{foodOrder}', name: 'app_order_item_new', methods: ['GET', 'POST'])]
|
||||||
public function delete(OrderItem $orderItem, EntityManagerInterface $entityManager): Response
|
public function new(Request $request, FoodOrder $foodOrder, EntityManagerInterface $entityManager, MenuItemRepository $menuItemRepository): Response
|
||||||
{
|
{
|
||||||
$foodOrder = $orderItem->getFoodOrder();
|
|
||||||
if ($foodOrder->isClosed()) {
|
if ($foodOrder->isClosed()) {
|
||||||
return $this->redirectToRoute('app_food_order_show', [
|
return $this->redirectToRoute('app_food_order_show', [
|
||||||
'id' => $foodOrder->getId(),
|
'id' => $foodOrder->getId(),
|
||||||
], Response::HTTP_SEE_OTHER);
|
], Response::HTTP_SEE_OTHER);
|
||||||
}
|
}
|
||||||
$entityManager->remove($orderItem);
|
|
||||||
|
$orderItem = new OrderItem;
|
||||||
|
$username = $request->cookies->get('username', 'nobody');
|
||||||
|
$orderItem->setCreatedBy($username);
|
||||||
|
|
||||||
|
$form = $this->createForm(OrderItemType::class, $orderItem);
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
$menuItem = $menuItemRepository->findOneBy([
|
||||||
|
'name' => $orderItem->getName(),
|
||||||
|
'foodVendor' => $foodOrder->getFoodVendor(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($menuItem === null) {
|
||||||
|
$menuItem = new MenuItem;
|
||||||
|
$menuItem->setName($orderItem->getName());
|
||||||
|
$menuItem->setFoodVendor($foodOrder->getFoodVendor());
|
||||||
|
$entityManager->persist($menuItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($menuItem->getAliasOf() !== null) {
|
||||||
|
$menuItem = $menuItem->getAliasOf();
|
||||||
|
$orderItem->setName($menuItem->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
$orderItem->setMenuItem($menuItem);
|
||||||
|
$orderItem->setFoodOrder($foodOrder);
|
||||||
|
$entityManager->persist($orderItem);
|
||||||
$entityManager->flush();
|
$entityManager->flush();
|
||||||
|
|
||||||
return $this->redirectToRoute('app_food_order_show', [
|
return $this->redirectToRoute('app_food_order_show', [
|
||||||
'id' => $orderItem->getFoodOrder()
|
'id' => $foodOrder->getId(),
|
||||||
->getId(),
|
|
||||||
], Response::HTTP_SEE_OTHER);
|
], Response::HTTP_SEE_OTHER);
|
||||||
}
|
}
|
||||||
|
$menuItems = $menuItemRepository->findBy([
|
||||||
|
'foodVendor' => $foodOrder->getFoodVendor(),
|
||||||
|
'deletedAt' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->render('order_item/new.html.twig', [
|
||||||
|
'order_item' => $orderItem,
|
||||||
|
'food_order' => $foodOrder,
|
||||||
|
'form' => $form,
|
||||||
|
'menuItems' => $menuItems,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,29 +16,6 @@ final class AppFixtures extends Fixture
|
||||||
{
|
{
|
||||||
private ObjectManager $manager;
|
private ObjectManager $manager;
|
||||||
|
|
||||||
#[Override]
|
|
||||||
public function load(ObjectManager $manager): void
|
|
||||||
{
|
|
||||||
$this->manager = $manager;
|
|
||||||
$vendorA = $this->createVendor('Vendor A');
|
|
||||||
$this->addMenuItemsToVendor($vendorA);
|
|
||||||
|
|
||||||
$vendorB = $this->createVendor('Vendor B');
|
|
||||||
$this->addMenuItemsToVendor($vendorB);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createVendor(string $name): FoodVendor
|
|
||||||
{
|
|
||||||
$vendorA = new FoodVendor;
|
|
||||||
$vendorA->setName($name);
|
|
||||||
$vendorA->setMenuLink('https://vendora.com');
|
|
||||||
$vendorA->setPhone('1234567890');
|
|
||||||
|
|
||||||
$this->manager->persist($vendorA);
|
|
||||||
$this->manager->flush();
|
|
||||||
return $vendorA;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addMenuItemsToVendor(FoodVendor $vendor): void
|
public function addMenuItemsToVendor(FoodVendor $vendor): void
|
||||||
{
|
{
|
||||||
$menuItems = [];
|
$menuItems = [];
|
||||||
|
@ -63,4 +40,27 @@ final class AppFixtures extends Fixture
|
||||||
$this->manager->persist($orderItem);
|
$this->manager->persist($orderItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createVendor(string $name): FoodVendor
|
||||||
|
{
|
||||||
|
$vendorA = new FoodVendor;
|
||||||
|
$vendorA->setName($name);
|
||||||
|
$vendorA->setMenuLink('https://vendora.com');
|
||||||
|
$vendorA->setPhone('1234567890');
|
||||||
|
|
||||||
|
$this->manager->persist($vendorA);
|
||||||
|
$this->manager->flush();
|
||||||
|
return $vendorA;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Override]
|
||||||
|
public function load(ObjectManager $manager): void
|
||||||
|
{
|
||||||
|
$this->manager = $manager;
|
||||||
|
$vendorA = $this->createVendor('Vendor A');
|
||||||
|
$this->addMenuItemsToVendor($vendorA);
|
||||||
|
|
||||||
|
$vendorB = $this->createVendor('Vendor B');
|
||||||
|
$this->addMenuItemsToVendor($vendorB);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,32 +47,32 @@ use function iterator_to_array;
|
||||||
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
|
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
|
||||||
class FoodOrder
|
class FoodOrder
|
||||||
{
|
{
|
||||||
#[ORM\Column(nullable: true)]
|
|
||||||
#[Groups(['food_order:read'])]
|
#[Groups(['food_order:read'])]
|
||||||
|
#[ORM\Column(nullable: true)]
|
||||||
private DateTimeImmutable|null $closedAt = null;
|
private DateTimeImmutable|null $closedAt = null;
|
||||||
|
|
||||||
#[ORM\ManyToOne(inversedBy: 'foodOrders')]
|
#[Groups(['food_order:read'])]
|
||||||
#[ORM\JoinColumn(nullable: false)]
|
#[ORM\Column(length: 255, options: [
|
||||||
|
'default' => 'nobody',
|
||||||
|
])]
|
||||||
|
private string|null $createdBy = 'nobody';
|
||||||
|
|
||||||
#[Groups(['food_order:read', 'food_order:latest'])]
|
#[Groups(['food_order:read', 'food_order:latest'])]
|
||||||
|
#[ORM\JoinColumn(nullable: false)]
|
||||||
|
#[ORM\ManyToOne(inversedBy: 'foodOrders')]
|
||||||
private FoodVendor|null $foodVendor = null;
|
private FoodVendor|null $foodVendor = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Collection<int, OrderItem>
|
* @var Collection<int, OrderItem>
|
||||||
*/
|
*/
|
||||||
#[ORM\OneToMany(targetEntity: OrderItem::class, mappedBy: 'foodOrder', orphanRemoval: true)]
|
|
||||||
#[Groups(['food_order:read', 'food_order:latest'])]
|
#[Groups(['food_order:read', 'food_order:latest'])]
|
||||||
|
#[ORM\OneToMany(targetEntity: OrderItem::class, mappedBy: 'foodOrder', orphanRemoval: true)]
|
||||||
private Collection $orderItems;
|
private Collection $orderItems;
|
||||||
|
|
||||||
#[ORM\Column(length: 255, options: [
|
|
||||||
'default' => 'nobody',
|
|
||||||
])]
|
|
||||||
#[Groups(['food_order:read'])]
|
|
||||||
private string|null $createdBy = 'nobody';
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[ORM\Id]
|
|
||||||
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
|
||||||
#[Groups(['food_order:read'])]
|
#[Groups(['food_order:read'])]
|
||||||
|
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
||||||
|
#[ORM\Id]
|
||||||
private Ulid|null $id = new Ulid
|
private Ulid|null $id = new Ulid
|
||||||
) {
|
) {
|
||||||
$this->id ??= new Ulid;
|
$this->id ??= new Ulid;
|
||||||
|
@ -80,9 +80,24 @@ class FoodOrder
|
||||||
$this->open();
|
$this->open();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): Ulid|null
|
public function addOrderItem(OrderItem $orderItem): static
|
||||||
{
|
{
|
||||||
return $this->id;
|
if (! $this->orderItems->contains($orderItem)) {
|
||||||
|
$this->orderItems->add($orderItem);
|
||||||
|
$orderItem->setFoodOrder($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function close(): static
|
||||||
|
{
|
||||||
|
return $this->setClosedAt(new DateTimeImmutable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getClosedAt(): DateTimeImmutable|null
|
||||||
|
{
|
||||||
|
return $this->closedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Groups(['food_order:read'])]
|
#[Groups(['food_order:read'])]
|
||||||
|
@ -91,35 +106,9 @@ class FoodOrder
|
||||||
return $this->id->getDateTime();
|
return $this->id->getDateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getClosedAt(): DateTimeImmutable|null
|
public function getCreatedBy(): string|null
|
||||||
{
|
{
|
||||||
return $this->closedAt;
|
return $this->createdBy;
|
||||||
}
|
|
||||||
|
|
||||||
public function setClosedAt(DateTimeImmutable|null $closedAt = null): static
|
|
||||||
{
|
|
||||||
$this->closedAt = $closedAt;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isClosed(): bool
|
|
||||||
{
|
|
||||||
if (! $this->closedAt instanceof DateTimeImmutable) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return $this->closedAt < new DateTimeImmutable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function close(): static
|
|
||||||
{
|
|
||||||
return $this->setClosedAt(new DateTimeImmutable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function open(): static
|
|
||||||
{
|
|
||||||
$this->closedAt = (new DateTimeImmutable)->add(new DateInterval('PT1H'));
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFoodVendor(): FoodVendor|null
|
public function getFoodVendor(): FoodVendor|null
|
||||||
|
@ -127,11 +116,9 @@ class FoodOrder
|
||||||
return $this->foodVendor;
|
return $this->foodVendor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setFoodVendor(FoodVendor|null $foodVendor): static
|
public function getId(): Ulid|null
|
||||||
{
|
{
|
||||||
$this->foodVendor = $foodVendor;
|
return $this->id;
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -159,13 +146,17 @@ class FoodOrder
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addOrderItem(OrderItem $orderItem): static
|
public function isClosed(): bool
|
||||||
{
|
{
|
||||||
if (! $this->orderItems->contains($orderItem)) {
|
if (! $this->closedAt instanceof DateTimeImmutable) {
|
||||||
$this->orderItems->add($orderItem);
|
return false;
|
||||||
$orderItem->setFoodOrder($this);
|
}
|
||||||
|
return $this->closedAt < new DateTimeImmutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function open(): static
|
||||||
|
{
|
||||||
|
$this->closedAt = (new DateTimeImmutable)->add(new DateInterval('PT1H'));
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,9 +170,11 @@ class FoodOrder
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCreatedBy(): string|null
|
public function setClosedAt(DateTimeImmutable|null $closedAt = null): static
|
||||||
{
|
{
|
||||||
return $this->createdBy;
|
$this->closedAt = $closedAt;
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCreatedBy(string $createdBy): static
|
public function setCreatedBy(string $createdBy): static
|
||||||
|
@ -190,4 +183,11 @@ class FoodOrder
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setFoodVendor(FoodVendor|null $foodVendor): static
|
||||||
|
{
|
||||||
|
$this->foodVendor = $foodVendor;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,19 +16,17 @@ use Symfony\Component\Validator\Constraints\Length;
|
||||||
|
|
||||||
use function mb_strlen;
|
use function mb_strlen;
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: FoodVendorRepository::class)]
|
|
||||||
#[ApiResource]
|
#[ApiResource]
|
||||||
|
#[ORM\Entity(repositoryClass: FoodVendorRepository::class)]
|
||||||
class FoodVendor
|
class FoodVendor
|
||||||
{
|
{
|
||||||
#[ORM\Column(length: 50)]
|
/**
|
||||||
|
* String of emojis (max 30 characters)
|
||||||
|
*/
|
||||||
#[Groups(['food_order:latest', 'food_vendor:read'])]
|
#[Groups(['food_order:latest', 'food_vendor:read'])]
|
||||||
private string|null $name = null;
|
#[Length(max: 10)]
|
||||||
|
#[ORM\Column(length: 30, nullable: true)]
|
||||||
#[ORM\Column(length: 50, nullable: true, options: [
|
private string|null $emojis = null;
|
||||||
'default' => '',
|
|
||||||
])]
|
|
||||||
#[Groups(['food_order:latest', 'food_vendor:read'])]
|
|
||||||
private string|null $phone = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Collection<int, FoodOrder>
|
* @var Collection<int, FoodOrder>
|
||||||
|
@ -42,24 +40,26 @@ class FoodVendor
|
||||||
#[ORM\OneToMany(targetEntity: MenuItem::class, mappedBy: 'foodVendor', orphanRemoval: true)]
|
#[ORM\OneToMany(targetEntity: MenuItem::class, mappedBy: 'foodVendor', orphanRemoval: true)]
|
||||||
private Collection $menuItems;
|
private Collection $menuItems;
|
||||||
|
|
||||||
#[ORM\Column(length: 255, nullable: true)]
|
|
||||||
#[Groups(['food_order:latest'])]
|
#[Groups(['food_order:latest'])]
|
||||||
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
private string|null $menuLink = null;
|
private string|null $menuLink = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* String of emojis (max 30 characters)
|
|
||||||
*/
|
|
||||||
#[ORM\Column(length: 30, nullable: true)]
|
|
||||||
#[Groups(['food_order:latest', 'food_vendor:read'])]
|
#[Groups(['food_order:latest', 'food_vendor:read'])]
|
||||||
#[Length(max: 10)]
|
#[ORM\Column(length: 50)]
|
||||||
private string|null $emojis = null;
|
private string|null $name = null;
|
||||||
|
|
||||||
|
#[Groups(['food_order:latest', 'food_vendor:read'])]
|
||||||
|
#[ORM\Column(length: 50, nullable: true, options: [
|
||||||
|
'default' => '',
|
||||||
|
])]
|
||||||
|
private string|null $phone = null;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[ORM\Id]
|
#[Groups(['food_order:latest'])]
|
||||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
|
||||||
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
||||||
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
||||||
#[Groups(['food_order:latest'])]
|
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||||
|
#[ORM\Id]
|
||||||
private Ulid|null $id = new Ulid
|
private Ulid|null $id = new Ulid
|
||||||
) {
|
) {
|
||||||
$this->id ??= new Ulid;
|
$this->id ??= new Ulid;
|
||||||
|
@ -67,31 +67,6 @@ class FoodVendor
|
||||||
$this->menuItems = new ArrayCollection;
|
$this->menuItems = new ArrayCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): Ulid|null
|
|
||||||
{
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName(): string|null
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setName(string $name): static
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Collection<int, FoodOrder>
|
|
||||||
*/
|
|
||||||
public function getFoodOrders(): Collection
|
|
||||||
{
|
|
||||||
return $this->foodOrders;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addFoodOrder(FoodOrder $foodOrder): static
|
public function addFoodOrder(FoodOrder $foodOrder): static
|
||||||
{
|
{
|
||||||
if (! $this->foodOrders->contains($foodOrder)) {
|
if (! $this->foodOrders->contains($foodOrder)) {
|
||||||
|
@ -102,16 +77,34 @@ class FoodVendor
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeFoodOrder(FoodOrder $foodOrder): static
|
public function addMenuItem(MenuItem $menuItem): static
|
||||||
{
|
{
|
||||||
// set the owning side to null (unless already changed)
|
if (! $this->menuItems->contains($menuItem)) {
|
||||||
if ($this->foodOrders->removeElement($foodOrder)) {
|
$this->menuItems->add($menuItem);
|
||||||
$foodOrder->setFoodVendor(null);
|
$menuItem->setFoodVendor($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getEmojis(): string|null
|
||||||
|
{
|
||||||
|
return $this->emojis;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, FoodOrder>
|
||||||
|
*/
|
||||||
|
public function getFoodOrders(): Collection
|
||||||
|
{
|
||||||
|
return $this->foodOrders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getId(): Ulid|null
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection<int, MenuItem>
|
* @return Collection<int, MenuItem>
|
||||||
*/
|
*/
|
||||||
|
@ -125,11 +118,26 @@ class FoodVendor
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addMenuItem(MenuItem $menuItem): static
|
public function getMenuLink(): string|null
|
||||||
{
|
{
|
||||||
if (! $this->menuItems->contains($menuItem)) {
|
return $this->menuLink;
|
||||||
$this->menuItems->add($menuItem);
|
}
|
||||||
$menuItem->setFoodVendor($this);
|
|
||||||
|
public function getName(): string|null
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPhone(): string|null
|
||||||
|
{
|
||||||
|
return $this->phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeFoodOrder(FoodOrder $foodOrder): static
|
||||||
|
{
|
||||||
|
// set the owning side to null (unless already changed)
|
||||||
|
if ($this->foodOrders->removeElement($foodOrder)) {
|
||||||
|
$foodOrder->setFoodVendor(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -145,34 +153,6 @@ class FoodVendor
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMenuLink(): string|null
|
|
||||||
{
|
|
||||||
return $this->menuLink;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setMenuLink(string|null $menuLink): static
|
|
||||||
{
|
|
||||||
$this->menuLink = $menuLink;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPhone(): string|null
|
|
||||||
{
|
|
||||||
return $this->phone;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setPhone(string|null $phone): static
|
|
||||||
{
|
|
||||||
$this->phone = $phone;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getEmojis(): string|null
|
|
||||||
{
|
|
||||||
return $this->emojis;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setEmojis(string|null $emojis): static
|
public function setEmojis(string|null $emojis): static
|
||||||
{
|
{
|
||||||
if ($emojis !== null && mb_strlen($emojis) > 30) {
|
if ($emojis !== null && mb_strlen($emojis) > 30) {
|
||||||
|
@ -182,4 +162,24 @@ class FoodVendor
|
||||||
$this->emojis = $emojis;
|
$this->emojis = $emojis;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setMenuLink(string|null $menuLink): static
|
||||||
|
{
|
||||||
|
$this->menuLink = $menuLink;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName(string $name): static
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPhone(string|null $phone): static
|
||||||
|
{
|
||||||
|
$this->phone = $phone;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,108 +16,36 @@ use Symfony\Component\Uid\Ulid;
|
||||||
#[ORM\Entity(repositoryClass: MenuItemRepository::class)]
|
#[ORM\Entity(repositoryClass: MenuItemRepository::class)]
|
||||||
class MenuItem
|
class MenuItem
|
||||||
{
|
{
|
||||||
#[ORM\Column(length: 255)]
|
|
||||||
private string|null $name = null;
|
|
||||||
|
|
||||||
#[ORM\ManyToOne(inversedBy: 'menuItems')]
|
|
||||||
#[ORM\JoinColumn(nullable: false)]
|
|
||||||
private FoodVendor|null $foodVendor = null;
|
|
||||||
|
|
||||||
#[ORM\Column(nullable: true)]
|
|
||||||
private DateTimeImmutable|null $deletedAt = null;
|
|
||||||
|
|
||||||
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'aliases')]
|
|
||||||
private self|null $aliasOf = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Collection<int, self>
|
* @var Collection<int, self>
|
||||||
*/
|
*/
|
||||||
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'aliasOf')]
|
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'aliasOf')]
|
||||||
private Collection $aliases;
|
private Collection $aliases;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'aliases')]
|
||||||
|
private self|null $aliasOf = null;
|
||||||
|
|
||||||
|
#[ORM\Column(nullable: true)]
|
||||||
|
private DateTimeImmutable|null $deletedAt = null;
|
||||||
|
|
||||||
|
#[ORM\JoinColumn(nullable: false)]
|
||||||
|
#[ORM\ManyToOne(inversedBy: 'menuItems')]
|
||||||
|
private FoodVendor|null $foodVendor = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private string|null $name = null;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[ORM\Id]
|
|
||||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
|
||||||
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
||||||
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
||||||
|
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||||
|
#[ORM\Id]
|
||||||
private Ulid|null $id = new Ulid
|
private Ulid|null $id = new Ulid
|
||||||
) {
|
) {
|
||||||
$this->id ??= new Ulid;
|
$this->id ??= new Ulid;
|
||||||
$this->aliases = new ArrayCollection;
|
$this->aliases = new ArrayCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): Ulid|null
|
|
||||||
{
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName(): string|null
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setName(string $name): static
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFoodVendor(): FoodVendor|null
|
|
||||||
{
|
|
||||||
return $this->foodVendor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setFoodVendor(FoodVendor|null $foodVendor): static
|
|
||||||
{
|
|
||||||
$this->foodVendor = $foodVendor;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isDeleted(): bool
|
|
||||||
{
|
|
||||||
return $this->getDeletedAt() instanceof DateTimeImmutable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete(): static
|
|
||||||
{
|
|
||||||
$this->setDeletedAt(new DateTimeImmutable);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDeletedAt(): DateTimeImmutable|null
|
|
||||||
{
|
|
||||||
return $this->deletedAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setDeletedAt(DateTimeImmutable|null $deletedAt = new DateTimeImmutable): static
|
|
||||||
{
|
|
||||||
$this->deletedAt = $deletedAt;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAliasOf(): self|null
|
|
||||||
{
|
|
||||||
return $this->aliasOf;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setAliasOf(self|null $aliasOf): static
|
|
||||||
{
|
|
||||||
$this->aliasOf = $aliasOf;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Collection<int, self>
|
|
||||||
*/
|
|
||||||
public function getAliases(): Collection
|
|
||||||
{
|
|
||||||
return $this->aliases;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addAlias(self $alias): static
|
public function addAlias(self $alias): static
|
||||||
{
|
{
|
||||||
if (! $this->aliases->contains($alias)) {
|
if (! $this->aliases->contains($alias)) {
|
||||||
|
@ -128,6 +56,50 @@ class MenuItem
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function delete(): static
|
||||||
|
{
|
||||||
|
$this->setDeletedAt(new DateTimeImmutable);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, self>
|
||||||
|
*/
|
||||||
|
public function getAliases(): Collection
|
||||||
|
{
|
||||||
|
return $this->aliases;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAliasOf(): self|null
|
||||||
|
{
|
||||||
|
return $this->aliasOf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDeletedAt(): DateTimeImmutable|null
|
||||||
|
{
|
||||||
|
return $this->deletedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFoodVendor(): FoodVendor|null
|
||||||
|
{
|
||||||
|
return $this->foodVendor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getId(): Ulid|null
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(): string|null
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDeleted(): bool
|
||||||
|
{
|
||||||
|
return $this->getDeletedAt() instanceof DateTimeImmutable;
|
||||||
|
}
|
||||||
|
|
||||||
public function removeAlias(self $alias): static
|
public function removeAlias(self $alias): static
|
||||||
{
|
{
|
||||||
// set the owning side to null (unless already changed)
|
// set the owning side to null (unless already changed)
|
||||||
|
@ -137,4 +109,32 @@ class MenuItem
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setAliasOf(self|null $aliasOf): static
|
||||||
|
{
|
||||||
|
$this->aliasOf = $aliasOf;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDeletedAt(DateTimeImmutable|null $deletedAt = new DateTimeImmutable): static
|
||||||
|
{
|
||||||
|
$this->deletedAt = $deletedAt;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFoodVendor(FoodVendor|null $foodVendor): static
|
||||||
|
{
|
||||||
|
$this->foodVendor = $foodVendor;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName(string $name): static
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,62 +14,77 @@ use Symfony\Component\Uid\Ulid;
|
||||||
#[ORM\Entity(repositoryClass: OrderItemRepository::class)]
|
#[ORM\Entity(repositoryClass: OrderItemRepository::class)]
|
||||||
class OrderItem
|
class OrderItem
|
||||||
{
|
{
|
||||||
#[ORM\Column(length: 255)]
|
|
||||||
#[Groups(['food_order:latest'])]
|
#[Groups(['food_order:latest'])]
|
||||||
private string|null $name = null;
|
|
||||||
|
|
||||||
#[ORM\Column(length: 255, nullable: true)]
|
|
||||||
#[Groups(['food_order:latest'])]
|
|
||||||
private string|null $extras = null;
|
|
||||||
|
|
||||||
#[ORM\ManyToOne(inversedBy: 'orderItems')]
|
|
||||||
#[ORM\JoinColumn(nullable: true)]
|
|
||||||
private FoodOrder|null $foodOrder = null;
|
|
||||||
|
|
||||||
#[ORM\ManyToOne]
|
|
||||||
#[ORM\JoinColumn(nullable: false)]
|
|
||||||
#[Groups(['food_order:latest'])]
|
|
||||||
private MenuItem|null $menuItem = null;
|
|
||||||
|
|
||||||
#[ORM\Column(length: 255, options: [
|
#[ORM\Column(length: 255, options: [
|
||||||
'default' => 'nobody',
|
'default' => 'nobody',
|
||||||
])]
|
])]
|
||||||
#[Groups(['food_order:latest'])]
|
|
||||||
private string|null $createdBy = 'nobody';
|
private string|null $createdBy = 'nobody';
|
||||||
|
|
||||||
|
#[Groups(['food_order:latest'])]
|
||||||
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
|
private string|null $extras = null;
|
||||||
|
|
||||||
|
#[ORM\JoinColumn(nullable: true)]
|
||||||
|
#[ORM\ManyToOne(inversedBy: 'orderItems')]
|
||||||
|
private FoodOrder|null $foodOrder = null;
|
||||||
|
|
||||||
|
#[Groups(['food_order:latest'])]
|
||||||
|
#[ORM\JoinColumn(nullable: false)]
|
||||||
|
#[ORM\ManyToOne]
|
||||||
|
private MenuItem|null $menuItem = null;
|
||||||
|
|
||||||
|
#[Groups(['food_order:latest'])]
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private string|null $name = null;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[ORM\Id]
|
#[Groups(['food_order:latest'])]
|
||||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
|
||||||
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
||||||
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
||||||
#[Groups(['food_order:latest'])]
|
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||||
|
#[ORM\Id]
|
||||||
private Ulid|null $id = new Ulid
|
private Ulid|null $id = new Ulid
|
||||||
) {
|
) {
|
||||||
$this->id ??= new Ulid;
|
$this->id ??= new Ulid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCreatedBy(): string|null
|
||||||
|
{
|
||||||
|
return $this->createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getExtras(): string|null
|
||||||
|
{
|
||||||
|
return $this->extras;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFoodOrder(): FoodOrder|null
|
||||||
|
{
|
||||||
|
return $this->foodOrder;
|
||||||
|
}
|
||||||
|
|
||||||
public function getId(): Ulid|null
|
public function getId(): Ulid|null
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMenuItem(): MenuItem|null
|
||||||
|
{
|
||||||
|
return $this->menuItem;
|
||||||
|
}
|
||||||
|
|
||||||
public function getName(): string|null
|
public function getName(): string|null
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setName(string $name): static
|
public function setCreatedBy(string $createdBy): static
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->createdBy = $createdBy;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getExtras(): string|null
|
|
||||||
{
|
|
||||||
return $this->extras;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setExtras(string|null $extras): static
|
public function setExtras(string|null $extras): static
|
||||||
{
|
{
|
||||||
$this->extras = $extras;
|
$this->extras = $extras;
|
||||||
|
@ -77,11 +92,6 @@ class OrderItem
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFoodOrder(): FoodOrder|null
|
|
||||||
{
|
|
||||||
return $this->foodOrder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setFoodOrder(FoodOrder|null $foodOrder): static
|
public function setFoodOrder(FoodOrder|null $foodOrder): static
|
||||||
{
|
{
|
||||||
$this->foodOrder = $foodOrder;
|
$this->foodOrder = $foodOrder;
|
||||||
|
@ -89,11 +99,6 @@ class OrderItem
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMenuItem(): MenuItem|null
|
|
||||||
{
|
|
||||||
return $this->menuItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setMenuItem(MenuItem|null $menuItem): static
|
public function setMenuItem(MenuItem|null $menuItem): static
|
||||||
{
|
{
|
||||||
$this->menuItem = $menuItem;
|
$this->menuItem = $menuItem;
|
||||||
|
@ -102,14 +107,9 @@ class OrderItem
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCreatedBy(): string|null
|
public function setName(string $name): static
|
||||||
{
|
{
|
||||||
return $this->createdBy;
|
$this->name = $name;
|
||||||
}
|
|
||||||
|
|
||||||
public function setCreatedBy(string $createdBy): static
|
|
||||||
{
|
|
||||||
$this->createdBy = $createdBy;
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,6 @@ final class FoodOrderRepository extends ServiceEntityRepository
|
||||||
parent::__construct($registry, FoodOrder::class);
|
parent::__construct($registry, FoodOrder::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save(): void
|
|
||||||
{
|
|
||||||
$this->getEntityManager()
|
|
||||||
->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return FoodOrder[]
|
* @return FoodOrder[]
|
||||||
*/
|
*/
|
||||||
|
@ -48,6 +42,15 @@ final class FoodOrderRepository extends ServiceEntityRepository
|
||||||
->getValues();
|
->getValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findLatestOrder(): FoodOrder|null
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('alias')
|
||||||
|
->orderBy('alias.id', 'DESC')
|
||||||
|
->setMaxResults(1)
|
||||||
|
->getQuery()
|
||||||
|
->getOneOrNullResult();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return FoodOrder[]
|
* @return FoodOrder[]
|
||||||
*/
|
*/
|
||||||
|
@ -63,12 +66,9 @@ final class FoodOrderRepository extends ServiceEntityRepository
|
||||||
->getResult();
|
->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findLatestOrder(): FoodOrder|null
|
public function save(): void
|
||||||
{
|
{
|
||||||
return $this->createQueryBuilder('alias')
|
$this->getEntityManager()
|
||||||
->orderBy('alias.id', 'DESC')
|
->flush();
|
||||||
->setMaxResults(1)
|
|
||||||
->getQuery()
|
|
||||||
->getOneOrNullResult();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
{
|
{
|
||||||
"api-platform/core": {
|
"api-platform/symfony": {
|
||||||
"version": "4.1",
|
"version": "4.1",
|
||||||
"recipe": {
|
"recipe": {
|
||||||
"repo": "github.com/symfony/recipes",
|
"repo": "github.com/symfony/recipes",
|
||||||
"branch": "main",
|
"branch": "main",
|
||||||
"version": "4.0",
|
"version": "4.0",
|
||||||
"ref": "cb9e6b8ceb9b62f32d41fc8ad72a25d5bd674c6d"
|
"ref": "e9952e9f393c2d048f10a78f272cd35e807d972b"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"config/packages/api_platform.yaml",
|
"config/packages/api_platform.yaml",
|
||||||
|
|
|
@ -18,10 +18,10 @@ use function str_contains;
|
||||||
abstract class DbWebTest extends WebTestCase
|
abstract class DbWebTest extends WebTestCase
|
||||||
{
|
{
|
||||||
protected KernelBrowser $client;
|
protected KernelBrowser $client;
|
||||||
protected EntityManagerInterface $manager;
|
|
||||||
protected EntityRepository $repository;
|
|
||||||
protected string $entityClass = '';
|
protected string $entityClass = '';
|
||||||
|
protected EntityManagerInterface $manager;
|
||||||
protected string $path = '';
|
protected string $path = '';
|
||||||
|
protected EntityRepository $repository;
|
||||||
|
|
||||||
#[Override]
|
#[Override]
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
|
@ -35,13 +35,6 @@ abstract class DbWebTest extends WebTestCase
|
||||||
$schemaTool->updateSchema($metadata);
|
$schemaTool->updateSchema($metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function generateOldUlid(int $daysToSubtract = 10): Ulid
|
|
||||||
{
|
|
||||||
$date = (new DateTimeImmutable)->sub(new DateInterval('P' . $daysToSubtract . 'D'));
|
|
||||||
$ulidString = Ulid::generate($date);
|
|
||||||
return Ulid::fromString($ulidString);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function assertElementContainsCount(Crawler $crawler, string $element, int $count, string $text): void
|
protected function assertElementContainsCount(Crawler $crawler, string $element, int $count, string $text): void
|
||||||
{
|
{
|
||||||
$this->assertCount(
|
$this->assertCount(
|
||||||
|
@ -53,6 +46,13 @@ abstract class DbWebTest extends WebTestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function generateOldUlid(int $daysToSubtract = 10): Ulid
|
||||||
|
{
|
||||||
|
$date = (new DateTimeImmutable)->sub(new DateInterval('P' . $daysToSubtract . 'D'));
|
||||||
|
$ulidString = Ulid::generate($date);
|
||||||
|
return Ulid::fromString($ulidString);
|
||||||
|
}
|
||||||
|
|
||||||
protected function setEntityClass(string $entityClass): void
|
protected function setEntityClass(string $entityClass): void
|
||||||
{
|
{
|
||||||
$this->entityClass = $entityClass;
|
$this->entityClass = $entityClass;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue