src/Entity/Direccion.php line 28
<?phpnamespace App\Entity;use ApiPlatform\Metadata\ApiResource;use App\Repository\DireccionRepository;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;use ApiPlatform\Metadata\Get;use ApiPlatform\Metadata\Post;use ApiPlatform\Metadata\Put;use ApiPlatform\Metadata\Delete;use ApiPlatform\Metadata\Patch;use ApiPlatform\Metadata\GetCollection;use ApiPlatform\Metadata\ApiFilter;#https://api-platform.com/docs/core/serialization/#plain-identifiers// use ApiPlatform\Doctrine\Orm\Filter\DateFilter;use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;use Symfony\Component\Validator\Constraints as Assert;use App\Validator\Constraints as CustomAssert;use Symfony\Component\Serializer\Annotation\Groups;use Symfony\Component\Serializer\Annotation\SerializedName;#[ORM\Entity(repositoryClass: DireccionRepository::class)]#[ApiResource(order: ['id' => 'DESC'],description: 'Direcciones de Herdasa',shortName: 'Direcciones',//Fichero para ver posibles opciones vendor/api-platform/core/src/Metadata/ApiResource.phpoperations:[new Get(security: 'is_granted("' . ApiToken::SCOPE_USER_READ . '")'),new GetCollection(security: 'is_granted("' . ApiToken::SCOPE_USER_READ . '")'),new Post(security: 'is_granted("' . ApiToken::SCOPE_USER_WRITE_DIST . '")'),new Put(security: 'is_granted("' . ApiToken::SCOPE_USER_WRITE_DIST . '")'),new Delete(security: 'is_granted("' . ApiToken::SCOPE_USER_WRITE_DIST . '")'),new Patch(security: 'is_granted("' . ApiToken::SCOPE_USER_WRITE_DIST . '")'),],// normalizationContext: ['groups' => ['direccion:read']],// denormalizationContext: ['groups' => ['direccion:write']],)]#[ApiFilter(SearchFilter::class, properties: ['id' => 'exact', 'usuario' => 'exact'])]#[ApiFilter(BooleanFilter::class, properties: ['primario'])]#[ApiFilter(NumericFilter::class, properties: ['tipo'])]// #[Get(normalizationContext: ['groups' => ['direccion:read', 'direccion:write']])]class Direccion{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]#[Groups(['direccion:read', 'direccion:write'])]private ?int $id = null;#[ORM\Column(length: 100)]#[Assert\NotBlank(message: "El nombre es requerido.")]#[Assert\Length(max: 100,maxMessage: "El nombre no puede tener más de {{ limit }} caracteres.")]#[Groups(['direccion:read', 'direccion:write'])]private ?string $nombre = null;#[ORM\Column(length: 150)]#[Assert\NotBlank(message: "Los apellidos son requeridos.")]#[Assert\Length(max: 150,maxMessage: "Los apellidos no pueden tener más de {{ limit }} caracteres.")]#[Groups(['direccion:read', 'direccion:write'])]private ?string $apellidos = null;#[ORM\Column(length: 255)]#[Assert\Length(max: 255,maxMessage: "La calle_1 no puede tener más de {{ limit }} caracteres.")]#[Assert\NotBlank(message: "La primera línea de la calle es requerida.")]#[Groups(['direccion:read', 'direccion:write'])]#[SerializedName('calle1')]private ?string $calle_1 = null;#[ORM\Column(length: 255, nullable: true)]#[Assert\Length(max: 255,maxMessage: "La calle_2 no puede tener más de {{ limit }} caracteres.")]#[Groups(['direccion:read', 'direccion:write'])]#[SerializedName('calle2')]private ?string $calle_2 = null;#[ORM\Column(length: 80)]#[Assert\Length(max: 80,maxMessage: "El código postal no puede tener más de {{ limit }} caracteres.")]#[Assert\NotBlank(message: "La ciudad es requerida.")]#[Groups(['direccion:read', 'direccion:write'])]private ?string $ciudad = null;#[ORM\Column(length: 80)]#[Assert\Length(max: 80,maxMessage: "La provincia no puede tener más de {{ limit }} caracteres.")]#[Assert\NotBlank(message: "La provincia es requerida.")]#[Groups(['direccion:read', 'direccion:write'])]private ?string $provincia = null;#[ORM\Column(length: 5)]#[Assert\Length(min: 5,max: 5,exactMessage: "El Código postal debe tener exactamente {{ limit }} caracteres.")]#[Assert\Regex(pattern: "/^[0-9]*$/",message: "El código postal solo puede contener números.")]#[Assert\NotBlank(message: "El código postal es requerido.")]#[Groups(['direccion:read', 'direccion:write'])]#[SerializedName('codigoPostal')]private ?string $codigo_postal = null;#[ORM\Column(length: 9)]#[Assert\Length(min: 9,max: 9,exactMessage: "El teléfono debe tener exactamente {{ limit }} caracteres.")]#[Assert\NotBlank(message: "El teléfono es requerido.")]#[Assert\Regex(pattern: "/^[0-9]*$/",message: "El teléfono solo puede contener números.")]#[Groups(['direccion:read', 'direccion:write'])]private ?string $telefono = null;#[ORM\Column(length: 100, nullable: true)]#[Assert\Length(max: 100,maxMessage: "El email no puede tener más de {{ limit }} caracteres.")]#[Assert\NotBlank(message: "El email es requerido.")]#[Assert\Email(message: "El email '{{ value }}' no es un email válido.")]#[Groups(['direccion:read', 'direccion:write'])]private ?string $email = null;#[ORM\Column(length: 9)]#[Assert\Length(min: 9,max: 9,exactMessage: "El dni/cif debe tener exactamente {{ limit }} caracteres.")]#[Assert\NotBlank(message: "El dni/cif es requerido.")]#[CustomAssert\DniCif]#[Groups(['direccion:read', 'direccion:write'])]#[SerializedName('dniCif')]private ?string $dni_cif = null;#[ORM\Column(type: Types::SMALLINT)]#[Groups(['direccion:read', 'direccion:write'])]private ?int $tipo = null;#[ORM\ManyToOne(inversedBy: 'direcciones')]#[ORM\JoinColumn(nullable: false)]#[Groups(['direccion:read', 'direccion:write'])]private ?User $usuario = null;#[ORM\Column]#[Groups(['direccion:read', 'direccion:write'])]private ?bool $primario = null;#[ORM\Column(length: 255)]#[ORM\JoinColumn(nullable: false)]#[Groups(['direccion:read', 'direccion:write'])]private ?string $alias = null;public function __toString(){return $this->id;}public function getId(): ?int{return $this->id;}public function getNombre(): ?string{return $this->nombre;}public function setNombre(string $nombre): static{$this->nombre = $nombre;return $this;}public function getApellidos(): ?string{return $this->apellidos;}public function setApellidos(string $apellidos): static{$this->apellidos = $apellidos;return $this;}public function getCalle1(): ?string{return $this->calle_1;}public function setCalle1(string $calle_1): static{$this->calle_1 = $calle_1;return $this;}public function getCalle2(): ?string{return $this->calle_2;}public function setCalle2(?string $calle_2): static{$this->calle_2 = $calle_2;return $this;}public function getCiudad(): ?string{return $this->ciudad;}public function setCiudad(string $ciudad): static{$this->ciudad = $ciudad;return $this;}public function getProvincia(): ?string{return $this->provincia;}public function setProvincia(string $provincia): static{$this->provincia = $provincia;return $this;}public function getCodigoPostal(): ?string{return $this->codigo_postal;}public function setCodigoPostal(string $codigo_postal): static{$this->codigo_postal = $codigo_postal;return $this;}public function getTelefono(): ?string{return $this->telefono;}public function setTelefono(string $telefono): static{$this->telefono = $telefono;return $this;}public function getEmail(): ?string{return $this->email;}public function setEmail(?string $email): static{$this->email = $email;return $this;}public function getDniCif(): ?string{return $this->dni_cif;}public function setDniCif(string $dni_cif): static{$this->dni_cif = $dni_cif;return $this;}public function getTipo(): ?int{return $this->tipo;}public function setTipo(int $tipo): static{$this->tipo = $tipo;return $this;}public function getUsuario(): ?User{return $this->usuario;}public function setUsuario(?User $usuario): static{$this->usuario = $usuario;return $this;}public function isPrimario(): ?bool{return $this->primario;}public function setPrimario(bool $primario): static{$this->primario = $primario;return $this;}public function getAlias(): ?string{return $this->alias;}public function setAlias(string $alias): static{$this->alias = $alias;return $this;}}