<?php
namespace App\Containers\SettingSection\ListContainer\Entities;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use Symfony\Component\Serializer\Annotation\Groups;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use Gedmo\Mapping\Annotation as Gedmo;
use App\Containers\SettingSection\ListContainer\Data\Repositories\AgentRepository;
use App\Containers\SettingSection\IndexContainer\Entities\TranslationEntity;
use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
#[ApiResource(
routePrefix: '/list',
normalizationContext: ['groups' => 'read'],
operations: [
new Get(
uriTemplate: '/agent/{id}',
requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new Patch(
uriTemplate: '/agent/{id}',
requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new Delete(
uriTemplate: '/agent/{id}',
requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new Post(
uriTemplate: '/agent',
security: "is_granted('ROLE_ADMIN')"
),
new GetCollection(
uriTemplate: '/agent',
security: "is_granted('ROLE_ADMIN')"
),
],
shortName: 'List_Agent'
)]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'name' => 'partial',
'code' => 'partial',
'docNum' => 'partial',
'jobType' => 'exact',
])]
#[ApiFilter(NumericFilter::class, properties: ['id'])]
#[ApiFilter(BooleanFilter::class, properties: ['isDefault'])]
#[ApiFilter(RangeFilter::class, properties: ['id', 'kv'])]
#[ApiFilter(OrderFilter::class)]
#[ApiFilter(filterClass: SimpleSearchFilter::class, properties: [
'name',
'code',
'docNum',
])]
#[ORM\Entity(repositoryClass: AgentRepository::class)]
#[ORM\Table(name: '`list_agent`')]
#[Gedmo\TranslationEntity(class: TranslationEntity::class)]
class AgentEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read'])]
private ?int $id = null;
#[ORM\Column(type: Types::STRING, length: 255, nullable: false)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private string $name;
#[ORM\Column(type: Types::STRING, length: 255, nullable: false)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private string $code;
#[ORM\Column(type: Types::STRING, length: 255, nullable: false)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private string $docNum;
#[ORM\ManyToOne(targetEntity: AgentJobTypeEntity::class)]
#[ORM\JoinColumn(name: 'job_type_id', referencedColumnName: 'id', nullable: false)]
#[Groups(['read'])]
private AgentJobTypeEntity $jobType;
#[ORM\Column(type: Types::FLOAT, scale: 2, nullable: false)]
#[Groups(['read'])]
private float $kv;
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
#[Groups(['read'])]
private bool $isDefault = false;
#[Gedmo\Timestampable(on: 'create')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
protected $createdAt;
#[Gedmo\Timestampable(on: 'update')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
protected $updatedAt;
/**
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
#[Gedmo\Locale]
private $locale;
public function getId(): ?int
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName(string $name)
{
$this->name = $name;
return $this;
}
public function getCode()
{
return $this->code;
}
public function setCode(string $code)
{
$this->code = $code;
return $this;
}
public function getDocNum()
{
return $this->docNum;
}
public function setDocNum(string $docNum)
{
$this->docNum = $docNum;
return $this;
}
public function getJobType()
{
return $this->jobType;
}
public function setJobType(AgentJobTypeEntity $jobType)
{
$this->jobType = $jobType;
return $this;
}
public function getKv()
{
return $this->kv;
}
public function setKv($kv)
{
$this->kv = $kv;
return $this;
}
public function getIsDefault()
{
return $this->isDefault;
}
public function setIsDefault($isDefault)
{
$this->isDefault = $isDefault;
return $this;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}