src/Containers/OscpvSection/ListContainer/Entities/CarModelEntity.php line 89

Open in your IDE?
  1. <?php
  2. namespace App\Containers\OscpvSection\ListContainer\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\BooleanFilter;
  16. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  17. use Doctrine\ORM\Mapping as ORM;
  18. use Doctrine\DBAL\Types\Types;
  19. use Gedmo\Mapping\Annotation as Gedmo;
  20. use Symfony\Component\Serializer\Annotation\Groups;
  21. use Symfony\Component\Serializer\Annotation\MaxDepth;
  22. use Symfony\Component\Serializer\Annotation\Context;
  23. use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  24. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  25. use App\Containers\OscpvSection\ListContainer\Data\Repositories\CarModelRepository;
  26. use App\Containers\OscpvSection\IndexContainer\Entities\TranslationEntity;
  27. use App\Containers\OscpvSection\ListContainer\Entities\CarBrandEntity;
  28. /** 
  29.  * Модели авто по классификации МТСБУ
  30. */
  31. #[ApiResource(
  32.     routePrefix'/oscpv/list',
  33.     normalizationContext: [
  34.         'groups' => 'read',
  35.         'enable_max_depth' => true
  36.     ],
  37.     operations: [
  38.         new Get(
  39.             uriTemplate'/car_models/{id}'requirements: ['id' => '\d+'],
  40.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  41.         ),
  42.         new Patch(
  43.             uriTemplate'/car_models/{id}'requirements: ['id' => '\d+'],
  44.             security"is_granted('ROLE_ADMIN')"
  45.         ),
  46.         // new Put(
  47.         //     uriTemplate: '/car_models/{id}', requirements: ['id' => '\d+'],
  48.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  49.         // ),
  50.         new Delete(
  51.             uriTemplate'/car_models/{id}'requirements: ['id' => '\d+'],
  52.             security"is_granted('ROLE_ADMIN')"
  53.         ),
  54.         new Post(
  55.             uriTemplate'/car_models',
  56.             security"is_granted('ROLE_ADMIN')"
  57.         ),
  58.         new GetCollection(
  59.             uriTemplate'/car_models',
  60.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  61.         )
  62.     ],
  63.     shortName'OSCPV_List_CarModels'
  64. )]
  65. #[ApiFilter(SearchFilter::class, properties: [
  66.     'id' => 'exact',
  67.     'dmreoModelId' => 'exact',
  68.     'dmreoMarkId' => 'exact',
  69.     'externalCode' => 'partial',
  70.     'name' => 'partial',
  71.     'typeOp' => 'exact',
  72.     'carBrand.name' => 'exact'
  73.     'carBrand.externalCode' => 'exact'
  74. ])]
  75. #[ApiFilter(NumericFilter::class, properties: ['id''dmreoModelId''dmreoMarkId',])]
  76. #[ApiFilter(RangeFilter::class, properties: ['id''dmreoModelId''dmreoMarkId'])]
  77. #[ApiFilter(BooleanFilter::class, properties: ['isActive'])]
  78. #[ApiFilter(DateFilter::class, properties: ['dateExternalUpdate''createdAt''updatedAt'])]
  79. #[ApiFilter(OrderFilter::class)]
  80. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: [
  81.     'name''dmreoModelId''dmreoMarkId''externalCode''typeOp'
  82. ])]
  83. #[ORM\Entity(repositoryClassCarModelRepository::class)]
  84. #[ORM\Table(name'`oscpv_list_car_models`')]
  85. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  86. class CarModelEntity
  87. {   
  88.     #[ORM\Id]
  89.     #[ORM\GeneratedValue]
  90.     #[ORM\Column(typeTypes::INTEGER)]
  91.     #[Groups(['read'])]
  92.     private ?int $id null;
  93.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  94.     #[Groups(['read'])]
  95.     private ?string $externalCode null;
  96.     // ДМРЕО модели авто
  97.     #[ORM\Column(typeTypes::INTEGERnullabletrueuniquetrue)]
  98.     #[Groups(['read'])]
  99.     private ?int $dmreoModelId null;
  100.     // ДМРЕО бренда авто
  101.     #[ORM\Column(typeTypes::INTEGERnullabletrue)]
  102.     #[Groups(['read'])]
  103.     private ?int $dmreoMarkId null;
  104.     // Название
  105.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  106.     #[Gedmo\Translatable]
  107.     #[Groups(['read'])]
  108.     private ?string $name null;
  109.     // Марка
  110.     #[ORM\ManyToOne(targetEntityCarBrandEntity::class)]
  111.     #[ORM\JoinColumn(name'car_brand_id'referencedColumnName'id'nullabletrue)]
  112.     #[Groups(['read'])]
  113.     private ?CarBrandEntity $carBrand null;
  114.     // Активность
  115.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => true])]
  116.     #[Groups(['read'])]
  117.     private bool $isActive true;
  118.     // Дата изменения
  119.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  120.     #[Context(
  121.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  122.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  123.     )]
  124.     #[Groups(['read'])]
  125.     private ?\DateTimeInterface $dateExternalUpdate null;
  126.     // Тип
  127.     #[ORM\Column(typeTypes::STRINGlength25nullabletrue)]
  128.     #[Groups(['read'])]
  129.     private ?string $typeOp null;
  130.     #[Gedmo\Timestampable(on'create')]
  131.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  132.     #[Groups(['read'])]
  133.     protected $createdAt;
  134.     #[Gedmo\Timestampable(on'update')]
  135.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  136.     #[Groups(['read'])]
  137.     protected $updatedAt;
  138.     /**
  139.      * Used locale to override Translation listener`s locale
  140.      * this is not a mapped field of entity metadata, just a simple property
  141.      */
  142.     #[Gedmo\Locale]
  143.     private $locale;
  144.     public function getId(): ?int
  145.     {
  146.         return $this->id;
  147.     }
  148.     public function getExternalCode()
  149.     {
  150.         return $this->externalCode;
  151.     }
  152.     public function setExternalCode($code)
  153.     {
  154.         $this->externalCode $code;
  155.         return $this;
  156.     }
  157.     public function getDmreoModelId()
  158.     {
  159.         return $this->dmreoModelId;
  160.     }
  161.     public function setDmreoModelId($id)
  162.     {
  163.         $this->dmreoModelId $id;
  164.         return $this;
  165.     }
  166.     public function getDmreoMarkId()
  167.     {
  168.         return $this->dmreoMarkId;
  169.     }
  170.     public function setDmreoMarkId($id)
  171.     {
  172.         $this->dmreoMarkId $id;
  173.         return $this;
  174.     }
  175.     public function getName()
  176.     {
  177.         return $this->name;
  178.     }
  179.     public function setName($name)
  180.     {
  181.         $this->name $name;
  182.         return $this;
  183.     }
  184.     public function getCarBrand()
  185.     {
  186.         return $this->carBrand;
  187.     }
  188.     public function setCarBrand($brand)
  189.     {
  190.         $this->carBrand $brand;
  191.         return $this;
  192.     }
  193.     public function getIsActive()
  194.     {
  195.         return $this->isActive;
  196.     }
  197.     public function setIsActive($isActive)
  198.     {
  199.         $this->isActive $isActive;
  200.         return $this;
  201.     }
  202.     public function setDateExternalUpdate(\DateTimeImmutable|null $date)
  203.     {
  204.         $this->dateExternalUpdate $date;
  205.         return $this;
  206.     }
  207.     public function getDateExternalUpdate()
  208.     {
  209.         return $this->dateExternalUpdate;
  210.     }
  211.     public function getTypeOp()
  212.     {
  213.         return $this->typeOp;
  214.     }
  215.     public function setTypeOp($type)
  216.     {
  217.         $this->typeOp $type;
  218.         return $this;
  219.     }
  220.     public function getCreatedAt()
  221.     {
  222.         return $this->createdAt;
  223.     }
  224.     public function getUpdatedAt()
  225.     {
  226.         return $this->updatedAt;
  227.     }
  228.     public function setTranslatableLocale($locale)
  229.     {
  230.         $this->locale $locale;
  231.     }
  232. }