src/Containers/OscpvSection/ListContainer/Entities/CarBrandEntity.php line 85

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