Skip to content
Snippets Groups Projects
Commit 23a9881c authored by ROUILLON Tom's avatar ROUILLON Tom
Browse files

Add API Platform

parent 1f1abc60
No related branches found
No related tags found
No related merge requests found
...@@ -39,3 +39,7 @@ MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0 ...@@ -39,3 +39,7 @@ MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
###> symfony/mailer ### ###> symfony/mailer ###
# MAILER_DSN=null://null # MAILER_DSN=null://null
###< symfony/mailer ### ###< symfony/mailer ###
###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
###< nelmio/cors-bundle ###
...@@ -7,10 +7,11 @@ ...@@ -7,10 +7,11 @@
"php": ">=8.2", "php": ">=8.2",
"ext-ctype": "*", "ext-ctype": "*",
"ext-iconv": "*", "ext-iconv": "*",
"api-platform/core": "^3.2",
"doctrine/doctrine-bundle": "^2.11", "doctrine/doctrine-bundle": "^2.11",
"doctrine/doctrine-migrations-bundle": "^3.3", "doctrine/doctrine-migrations-bundle": "^3.3",
"doctrine/orm": "^2.17", "doctrine/orm": "^2.17",
"nelmio/api-doc-bundle": "^4.18", "nelmio/cors-bundle": "^2.4",
"phpdocumentor/reflection-docblock": "^5.3", "phpdocumentor/reflection-docblock": "^5.3",
"phpstan/phpdoc-parser": "^1.25", "phpstan/phpdoc-parser": "^1.25",
"symfony/asset": "7.0.*", "symfony/asset": "7.0.*",
......
This diff is collapsed.
...@@ -13,4 +13,6 @@ return [ ...@@ -13,4 +13,6 @@ return [
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
]; ];
api_platform:
title: API SAE S5
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
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
api_platform:
resource: .
type: api_platform
prefix: /api
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
namespace App\Entity; namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\UniteRepository; use App\Repository\UniteRepository;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: UniteRepository::class)] #[ORM\Entity(repositoryClass: UniteRepository::class)]
#[ApiResource]
class Unite class Unite
{ {
#[ORM\Id] #[ORM\Id]
...@@ -72,26 +74,4 @@ class Unite ...@@ -72,26 +74,4 @@ class Unite
{ {
return $this->paniers; return $this->paniers;
} }
public function addPanier(Panier $panier): static
{
if (!$this->paniers->contains($panier)) {
$this->paniers->add($panier);
$panier->setUniteId($this);
}
return $this;
}
public function removePanier(Panier $panier): static
{
if ($this->paniers->removeElement($panier)) {
// set the owning side to null (unless already changed)
if ($panier->getUniteId() === $this) {
$panier->setUniteId(null);
}
}
return $this;
}
} }
{ {
"api-platform/core": {
"version": "3.2",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "3.2",
"ref": "696d44adc3c0d4f5d25a2f1c4f3700dd8a5c6db9"
},
"files": [
"config/packages/api_platform.yaml",
"config/routes/api_platform.yaml",
"src/ApiResource/.gitignore"
]
},
"doctrine/doctrine-bundle": { "doctrine/doctrine-bundle": {
"version": "2.11", "version": "2.11",
"recipe": { "recipe": {
...@@ -26,14 +40,17 @@ ...@@ -26,14 +40,17 @@
"./migrations/.gitignore" "./migrations/.gitignore"
] ]
}, },
"nelmio/api-doc-bundle": { "nelmio/cors-bundle": {
"version": "4.18", "version": "2.4",
"recipe": { "recipe": {
"repo": "github.com/symfony/recipes-contrib", "repo": "github.com/symfony/recipes",
"branch": "main", "branch": "main",
"version": "3.0", "version": "1.5",
"ref": "c8e0c38e1a280ab9e37587a8fa32b251d5bc1c94" "ref": "6bea22e6c564fba3a1391615cada1437d0bde39c"
} },
"files": [
"config/packages/nelmio_cors.yaml"
]
}, },
"phpunit/phpunit": { "phpunit/phpunit": {
"version": "9.6", "version": "9.6",
......
...@@ -11,4 +11,6 @@ Dans notre cas, nous avons choisi Symfony. Donc, nous avons besoin de 3 containe ...@@ -11,4 +11,6 @@ Dans notre cas, nous avons choisi Symfony. Donc, nous avons besoin de 3 containe
- Un container pour la base de données (MySQL) - Un container pour la base de données (MySQL)
- Un container pour l'application (Symfony/PHP) - Un container pour l'application (Symfony/PHP)
Un container adminer a été ajouté pour pouvoir gérer la base de données. Un container adminer a été ajouté pour pouvoir gérer la base de données.
\ No newline at end of file
Lien vers la documentation swagger de l'api : http://localhost:8080/api
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment