<?php
declare(strict_types=1);
namespace App\Point\Doctrine\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Point\Doctrine\Repository\TransferTypeRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\Table;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints\NotBlank;
#[ApiResource(
collectionOperations: ['get', 'post'],
// itemOperations: ['get' => ['security' => 'is_granted("item", object)']],
itemOperations: ['get'],
normalizationContext: ['groups' => ['read']],
denormalizationContext: ['groups' => ['write']]
)]
#[Entity(repositoryClass: TransferTypeRepository::class)]
#[Table(name: '`point_transfer_type`')]
class TransferType
{
#[Id]
#[Column(type: 'integer')]
#[GeneratedValue]
#[Groups('read')]
private ?int $id = null;
#[Column(type: 'string')]
#[NotBlank]
#[Groups(['read', 'write'])]
private string $name;
/**
* @var Collection<int, Transfer>
*/
#[OneToMany(mappedBy: 'type', targetEntity: Transfer::class)]
#[Groups('read')]
#[ApiProperty(readableLink: false)]
private Collection $transfers;
public function __toString(): string
{
return $this->name;
}
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): void
{
$this->id = $id;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return Collection<int, Transfer>
*/
public function getTransfers(): Collection
{
return $this->transfers;
}
}