<?php
namespace App\Containers\SettingSection\ControlContainer\Entities;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
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\RangeFilter;
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\Context;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use App\Containers\SettingSection\ControlContainer\Data\Repositories\IndividualCostCarRepository;
use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
/**
* Индивидуальная стоимость
*/
#[ApiResource(
routePrefix: '/control',
normalizationContext: ['groups' => 'read'],
operations: [
new Get(
uriTemplate: '/individual_costs_cars/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
new Patch(
uriTemplate: '/individual_costs_cars/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
// new Put(
// uriTemplate: '/individual_costs_cars/{id}', requirements: ['id' => '\d+'],
// security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
// ),
new Delete(
uriTemplate: '/individual_costs_cars/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new Post(
uriTemplate: '/individual_costs_cars',
security: "is_granted('ROLE_ADMIN')"
),
new GetCollection(
uriTemplate: '/individual_costs_cars',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')"
),
],
shortName: 'Control_IndividualCostsCars'
)]
#[ApiFilter(SearchFilter::class, properties: ['id' => 'exact', 'carNumber' => 'partial', 'externalCode' => 'partial'])]
#[ApiFilter(NumericFilter::class, properties: ['id'])]
#[ApiFilter(RangeFilter::class, properties: ['id', 'carPriceUSD', 'carPriceUAH'])]
#[ApiFilter(DateFilter::class, properties: ['dateStart', 'dateEnd', 'createdAt', 'updatedAt'])]
#[ApiFilter(OrderFilter::class)]
#[ApiFilter(filterClass: SimpleSearchFilter::class, properties: ['carNumber', 'externalCode'])]
#[ORM\Entity(repositoryClass: IndividualCostCarRepository::class)]
#[ORM\Table(name: '`control_individual_costs_cars`')]
#[ORM\Index(columns: ['car_number', 'car_number_latin'], name: 'control_individual_costs_cars_custom_idx')]
class IndividualCostCarEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read'])]
private ?int $id = null;
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, unique: true)]
#[Groups(['read'])]
private ?string $externalCode = null;
// Номер авто
#[ORM\Column(type: Types::STRING, length: 50, nullable: false)]
#[Groups(['read'])]
private string $carNumber;
// Номер авто (латиница)
#[ORM\Column(type: Types::STRING, length: 50, nullable: true)]
#[Groups(['read'])]
private ?string $carNumberLatin = null;
// Стоимость авто в USD
#[ORM\Column(type: Types::INTEGER, nullable: false)]
#[Groups(['read'])]
private int $carPriceUSD;
// Стоимость авто в ГРН
#[ORM\Column(type: Types::INTEGER, nullable: true)]
#[Groups(['read'])]
private ?int $carPriceUAH = null;
// Дата начала активности
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: false)]
#[Context(
normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'],
denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d']
)]
#[Groups(['read'])]
private \DateTimeInterface $dateStart;
// Дата окончания активности
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: false)]
#[Context(
normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'],
denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d']
)]
#[Groups(['read'])]
private \DateTimeInterface $dateEnd;
#[Gedmo\Timestampable(on: 'create')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
#[Groups(['read'])]
protected $createdAt;
#[Gedmo\Timestampable(on: 'update')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
#[Groups(['read'])]
protected $updatedAt;
public function getId(): ?int
{
return $this->id;
}
public function getExternalCode()
{
return $this->externalCode;
}
public function setExternalCode($code)
{
$this->externalCode = $code;
return $this;
}
public function getCarNumber()
{
return $this->carNumber;
}
public function setCarNumber($number)
{
$this->carNumber = ($number !== null ? str_replace(' ','', trim($number)) : null);
return $this;
}
public function getCarNumberLatin()
{
return $this->carNumberLatin;
}
public function setCarNumberLatin($number)
{
$this->carNumberLatin = ($number !== null ? str_replace(' ','', trim($number)) : null);
return $this;
}
public function getCarPriceUSD()
{
return $this->carPriceUSD;
}
public function setCarPriceUSD($price)
{
$this->carPriceUSD = $price;
return $this;
}
public function getCarPriceUAH()
{
return $this->carPriceUAH;
}
public function setCarPriceUAH($price)
{
$this->carPriceUAH = $price;
return $this;
}
public function setDateStart(\DateTimeInterface $date)
{
$this->dateStart = $date;
return $this;
}
public function getDateStart()
{
return $this->dateStart;
}
public function setDateEnd(\DateTimeInterface $date)
{
$this->dateEnd = $date;
return $this;
}
public function getDateEnd()
{
return $this->dateEnd;
}
public function getCreatedAt()
{
return $this->createdAt;
}
public function getUpdatedAt()
{
return $this->updatedAt;
}
}