src/Containers/SettingSection/ListContainer/Entities/CarBrandEntity.php line 81

Open in your IDE?
  1. <?php
  2. namespace App\Containers\SettingSection\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\OrderFilter;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Doctrine\DBAL\Types\Types;
  17. use Gedmo\Mapping\Annotation as Gedmo;
  18. use Symfony\Component\Serializer\Annotation\Groups;
  19. use App\Containers\SettingSection\ListContainer\Data\Repositories\CarBrandRepository;
  20. use App\Containers\SettingSection\IndexContainer\Entities\TranslationEntity;
  21. use App\Containers\SettingSection\ListContainer\Entities\CarTypeEntity;
  22. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  23. /** 
  24.  * Марки авто
  25. */
  26. #[ApiResource(
  27.     routePrefix'/list',
  28.     normalizationContext: ['groups' => ['read']],
  29.     operations: [
  30.         new Get(
  31.             uriTemplate'/car_brands/{id}'requirements: ['id' => '\d+'],
  32.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  33.         ),
  34.         new Patch(
  35.             uriTemplate'/car_brands/{id}'requirements: ['id' => '\d+'],
  36.             security"is_granted('ROLE_ADMIN')"
  37.         ),
  38.         // new Put(
  39.         //     uriTemplate: '/car_brands/{id}', requirements: ['id' => '\d+'],
  40.         //     security: "is_granted('ROLE_ADMIN')"
  41.         // ),
  42.         new Delete(
  43.             uriTemplate'/car_brands/{id}'requirements: ['id' => '\d+'],
  44.             security"is_granted('ROLE_ADMIN')"
  45.         ),
  46.         new Post(
  47.             uriTemplate'/car_brands',
  48.             security"is_granted('ROLE_ADMIN')"
  49.         ),
  50.         new GetCollection(
  51.             uriTemplate'/car_brands',
  52.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  53.         ),
  54.     ],
  55.     shortName'List_CarBrands'
  56. )]
  57. #[ApiFilter(SearchFilter::class, properties: [
  58.     'id' => 'exact',
  59.     'name' => 'partial'
  60.     'codeAutoria' => 'partial'
  61.     'codeOpendataBot' => 'partial'
  62.     'code1C' => 'partial'
  63.     'name1C' => 'partial'
  64.     'carType' => 'exact',
  65.     'carType.name' => 'partial'
  66.     'carType.codeAutoria' => 'partial'
  67. ])]
  68. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  69. #[ApiFilter(RangeFilter::class, properties: ['id'])]
  70. #[ApiFilter(OrderFilter::class)]
  71. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: [
  72.     'name''codeAutoria''codeOpendataBot''code1C''name1C'
  73. ])]
  74. #[ORM\Entity(repositoryClassCarBrandRepository::class)]
  75. #[ORM\Table(name'`list_car_brands`')]
  76. #[ORM\Index(columns: ['code_autoria''code_opendata_bot'], name'list_car_brands_custom_idx')]
  77. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  78. class CarBrandEntity
  79. {
  80.     #[ORM\Id]
  81.     #[ORM\GeneratedValue]
  82.     #[ORM\Column(typeTypes::INTEGER)]
  83.     #[Groups(['read'])]
  84.     private ?int $id null;
  85.     // Название
  86.     #[ORM\Column(typeTypes::STRINGlength255nullablefalse)]
  87.     #[Gedmo\Translatable]
  88.     #[Groups(['read'])]
  89.     private string $name;
  90.     // Код АвтоРИА
  91.     #[ORM\Column(typeTypes::STRINGlength255nullablefalse)]
  92.     #[Groups(['read'])]
  93.     private string $codeAutoria;
  94.     // Код OpendataBot
  95.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  96.     #[Groups(['read'])]
  97.     private ?string $codeOpendataBot null;
  98.     // Категория
  99.     #[ORM\ManyToOne(targetEntityCarTypeEntity::class)]
  100.     #[ORM\JoinColumn(name'car_type_id'referencedColumnName'id'nullablefalse)]
  101.     #[Groups(['read'])]
  102.     private CarTypeEntity $carType;
  103.     // Код 1С
  104.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  105.     #[Groups(['read'])]
  106.     private ?string $code1C null;
  107.     // Название 1С
  108.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  109.     #[Groups(['read'])]
  110.     private ?string $name1C null;
  111.     #[Gedmo\Timestampable(on'create')]
  112.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  113.     protected $createdAt;
  114.     #[Gedmo\Timestampable(on'update')]
  115.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  116.     protected $updatedAt;
  117.     /**
  118.      * Used locale to override Translation listener`s locale
  119.      * this is not a mapped field of entity metadata, just a simple property
  120.      */
  121.     #[Gedmo\Locale]
  122.     private $locale;
  123.     public function getId(): ?int
  124.     {
  125.         return $this->id;
  126.     }
  127.     public function getName()
  128.     {
  129.         return $this->name;
  130.     }
  131.     public function setName($name)
  132.     {
  133.         $this->name $name;
  134.         return $this;
  135.     }
  136.     public function getCodeAutoria()
  137.     {
  138.         return $this->codeAutoria;
  139.     }
  140.     public function setCodeAutoria($code)
  141.     {
  142.         $this->codeAutoria $code;
  143.         return $this;
  144.     }
  145.     public function getCodeOpendataBot()
  146.     {
  147.         return $this->codeOpendataBot;
  148.     }
  149.     public function setCodeOpendataBot($code)
  150.     {
  151.         $this->codeOpendataBot $code;
  152.         return $this;
  153.     }
  154.     public function getCarType()
  155.     {
  156.         return $this->carType;
  157.     }
  158.     public function setCarType($type)
  159.     {
  160.         $this->carType $type;
  161.         return $this;
  162.     }
  163.     public function getCode1C()
  164.     {
  165.         return $this->code1C;
  166.     }
  167.     public function setCode1C($code)
  168.     {
  169.         $this->code1C $code;
  170.         return $this;
  171.     }
  172.     public function getName1C()
  173.     {
  174.         return $this->name1C;
  175.     }
  176.     public function setName1C($name)
  177.     {
  178.         $this->name1C $name;
  179.         return $this;
  180.     }
  181.     public function setTranslatableLocale($locale)
  182.     {
  183.         $this->locale $locale;
  184.     }
  185. }