src/Entity/Telefono.php line 35

  1. <?php
  2. namespace App\Entity;
  3. use Ramsey\Uuid\Uuid;
  4. use App\Trait\UuidTrait;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\Put;
  7. use ApiPlatform\Metadata\Post;
  8. use ApiPlatform\Metadata\Patch;
  9. use ApiPlatform\Metadata\Delete;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use ApiPlatform\Metadata\ApiResource;
  12. use App\Repository\TelefonoRepository;
  13. use ApiPlatform\Metadata\GetCollection;
  14. use Ramsey\Uuid\Doctrine\UuidGenerator;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. #[ORM\Entity(repositoryClassTelefonoRepository::class)]
  18. #[
  19.     ApiResource(
  20.         operations: [
  21.             new Get(uriTemplate'telefonos/'),
  22.             new Post(validationContext: ['groups' => ['Default''telefono:create']], denormalizationContext: ['groups' => ['telefono:create']], uriTemplate'telefonoes'),
  23.             new GetCollection(uriTemplate'telefonoes'),
  24.             new Put(denormalizationContext: ['groups' => ['telefono:update']],),
  25.             new Patch(denormalizationContext: ['groups' => ['telefono:update']],),
  26.             new Delete(),
  27.         ],
  28.         normalizationContext: ['groups' => ['telefono:read''uuid']],
  29.     )
  30. ]
  31. class Telefono
  32. {
  33.     use UuidTrait;
  34.     #[Assert\NotBlank(groups: ['telefono:create'])]
  35.     #[Groups([
  36.         'telefono:read''telefono:create''telefono:update',
  37.         'user:read''user:create''user:update',
  38.         'empresa:read''empresa:create''empresa:update'
  39.     ])]
  40.     #[ORM\Column(length255)]
  41.     private ?string $numero null;
  42.     #[Groups(['telefono:read''telefono:create''telefono:update'])]
  43.     #[ORM\ManyToOne(inversedBy'telefonos')]
  44.     private ?User $user null;
  45.     #[Groups([
  46.         'telefono:read''telefono:create''telefono:update',
  47.         'user:read''user:create''user:update',
  48.         'empresa:read''empresa:create''empresa:update'
  49.     ])]
  50.     #[ORM\Column]
  51.     private ?bool $isPrincipal null;
  52.     #[Groups(['telefono:read''telefono:create''telefono:update'])]
  53.     #[ORM\ManyToOne(inversedBy'telefonos')]
  54.     private ?Empresa $empresa null;
  55.     public function __construct()
  56.     {
  57.         $this->uuid Uuid::uuid4()->toString();
  58.     }
  59.     
  60.     public function getNumero(): ?string
  61.     {
  62.         return $this->numero;
  63.     }
  64.     public function setNumero(string $numero): self
  65.     {
  66.         $this->numero $numero;
  67.         return $this;
  68.     }
  69.     public function getUser(): ?User
  70.     {
  71.         return $this->user;
  72.     }
  73.     public function setUser(?User $user): self
  74.     {
  75.         $this->user $user;
  76.         return $this;
  77.     }
  78.     public function isIsPrincipal(): ?bool
  79.     {
  80.         return $this->isPrincipal;
  81.     }
  82.     public function setIsPrincipal(bool $isPrincipal): self
  83.     {
  84.         $this->isPrincipal $isPrincipal;
  85.         return $this;
  86.     }
  87.     public function getEmpresa(): ?Empresa
  88.     {
  89.         return $this->empresa;
  90.     }
  91.     public function setEmpresa(?Empresa $empresa): self
  92.     {
  93.         $this->empresa $empresa;
  94.         return $this;
  95.     }
  96. }