creation of API endpoint thirdparty

This commit is contained in:
Julie Lenaerts 2021-09-01 17:34:30 +02:00
parent 9961c38b3c
commit 19a4542e2b
4 changed files with 17 additions and 4 deletions

View File

@ -10,6 +10,7 @@ use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter; use Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
/** /**
* This is the class that loads and manages your bundle configuration. * This is the class that loads and manages your bundle configuration.
* *
@ -59,7 +60,15 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte
'name' => 'thirdparty', 'name' => 'thirdparty',
'base_path' => '/api/1.0/thirdparty/thirdparty', 'base_path' => '/api/1.0/thirdparty/thirdparty',
'base_role' => \Chill\ThirdPartyBundle\Security\Authorization\ThirdPartyVoter::class, 'base_role' => \Chill\ThirdPartyBundle\Security\Authorization\ThirdPartyVoter::class,
'controller' => \Chill\ThirdPartyBundle\Controller\ThirdPartyApiController::class,
'actions' => [ 'actions' => [
'_index' => [
'methods' => [
Request::METHOD_GET => true,
Request::METHOD_HEAD => true,
Request::METHOD_POST => true,
],
],
'_entity' => [ '_entity' => [
'methods' => [ 'methods' => [
Request::METHOD_GET => true, Request::METHOD_GET => true,

View File

@ -60,7 +60,7 @@ class ThirdParty
* @var string * @var string
* @ORM\Column(name="name", type="string", length=255) * @ORM\Column(name="name", type="string", length=255)
* @Assert\Length(min="2") * @Assert\Length(min="2")
* @Groups({"read", "write"}) * @Groups({"read"})
*/ */
private $name; private $name;
@ -130,7 +130,7 @@ class ThirdParty
* @Assert\Regex("/^([\+{1}])([0-9\s*]{4,20})$/", * @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" * 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"}) * @Groups({"read"})
*/ */
private $telephone; private $telephone;
@ -138,7 +138,7 @@ class ThirdParty
* @var string|null * @var string|null
* @ORM\Column(name="email", type="string", length=255, nullable=true) * @ORM\Column(name="email", type="string", length=255, nullable=true)
* @Assert\Email(checkMX=false) * @Assert\Email(checkMX=false)
* @Groups({"read", "write"}) * @Groups({"read"})
*/ */
private $email; private $email;
@ -147,7 +147,7 @@ class ThirdParty
* @ORM\ManyToOne(targetEntity="\Chill\MainBundle\Entity\Address", * @ORM\ManyToOne(targetEntity="\Chill\MainBundle\Entity\Address",
* cascade={"persist", "remove"}) * cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL") * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
* @Groups({"read", "write"}) * @Groups({"read"})
*/ */
private $address; private $address;

View File

@ -21,6 +21,8 @@ class ThirdPartyNormalizer implements NormalizerInterface, NormalizerAwareInterf
$data['id'] = $thirdParty->getId(); $data['id'] = $thirdParty->getId();
$data['address'] = $this->normalizer->normalize($thirdParty->getAddress(), $format, $data['address'] = $this->normalizer->normalize($thirdParty->getAddress(), $format,
[ 'address_rendering' => 'short' ]); [ 'address_rendering' => 'short' ]);
$data['phonenumber'] = $thirdParty->getTelephone();
$data['email'] = $thirdParty->getEmail();
return $data; return $data;
} }

View File

@ -17,6 +17,8 @@ paths:
responses: responses:
200: 200:
description: "ok" description: "ok"
401:
description: "Unauthorized"
/1.0/thirdparty/thirdparty/{id}.json: /1.0/thirdparty/thirdparty/{id}.json:
get: get: