diff --git a/composer.json b/composer.json index f5568b9..43c32cd 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,8 @@ "php": ">=8.4", "ext-ctype": "*", "ext-iconv": "*", + "api-platform/doctrine-orm": "*", + "api-platform/symfony": "*", "doctrine/dbal": "^4.2.3", "doctrine/doctrine-bundle": "^2.14.1", "doctrine/doctrine-migrations-bundle": "^3.4.2", diff --git a/composer.lock b/composer.lock index 3658189..9c27807 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,224 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "960c510bab4f3f719a8433b77b0e6e47", + "content-hash": "c21233664fb5c4d25afb8a8cdc29213a", "packages": [ + { + "name": "api-platform/core", + "version": "v4.1.16", + "source": { + "type": "git", + "url": "https://github.com/api-platform/core.git", + "reference": "64ff50f9b7206e7ac324ea221537f753194889b3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/api-platform/core/zipball/64ff50f9b7206e7ac324ea221537f753194889b3", + "reference": "64ff50f9b7206e7ac324ea221537f753194889b3", + "shasum": "" + }, + "require": { + "doctrine/inflector": "^2.0", + "php": ">=8.2", + "psr/cache": "^1.0 || ^2.0 || ^3.0", + "psr/container": "^1.0 || ^2.0", + "symfony/deprecation-contracts": "^3.1", + "symfony/http-foundation": "^6.4 || ^7.0", + "symfony/http-kernel": "^6.4 || ^7.0", + "symfony/property-access": "^6.4 || ^7.0", + "symfony/property-info": "^6.4 || ^7.1", + "symfony/serializer": "^6.4 || ^7.0", + "symfony/translation-contracts": "^3.3", + "symfony/type-info": "^7.2", + "symfony/web-link": "^6.4 || ^7.1", + "willdurand/negotiation": "^3.1" + }, + "conflict": { + "doctrine/common": "<3.2.2", + "doctrine/dbal": "<2.10", + "doctrine/mongodb-odm": "<2.4", + "doctrine/orm": "<2.14.0", + "doctrine/persistence": "<1.3", + "phpspec/prophecy": "<1.15", + "phpunit/phpunit": "<9.5", + "symfony/framework-bundle": "6.4.6 || 7.0.6", + "symfony/var-exporter": "<6.1.1" + }, + "replace": { + "api-platform/doctrine-common": "self.version", + "api-platform/doctrine-odm": "self.version", + "api-platform/doctrine-orm": "self.version", + "api-platform/documentation": "self.version", + "api-platform/elasticsearch": "self.version", + "api-platform/graphql": "self.version", + "api-platform/http-cache": "self.version", + "api-platform/hydra": "self.version", + "api-platform/json-api": "self.version", + "api-platform/json-hal": "self.version", + "api-platform/json-schema": "self.version", + "api-platform/jsonld": "self.version", + "api-platform/laravel": "self.version", + "api-platform/metadata": "self.version", + "api-platform/openapi": "self.version", + "api-platform/parameter-validator": "self.version", + "api-platform/ramsey-uuid": "self.version", + "api-platform/serializer": "self.version", + "api-platform/state": "self.version", + "api-platform/symfony": "self.version", + "api-platform/validator": "self.version" + }, + "require-dev": { + "behat/behat": "^3.11", + "behat/mink": "^1.9", + "doctrine/cache": "^1.11 || ^2.1", + "doctrine/common": "^3.2.2", + "doctrine/dbal": "^4.0", + "doctrine/doctrine-bundle": "^2.11", + "doctrine/mongodb-odm": "^2.10", + "doctrine/mongodb-odm-bundle": "^5.0", + "doctrine/orm": "^2.17 || ^3.0", + "elasticsearch/elasticsearch": "^7.17 || ^8.4 || ^9.0", + "friends-of-behat/mink-browserkit-driver": "^1.3.1", + "friends-of-behat/mink-extension": "^2.2", + "friends-of-behat/symfony-extension": "^2.1", + "guzzlehttp/guzzle": "^6.0 || ^7.0", + "illuminate/config": "^11.0 || ^12.0", + "illuminate/contracts": "^11.0 || ^12.0", + "illuminate/database": "^11.0 || ^12.0", + "illuminate/http": "^11.0 || ^12.0", + "illuminate/pagination": "^11.0 || ^12.0", + "illuminate/routing": "^11.0 || ^12.0", + "illuminate/support": "^11.0 || ^12.0", + "jangregor/phpstan-prophecy": "^1.0", + "justinrainbow/json-schema": "^5.2.11", + "laravel/framework": "^11.0 || ^12.0", + "orchestra/testbench": "^9.1", + "phpspec/prophecy-phpunit": "^2.2", + "phpstan/extension-installer": "^1.1", + "phpstan/phpdoc-parser": "^1.29 || ^2.0", + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-doctrine": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "phpstan/phpstan-symfony": "^1.0", + "phpunit/phpunit": "11.5.x-dev", + "psr/log": "^1.0 || ^2.0 || ^3.0", + "ramsey/uuid": "^4.7", + "ramsey/uuid-doctrine": "^2.0", + "soyuka/contexts": "^3.3.10", + "soyuka/pmu": "^0.2.0", + "soyuka/stubs-mongodb": "^1.0", + "symfony/asset": "^6.4 || ^7.0", + "symfony/browser-kit": "^6.4 || ^7.0", + "symfony/cache": "^6.4 || ^7.0", + "symfony/config": "^6.4 || ^7.0", + "symfony/console": "^6.4 || ^7.0", + "symfony/css-selector": "^6.4 || ^7.0", + "symfony/dependency-injection": "^6.4 || ^7.0", + "symfony/doctrine-bridge": "^6.4.2 || ^7.0.2", + "symfony/dom-crawler": "^6.4 || ^7.0", + "symfony/error-handler": "^6.4 || ^7.0", + "symfony/event-dispatcher": "^6.4 || ^7.0", + "symfony/expression-language": "^6.4 || ^7.0", + "symfony/finder": "^6.4 || ^7.0", + "symfony/form": "^6.4 || ^7.0", + "symfony/framework-bundle": "^6.4 || ^7.0", + "symfony/http-client": "^6.4 || ^7.0", + "symfony/intl": "^6.4 || ^7.0", + "symfony/maker-bundle": "^1.24", + "symfony/mercure-bundle": "*", + "symfony/messenger": "^6.4 || ^7.0", + "symfony/routing": "^6.4 || ^7.0", + "symfony/security-bundle": "^6.4 || ^7.0", + "symfony/security-core": "^6.4 || ^7.0", + "symfony/stopwatch": "^6.4 || ^7.0", + "symfony/string": "^6.4 || ^7.0", + "symfony/twig-bundle": "^6.4 || ^7.0", + "symfony/uid": "^6.4 || ^7.0", + "symfony/validator": "^6.4 || ^7.0", + "symfony/web-profiler-bundle": "^6.4 || ^7.0", + "symfony/yaml": "^6.4 || ^7.0", + "twig/twig": "^1.42.3 || ^2.12 || ^3.0", + "webonyx/graphql-php": "^15.0" + }, + "suggest": { + "doctrine/mongodb-odm-bundle": "To support MongoDB. Only versions 4.0 and later are supported.", + "elasticsearch/elasticsearch": "To support Elasticsearch.", + "ocramius/package-versions": "To display the API Platform's version in the debug bar.", + "phpstan/phpdoc-parser": "To support extracting metadata from PHPDoc.", + "psr/cache-implementation": "To use metadata caching.", + "ramsey/uuid": "To support Ramsey's UUID identifiers.", + "symfony/cache": "To have metadata caching when using Symfony integration.", + "symfony/config": "To load XML configuration files.", + "symfony/expression-language": "To use authorization features.", + "symfony/http-client": "To use the HTTP cache invalidation system.", + "symfony/messenger": "To support messenger integration.", + "symfony/security": "To use authorization features.", + "symfony/twig-bundle": "To use the Swagger UI integration.", + "symfony/uid": "To support Symfony UUID/ULID identifiers.", + "symfony/web-profiler-bundle": "To use the data collector.", + "webonyx/graphql-php": "To support GraphQL." + }, + "type": "library", + "extra": { + "pmu": { + "projects": [ + "./src/*/composer.json", + "src/Doctrine/*/composer.json" + ] + }, + "thanks": { + "url": "https://github.com/api-platform/api-platform", + "name": "api-platform/api-platform" + }, + "symfony": { + "require": "^6.4 || ^7.1" + }, + "branch-alias": { + "dev-3.4": "3.4.x-dev", + "dev-4.1": "4.1.x-dev", + "dev-main": "4.2.x-dev" + } + }, + "autoload": { + "files": [ + "src/JsonLd/HydraContext.php" + ], + "psr-4": { + "ApiPlatform\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kévin Dunglas", + "email": "kevin@dunglas.fr", + "homepage": "https://dunglas.fr" + } + ], + "description": "Build a fully-featured hypermedia or GraphQL API in minutes!", + "homepage": "https://api-platform.com", + "keywords": [ + "Hydra", + "JSON-LD", + "api", + "graphql", + "hal", + "jsonapi", + "laravel", + "openapi", + "rest", + "swagger", + "symfony" + ], + "support": { + "issues": "https://github.com/api-platform/core/issues", + "source": "https://github.com/api-platform/core/tree/v4.1.16" + }, + "time": "2025-06-13T13:00:13+00:00" + }, { "name": "doctrine/collections", "version": "2.3.0", @@ -1609,6 +1825,62 @@ }, "time": "2019-01-08T18:20:26+00:00" }, + { + "name": "psr/link", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/link.git", + "reference": "84b159194ecfd7eaa472280213976e96415433f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/link/zipball/84b159194ecfd7eaa472280213976e96415433f7", + "reference": "84b159194ecfd7eaa472280213976e96415433f7", + "shasum": "" + }, + "require": { + "php": ">=8.0.0" + }, + "suggest": { + "fig/link-util": "Provides some useful PSR-13 utilities" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Link\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for HTTP links", + "homepage": "https://github.com/php-fig/link", + "keywords": [ + "http", + "http-link", + "link", + "psr", + "psr-13", + "rest" + ], + "support": { + "source": "https://github.com/php-fig/link/tree/2.0.1" + }, + "time": "2021-03-11T23:00:27+00:00" + }, { "name": "psr/log", "version": "3.0.2", @@ -5644,6 +5916,89 @@ ], "time": "2025-05-15T09:04:05+00:00" }, + { + "name": "symfony/web-link", + "version": "v7.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/web-link.git", + "reference": "7697f74fce67555665339423ce453cc8216a98ff" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/web-link/zipball/7697f74fce67555665339423ce453cc8216a98ff", + "reference": "7697f74fce67555665339423ce453cc8216a98ff", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "psr/link": "^1.1|^2.0" + }, + "conflict": { + "symfony/http-kernel": "<6.4" + }, + "provide": { + "psr/link-implementation": "1.0|2.0" + }, + "require-dev": { + "symfony/http-kernel": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\WebLink\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kévin Dunglas", + "email": "dunglas@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Manages links between resources", + "homepage": "https://symfony.com", + "keywords": [ + "dns-prefetch", + "http", + "http2", + "link", + "performance", + "prefetch", + "preload", + "prerender", + "psr13", + "push" + ], + "support": { + "source": "https://github.com/symfony/web-link/tree/v7.3.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2025-05-19T13:28:18+00:00" + }, { "name": "symfony/yaml", "version": "v7.3.0", @@ -5852,6 +6207,62 @@ "source": "https://github.com/webmozarts/assert/tree/1.11.0" }, "time": "2022-06-03T18:03:27+00:00" + }, + { + "name": "willdurand/negotiation", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/willdurand/Negotiation.git", + "reference": "68e9ea0553ef6e2ee8db5c1d98829f111e623ec2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/willdurand/Negotiation/zipball/68e9ea0553ef6e2ee8db5c1d98829f111e623ec2", + "reference": "68e9ea0553ef6e2ee8db5c1d98829f111e623ec2", + "shasum": "" + }, + "require": { + "php": ">=7.1.0" + }, + "require-dev": { + "symfony/phpunit-bridge": "^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Negotiation\\": "src/Negotiation" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "William Durand", + "email": "will+git@drnd.me" + } + ], + "description": "Content Negotiation tools for PHP provided as a standalone library.", + "homepage": "http://williamdurand.fr/Negotiation/", + "keywords": [ + "accept", + "content", + "format", + "header", + "negotiation" + ], + "support": { + "issues": "https://github.com/willdurand/Negotiation/issues", + "source": "https://github.com/willdurand/Negotiation/tree/3.1.0" + }, + "time": "2022-01-30T20:08:53+00:00" } ], "packages-dev": [ @@ -9873,7 +10284,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": true, "prefer-lowest": false, "platform": { @@ -9881,7 +10292,7 @@ "ext-ctype": "*", "ext-iconv": "*" }, - "platform-dev": {}, + "platform-dev": [], "platform-overrides": { "php": "8.4" }, diff --git a/config/bundles.php b/config/bundles.php index 7e02dfa..020f7cf 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -1,5 +1,6 @@ true, 'test' => true, ], + ApiPlatformBundle::class => [ + 'all' => true, + ], ]; diff --git a/config/packages/api_platform.php b/config/packages/api_platform.php new file mode 100644 index 0000000..d19bc6e --- /dev/null +++ b/config/packages/api_platform.php @@ -0,0 +1,20 @@ +extension('api_platform', [ + 'title' => 'Hello API Platform', + 'version' => '1.0.0', + 'defaults' => [ + 'stateless' => true, + 'cache_headers' => [ + 'vary' => [ + 'Content-Type', + 'Authorization', + 'Origin', + ], + ], + ], + ]); +}; diff --git a/config/routes/api_platform.php b/config/routes/api_platform.php new file mode 100644 index 0000000..7d9d7d7 --- /dev/null +++ b/config/routes/api_platform.php @@ -0,0 +1,8 @@ +import('.', 'api_platform') + ->prefix('/api'); +}; diff --git a/src/ApiResource/.gitignore b/src/ApiResource/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/src/Entity/FoodOrder.php b/src/Entity/FoodOrder.php index a25dd3a..bbf7116 100644 --- a/src/Entity/FoodOrder.php +++ b/src/Entity/FoodOrder.php @@ -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 { diff --git a/src/Entity/FoodVendor.php b/src/Entity/FoodVendor.php index dd3f350..890c674 100644 --- a/src/Entity/FoodVendor.php +++ b/src/Entity/FoodVendor.php @@ -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)] diff --git a/src/Entity/MenuItem.php b/src/Entity/MenuItem.php index 2591975..71021a5 100644 --- a/src/Entity/MenuItem.php +++ b/src/Entity/MenuItem.php @@ -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 { diff --git a/src/Entity/OrderItem.php b/src/Entity/OrderItem.php index 8e07b8b..6569142 100644 --- a/src/Entity/OrderItem.php +++ b/src/Entity/OrderItem.php @@ -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 { diff --git a/src/State/OpenOrdersProvider.php b/src/State/OpenOrdersProvider.php new file mode 100644 index 0000000..6223a74 --- /dev/null +++ b/src/State/OpenOrdersProvider.php @@ -0,0 +1,25 @@ +repository->findOpenOrders(); + } +} diff --git a/symfony.lock b/symfony.lock index 7b7218e..676275b 100644 --- a/symfony.lock +++ b/symfony.lock @@ -1,4 +1,18 @@ { + "api-platform/core": { + "version": "4.1", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "4.0", + "ref": "cb9e6b8ceb9b62f32d41fc8ad72a25d5bd674c6d" + }, + "files": [ + "config/packages/api_platform.yaml", + "config/routes/api_platform.yaml", + "src/ApiResource/.gitignore" + ] + }, "doctrine/deprecations": { "version": "1.1", "recipe": {