diff --git a/composer.json b/composer.json index 9da9fe8..9776480 100644 --- a/composer.json +++ b/composer.json @@ -9,10 +9,12 @@ "php": ">=8.1", "ext-ctype": "*", "ext-iconv": "*", + "api-platform/core": "^3.2", "doctrine/dbal": "^3", "doctrine/doctrine-bundle": "^2.13", "doctrine/doctrine-migrations-bundle": "^3.4", "doctrine/orm": "^3.3", + "nelmio/cors-bundle": "^2.5", "phpdocumentor/reflection-docblock": "^5.6", "phpstan/phpdoc-parser": "^1.14", "symfony/asset": "6.1.*", diff --git a/config/packages/api_platform.yaml b/config/packages/api_platform.yaml new file mode 100644 index 0000000..4d0c3f7 --- /dev/null +++ b/config/packages/api_platform.yaml @@ -0,0 +1,18 @@ +api_platform: + title: Hello API Platform + version: 1.0.0 + formats: + jsonld: ['application/ld+json'] + docs_formats: + jsonld: ['application/ld+json'] + jsonopenapi: ['application/vnd.openapi+json'] + html: ['text/html'] + defaults: + stateless: true + cache_headers: + vary: ['Content-Type', 'Authorization', 'Origin'] + extra_properties: + standard_put: true + rfc_7807_compliant_errors: true + event_listeners_backward_compatibility_layer: false + keep_legacy_inflector: false diff --git a/config/packages/nelmio_cors.yaml b/config/packages/nelmio_cors.yaml new file mode 100644 index 0000000..c766508 --- /dev/null +++ b/config/packages/nelmio_cors.yaml @@ -0,0 +1,10 @@ +nelmio_cors: + defaults: + origin_regex: true + allow_origin: ['%env(CORS_ALLOW_ORIGIN)%'] + allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE'] + allow_headers: ['Content-Type', 'Authorization'] + expose_headers: ['Link'] + max_age: 3600 + paths: + '^/': null diff --git a/config/routes/api_platform.yaml b/config/routes/api_platform.yaml new file mode 100644 index 0000000..38f11cb --- /dev/null +++ b/config/routes/api_platform.yaml @@ -0,0 +1,4 @@ +api_platform: + resource: . + type: 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/Emoji.php b/src/Entity/Emoji.php index 611950f..8668ff8 100644 --- a/src/Entity/Emoji.php +++ b/src/Entity/Emoji.php @@ -4,8 +4,10 @@ namespace App\Entity; use App\Repository\EmojiRepository; use Doctrine\ORM\Mapping as ORM; +use ApiPlatform\Metadata\ApiResource; #[ORM\Entity(repositoryClass: EmojiRepository::class)] +#[ApiResource] class Emoji { #[ORM\Id] diff --git a/src/Entity/Rarity.php b/src/Entity/Rarity.php index 0df259d..8ca232f 100644 --- a/src/Entity/Rarity.php +++ b/src/Entity/Rarity.php @@ -4,8 +4,10 @@ namespace App\Entity; use App\Repository\RarityRepository; use Doctrine\ORM\Mapping as ORM; +use ApiPlatform\Metadata\ApiResource; #[ORM\Entity(repositoryClass: RarityRepository::class)] +#[ApiResource] class Rarity { #[ORM\Id] diff --git a/src/Entity/StockEmoji.php b/src/Entity/StockEmoji.php index 1626de0..08d9fc9 100644 --- a/src/Entity/StockEmoji.php +++ b/src/Entity/StockEmoji.php @@ -4,8 +4,10 @@ namespace App\Entity; use App\Repository\StockEmojiRepository; use Doctrine\ORM\Mapping as ORM; +use ApiPlatform\Metadata\ApiResource; #[ORM\Entity(repositoryClass: StockEmojiRepository::class)] +#[ApiResource] class StockEmoji { #[ORM\Id] diff --git a/src/Entity/User.php b/src/Entity/User.php index bef596e..566bfcc 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -9,9 +9,11 @@ use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use ApiPlatform\Metadata\ApiResource; #[ORM\Entity(repositoryClass: UserRepository::class)] -#[UniqueEntity(fields: ['username'], message: 'There is already an account with this username')] +#[UniqueEntity(fields: ['username'], message: 'Un compte existe déjà avec ce nom d\'utilisateur')] +#[ApiResource] class User implements UserInterface, PasswordAuthenticatedUserInterface { #[ORM\Id]