src/Containers/SettingSection/ControlContainer/Entities/IndividualCostCarEntity.php line 70

Open in your IDE?
  1. <?php
  2. namespace App\Containers\SettingSection\ControlContainer\Entities;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Delete;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Patch;
  8. use ApiPlatform\Metadata\Put;
  9. use ApiPlatform\Metadata\Post;
  10. use ApiPlatform\Metadata\ApiFilter;
  11. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  12. use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
  13. use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
  14. use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
  15. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Doctrine\DBAL\Types\Types;
  18. use Gedmo\Mapping\Annotation as Gedmo;
  19. use Symfony\Component\Serializer\Annotation\Groups;
  20. use Symfony\Component\Serializer\Annotation\Context;
  21. use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  22. use App\Containers\SettingSection\ControlContainer\Data\Repositories\IndividualCostCarRepository;
  23. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  24. /** 
  25.  * Индивидуальная стоимость
  26. */
  27. #[ApiResource(
  28.     routePrefix'/control',
  29.     normalizationContext: ['groups' => 'read'],
  30.     operations: [
  31.         new Get(
  32.             uriTemplate'/individual_costs_cars/{id}'requirements: ['id' => '\d+'],
  33.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  34.         ),
  35.         new Patch(
  36.             uriTemplate'/individual_costs_cars/{id}'requirements: ['id' => '\d+'],
  37.             security"is_granted('ROLE_ADMIN')"
  38.         ),
  39.         // new Put(
  40.         //     uriTemplate: '/individual_costs_cars/{id}', requirements: ['id' => '\d+'],
  41.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  42.         // ),
  43.         new Delete(
  44.             uriTemplate'/individual_costs_cars/{id}'requirements: ['id' => '\d+'],
  45.             security"is_granted('ROLE_ADMIN')"
  46.         ),
  47.         new Post(
  48.             uriTemplate'/individual_costs_cars',
  49.             security"is_granted('ROLE_ADMIN')"
  50.         ),
  51.         new GetCollection(
  52.             uriTemplate'/individual_costs_cars',
  53.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')"
  54.         ),
  55.     ],
  56.     shortName'Control_IndividualCostsCars'
  57. )]
  58. #[ApiFilter(SearchFilter::class, properties: ['id' => 'exact''carNumber' => 'partial''externalCode' => 'partial'])]
  59. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  60. #[ApiFilter(RangeFilter::class, properties: ['id''carPriceUSD''carPriceUAH'])]
  61. #[ApiFilter(DateFilter::class, properties: ['dateStart''dateEnd''createdAt''updatedAt'])]
  62. #[ApiFilter(OrderFilter::class)]
  63. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: ['carNumber''externalCode'])]
  64. #[ORM\Entity(repositoryClassIndividualCostCarRepository::class)]
  65. #[ORM\Table(name'`control_individual_costs_cars`')]
  66. #[ORM\Index(columns: ['car_number''car_number_latin'], name'control_individual_costs_cars_custom_idx')]
  67. class IndividualCostCarEntity
  68. {   
  69.     #[ORM\Id]
  70.     #[ORM\GeneratedValue]
  71.     #[ORM\Column(typeTypes::INTEGER)]
  72.     #[Groups(['read'])]
  73.     private ?int $id null;
  74.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  75.     #[Groups(['read'])]
  76.     private ?string $externalCode null;
  77.     // Номер авто
  78.     #[ORM\Column(typeTypes::STRINGlength50nullablefalse)]
  79.     #[Groups(['read'])]
  80.     private string $carNumber;
  81.     // Номер авто (латиница)
  82.     #[ORM\Column(typeTypes::STRINGlength50nullabletrue)]
  83.     #[Groups(['read'])]
  84.     private ?string $carNumberLatin null;
  85.     // Стоимость авто в USD
  86.     #[ORM\Column(typeTypes::INTEGERnullablefalse)]
  87.     #[Groups(['read'])]
  88.     private int $carPriceUSD;
  89.     // Стоимость авто в ГРН
  90.     #[ORM\Column(typeTypes::INTEGERnullabletrue)]
  91.     #[Groups(['read'])]
  92.     private ?int $carPriceUAH null;
  93.     // Дата начала активности
  94.     #[ORM\Column(typeTypes::DATE_IMMUTABLEnullablefalse)]
  95.     #[Context(
  96.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'],
  97.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d']
  98.     )]
  99.     #[Groups(['read'])]
  100.     private \DateTimeInterface $dateStart;
  101.     // Дата окончания активности
  102.     #[ORM\Column(typeTypes::DATE_IMMUTABLEnullablefalse)]
  103.     #[Context(
  104.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'],
  105.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d']
  106.     )]
  107.     #[Groups(['read'])]
  108.     private \DateTimeInterface $dateEnd;
  109.     #[Gedmo\Timestampable(on'create')]
  110.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  111.     #[Groups(['read'])]
  112.     protected $createdAt;
  113.     #[Gedmo\Timestampable(on'update')]
  114.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  115.     #[Groups(['read'])]
  116.     protected $updatedAt;
  117.     public function getId(): ?int
  118.     {
  119.         return $this->id;
  120.     }
  121.     public function getExternalCode()
  122.     {
  123.         return $this->externalCode;
  124.     }
  125.     public function setExternalCode($code)
  126.     {
  127.         $this->externalCode $code;
  128.         return $this;
  129.     }
  130.     public function getCarNumber()
  131.     {
  132.         return $this->carNumber;
  133.     }
  134.     public function setCarNumber($number)
  135.     {
  136.         $this->carNumber = ($number !== null str_replace(' ',''trim($number)) : null);
  137.         return $this;
  138.     }
  139.     public function getCarNumberLatin()
  140.     {
  141.         return $this->carNumberLatin;
  142.     }
  143.     public function setCarNumberLatin($number)
  144.     {
  145.         $this->carNumberLatin = ($number !== null str_replace(' ',''trim($number)) : null);
  146.         return $this;
  147.     }
  148.     
  149.     public function getCarPriceUSD()
  150.     {
  151.         return $this->carPriceUSD;
  152.     }
  153.     public function setCarPriceUSD($price)
  154.     {
  155.         $this->carPriceUSD $price;
  156.         return $this;
  157.     }
  158.     public function getCarPriceUAH()
  159.     {
  160.         return $this->carPriceUAH;
  161.     }
  162.     public function setCarPriceUAH($price)
  163.     {
  164.         $this->carPriceUAH $price;
  165.         return $this;
  166.     }
  167.     public function setDateStart(\DateTimeInterface $date)
  168.     {
  169.         $this->dateStart $date;
  170.         return $this;
  171.     }
  172.     public function getDateStart()
  173.     {
  174.         return $this->dateStart;
  175.     }
  176.     public function setDateEnd(\DateTimeInterface $date)
  177.     {
  178.         $this->dateEnd $date;
  179.         return $this;
  180.     }
  181.     public function getDateEnd()
  182.     {
  183.         return $this->dateEnd;
  184.     }
  185.     public function getCreatedAt()
  186.     {
  187.         return $this->createdAt;
  188.     }
  189.     public function getUpdatedAt()
  190.     {
  191.         return $this->updatedAt;
  192.     }
  193. }