forked from lubiana/futtern
api api
This commit is contained in:
parent
9d2f0204e3
commit
ee32852789
12 changed files with 514 additions and 3 deletions
0
src/ApiResource/.gitignore
vendored
Normal file
0
src/ApiResource/.gitignore
vendored
Normal file
|
@ -2,7 +2,14 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use ApiPlatform\Metadata\Put;
|
||||
use App\Repository\FoodOrderRepository;
|
||||
use App\State\OpenOrdersProvider;
|
||||
use DateInterval;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
@ -13,6 +20,20 @@ use Symfony\Component\Uid\Ulid;
|
|||
|
||||
use function iterator_to_array;
|
||||
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new GetCollection(
|
||||
uriTemplate: 'food_orders/open',
|
||||
description: 'Get only open orders',
|
||||
provider: OpenOrdersProvider::class,
|
||||
),
|
||||
new GetCollection,
|
||||
new Get,
|
||||
new Post,
|
||||
new Put,
|
||||
new Delete,
|
||||
]
|
||||
)]
|
||||
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
|
||||
class FoodOrder
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use App\Repository\FoodVendorRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
@ -11,6 +12,7 @@ use Symfony\Bridge\Doctrine\Types\UlidType;
|
|||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
#[ORM\Entity(repositoryClass: FoodVendorRepository::class)]
|
||||
#[ApiResource]
|
||||
class FoodVendor
|
||||
{
|
||||
#[ORM\Column(length: 50)]
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use App\Repository\MenuItemRepository;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
@ -11,6 +12,7 @@ use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
|
|||
use Symfony\Bridge\Doctrine\Types\UlidType;
|
||||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
#[ApiResource]
|
||||
#[ORM\Entity(repositoryClass: MenuItemRepository::class)]
|
||||
class MenuItem
|
||||
{
|
||||
|
|
|
@ -2,12 +2,14 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use App\Repository\OrderItemRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
|
||||
use Symfony\Bridge\Doctrine\Types\UlidType;
|
||||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
#[ApiResource]
|
||||
#[ORM\Entity(repositoryClass: OrderItemRepository::class)]
|
||||
class OrderItem
|
||||
{
|
||||
|
|
25
src/State/OpenOrdersProvider.php
Normal file
25
src/State/OpenOrdersProvider.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\State;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Entity\FoodOrder;
|
||||
use App\Repository\FoodOrderRepository;
|
||||
use Override;
|
||||
|
||||
final readonly class OpenOrdersProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private FoodOrderRepository $repository
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return FoodOrder[]
|
||||
*/
|
||||
#[Override]
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): array
|
||||
{
|
||||
return $this->repository->findOpenOrders();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue