From f41997e6da595d60dd8f1cc68501a552545f8756 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 1 Sep 2021 14:33:31 +0200 Subject: [PATCH] creation api endpoint. Route found, but ajax call still needs to be tested --- .../ChillThirdPartyExtension.php | 28 ++++++++++++- .../Entity/ThirdParty.php | 5 +++ .../chill.api.specs.yaml | 41 +++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 src/Bundle/ChillThirdPartyBundle/chill.api.specs.yaml diff --git a/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php b/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php index 7ada8db8e..fb3770f02 100644 --- a/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php +++ b/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php @@ -8,6 +8,7 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter; +use Symfony\Component\HttpFoundation\Request; /** * This is the class that loads and manages your bundle configuration. @@ -47,11 +48,34 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte { //declare routes for 3party bundle $container->prependExtensionConfig('chill_main', array( - 'routing' => array( + 'routing' => [ 'resources' => array( '@ChillThirdPartyBundle/config/routes.yaml' ) - ) + ], + 'apis' => [ + [ + 'class' => \Chill\ThirdPartyBundle\Entity\ThirdParty::class, + 'name' => 'thirdparty', + 'base_path' => '/api/1.0/thirdparty/thirdparty', + 'base_role' => \Chill\ThirdPartyBundle\Security\Authorization\ThirdPartyVoter::class, + 'actions' => [ + '_entity' => [ + 'methods' => [ + Request::METHOD_GET => true, + Request::METHOD_HEAD => true, + Request::METHOD_POST=> true, + ], + 'roles' => [ + Request::METHOD_GET => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::SHOW, + Request::METHOD_HEAD => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::SHOW, + Request::METHOD_POST => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::CREATE, + + ], + ] + ] + ] + ], )); } diff --git a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php index 277202324..45a446443 100644 --- a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php +++ b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php @@ -30,6 +30,7 @@ use Chill\MainBundle\Entity\Center; use Symfony\Component\Validator\Constraints as Assert; use Chill\MainBundle\Entity\Address; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; +use Symfony\Component\Serializer\Annotation\Groups; /** * ThirdParty is a party recorded in the database. @@ -59,6 +60,7 @@ class ThirdParty * @var string * @ORM\Column(name="name", type="string", length=255) * @Assert\Length(min="2") + * @Groups({"read", "write"}) */ private $name; @@ -128,6 +130,7 @@ class ThirdParty * @Assert\Regex("/^([\+{1}])([0-9\s*]{4,20})$/", * message="Invalid phone number: it should begin with the international prefix starting with ""+"", hold only digits and be smaller than 20 characters. Ex: +33123456789" * ) + * @Groups({"read", "write"}) */ private $telephone; @@ -135,6 +138,7 @@ class ThirdParty * @var string|null * @ORM\Column(name="email", type="string", length=255, nullable=true) * @Assert\Email(checkMX=false) + * @Groups({"read", "write"}) */ private $email; @@ -143,6 +147,7 @@ class ThirdParty * @ORM\ManyToOne(targetEntity="\Chill\MainBundle\Entity\Address", * cascade={"persist", "remove"}) * @ORM\JoinColumn(nullable=true, onDelete="SET NULL") + * @Groups({"read", "write"}) */ private $address; diff --git a/src/Bundle/ChillThirdPartyBundle/chill.api.specs.yaml b/src/Bundle/ChillThirdPartyBundle/chill.api.specs.yaml new file mode 100644 index 000000000..32b23a747 --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/chill.api.specs.yaml @@ -0,0 +1,41 @@ +--- +openapi: "3.0.0" +info: + version: "1.0.0" + title: "Chill api" + description: "Api documentation for chill. Currently, work in progress" +servers: + - url: "/api" + description: "Your current dev server" + +paths: + /1.0/thirdparty/thirdparty.json: + get: + tags: + - thirdparty + summary: Return a list of all thirdparty items + responses: + 200: + description: "ok" + + /1.0/thirdparty/thirdparty/{id}.json: + get: + tags: + - thirdparty + summary: Return a thirdparty item by id + parameters: + - name: id + in: path + required: true + description: The thirdparty id + schema: + type: integer + format: integer + minimum: 1 + responses: + 200: + description: "ok" + 404: + description: "not found" + 401: + description: "Unauthorized"