| 313| Création d'une page d'administration : modification/création d'un fournisseur | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [x] Pas de régression - [ ] TU/TI/TF rédigée - [x] TU/TI/TF OK - [x] CHANGELOG modifié Reviewed-on: https://gitea.malio.fr/MALIO-DEV/Ferme/pulls/20 Reviewed-by: Autin <tristan@yuno.malio.fr> Co-authored-by: Matteo <matteo@yuno.malio.fr> Co-committed-by: Matteo <matteo@yuno.malio.fr>
This commit is contained in:
+47
-4
@@ -8,6 +8,8 @@ use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Patch;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@@ -24,6 +26,21 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
||||
new GetCollection(
|
||||
normalizationContext: ['groups' => ['supplier:read']],
|
||||
),
|
||||
new GetCollection(
|
||||
uriTemplate: '/admin/suppliers',
|
||||
normalizationContext: ['groups' => ['supplier:read']],
|
||||
security: "is_granted('ROLE_ADMIN')"
|
||||
),
|
||||
new Post(
|
||||
normalizationContext: ['groups' => ['supplier:read']],
|
||||
denormalizationContext: ['groups' => ['supplier:write']],
|
||||
security: "is_granted('ROLE_ADMIN')",
|
||||
),
|
||||
new Patch(
|
||||
normalizationContext: ['groups' => ['supplier:read']],
|
||||
denormalizationContext: ['groups' => ['supplier:write']],
|
||||
security: "is_granted('ROLE_ADMIN')",
|
||||
),
|
||||
],
|
||||
security: "is_granted('ROLE_USER')",
|
||||
)]
|
||||
@@ -36,15 +53,15 @@ class Supplier
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 180)]
|
||||
#[Groups(['supplier:read', 'reception:read'])]
|
||||
#[Groups(['supplier:read', 'reception:read', 'supplier:write'])]
|
||||
private string $name = '';
|
||||
|
||||
#[ORM\Column(length: 180, nullable: true)]
|
||||
#[Groups(['supplier:read', 'reception:read'])]
|
||||
#[Groups(['supplier:read', 'reception:read', 'supplier:write'])]
|
||||
private ?string $email = null;
|
||||
|
||||
#[ORM\Column(length: 40, nullable: true)]
|
||||
#[Groups(['supplier:read', 'reception:read'])]
|
||||
#[Groups(['supplier:read', 'reception:read', 'supplier:write'])]
|
||||
private ?string $phone = null;
|
||||
|
||||
/**
|
||||
@@ -52,7 +69,7 @@ class Supplier
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Address::class, inversedBy: 'suppliers')]
|
||||
#[ORM\JoinTable(name: 'supplier_address')]
|
||||
#[Groups(['supplier:read'])]
|
||||
#[Groups(['supplier:read', 'supplier:write'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
private Collection $addresses;
|
||||
|
||||
@@ -109,4 +126,30 @@ class Supplier
|
||||
{
|
||||
return $this->addresses;
|
||||
}
|
||||
|
||||
public function setAddresses(iterable $addresses): self
|
||||
{
|
||||
$this->addresses->clear();
|
||||
foreach ($addresses as $address) {
|
||||
$this->addAddress($address);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addAddress(Address $address): self
|
||||
{
|
||||
if (!$this->addresses->contains($address)) {
|
||||
$this->addresses->add($address);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeAddress(Address $address): self
|
||||
{
|
||||
$this->addresses->removeElement($address);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user