src/Containers/SettingSection/ListContainer/Entities/GenderEntity.php line 67

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 Symfony\Component\Serializer\Annotation\Groups;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Doctrine\DBAL\Types\Types;
  18. use Gedmo\Mapping\Annotation as Gedmo;
  19. use App\Containers\SettingSection\ListContainer\Data\Repositories\GenderRepository;
  20. use App\Containers\SettingSection\IndexContainer\Entities\TranslationEntity;
  21. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  22. /** 
  23.  * Пол
  24. */
  25. #[ApiResource(
  26.     routePrefix'/list',
  27.     normalizationContext: ['groups' => 'read'],
  28.     operations: [
  29.         new Get(
  30.             uriTemplate'/genders/{id}'requirements: ['id' => '\d+'],
  31.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  32.         ),
  33.         new Patch(
  34.             uriTemplate'/genders/{id}'requirements: ['id' => '\d+'],
  35.             security"is_granted('ROLE_ADMIN')"
  36.         ),
  37.         // new Put(
  38.         //     uriTemplate: '/genders/{id}', requirements: ['id' => '\d+'],
  39.         //     security: "is_granted('ROLE_ADMIN')"
  40.         // ),
  41.         new Delete(
  42.             uriTemplate'/genders/{id}'requirements: ['id' => '\d+'],
  43.             security"is_granted('ROLE_ADMIN')"
  44.         ),
  45.         new Post(
  46.             uriTemplate'/genders',
  47.             security"is_granted('ROLE_ADMIN')"
  48.         ),
  49.         new GetCollection(
  50.             uriTemplate'/genders',
  51.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  52.         ),
  53.     ],
  54.     shortName'List_Genders'
  55. )]
  56. #[ApiFilter(SearchFilter::class, properties: ['id' => 'exact''name' => 'partial''externalCode' => 'partial'])]
  57. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  58. #[ApiFilter(RangeFilter::class, properties: ['id'])]
  59. #[ApiFilter(OrderFilter::class)]
  60. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: ['name''externalCode'])]
  61. #[ORM\Entity(repositoryClassGenderRepository::class)]
  62. #[ORM\Table(name'`list_genders`')]
  63. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  64. class GenderEntity
  65. {
  66.     #[ORM\Id]
  67.     #[ORM\GeneratedValue]
  68.     #[ORM\Column(typeTypes::INTEGER)]
  69.     #[Groups(['read'])]
  70.     private ?int $id null;
  71.     // Наименование
  72.     #[ORM\Column(typeTypes::STRINGlength255nullablefalse)]
  73.     #[Gedmo\Translatable]
  74.     #[Groups(['read'])]
  75.     private string $name;
  76.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  77.     #[Groups(['read'])]
  78.     private ?string $externalCode null;
  79.     #[Gedmo\Timestampable(on'create')]
  80.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  81.     protected $createdAt;
  82.     #[Gedmo\Timestampable(on'update')]
  83.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  84.     protected $updatedAt;
  85.     /**
  86.      * Used locale to override Translation listener`s locale
  87.      * this is not a mapped field of entity metadata, just a simple property
  88.      */
  89.     #[Gedmo\Locale]
  90.     private $locale;
  91.     
  92.     public function getId(): ?int
  93.     {
  94.         return $this->id;
  95.     }
  96.     public function getExternalCode()
  97.     {
  98.         return $this->externalCode;
  99.     }
  100.     public function setExternalCode($code)
  101.     {
  102.         $this->externalCode $code;
  103.         return $this;
  104.     }
  105.     public function getName()
  106.     {
  107.         return $this->name;
  108.     }
  109.     public function setName($name)
  110.     {
  111.         $this->name $name;
  112.         return $this;
  113.     }
  114.     public function setTranslatableLocale($locale)
  115.     {
  116.         $this->locale $locale;
  117.     }
  118. }