src/Containers/SettingSection/ListContainer/Entities/RiskEntity.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\RisksRepository;
  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'/risks/{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'/risks/{id}'requirements: ['id' => '\d+'],
  35.             security"is_granted('ROLE_ADMIN')"
  36.         ),
  37.         // new Put(
  38.         //     uriTemplate: '/risks/{id}', requirements: ['id' => '\d+'],
  39.         //     security: "is_granted('ROLE_ADMIN')"
  40.         // ),
  41.         new Delete(
  42.             uriTemplate'/risks/{id}'requirements: ['id' => '\d+'],
  43.             security"is_granted('ROLE_ADMIN')"
  44.         ),
  45.         new Post(
  46.             uriTemplate'/risks',
  47.             security"is_granted('ROLE_ADMIN')"
  48.         ),
  49.         new GetCollection(
  50.             uriTemplate'/risks',
  51.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  52.         ),
  53.     ],
  54.     shortName'List_Risks'
  55. )]
  56. #[ApiFilter(SearchFilter::class, properties: ['id' => 'exact''name' => 'partial''externalCode' => 'partial''description' => 'partial'])]
  57. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  58. #[ApiFilter(RangeFilter::class, properties: ['id'])]
  59. #[ApiFilter(OrderFilter::class)]
  60. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: ['name''externalCode''description'])]
  61. #[ORM\Entity(repositoryClassRisksRepository::class)]
  62. #[ORM\Table(name'`list_risks`')]
  63. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  64. class RiskEntity
  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.     // Внешний код
  77.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  78.     #[Groups(['read'])]
  79.     private ?string $externalCode null;
  80.     // Описание
  81.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  82.     #[Gedmo\Translatable]
  83.     #[Groups(['read'])]
  84.     private ?string $description null;
  85.     #[Gedmo\Timestampable(on'create')]
  86.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  87.     protected $createdAt;
  88.     #[Gedmo\Timestampable(on'update')]
  89.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  90.     protected $updatedAt;
  91.     /**
  92.      * Used locale to override Translation listener`s locale
  93.      * this is not a mapped field of entity metadata, just a simple property
  94.      */
  95.     #[Gedmo\Locale]
  96.     private $locale;
  97.     public function getId(): ?int
  98.     {
  99.         return $this->id;
  100.     }
  101.     public function getName()
  102.     {
  103.         return $this->name;
  104.     }
  105.     public function setName($name)
  106.     {
  107.         $this->name $name;
  108.         return $this;
  109.     }
  110.  
  111.     public function getExternalCode()
  112.     {
  113.         return $this->externalCode;
  114.     }
  115.     public function setExternalCode($code)
  116.     {
  117.         $this->externalCode $code;
  118.         return $this;
  119.     }
  120.     public function getDescription()
  121.     {
  122.         return $this->description;
  123.     }
  124.     public function setDescription($text)
  125.     {
  126.         $this->description $text;
  127.         return $this;
  128.     }
  129.     public function setTranslatableLocale($locale)
  130.     {
  131.         $this->locale $locale;
  132.     }
  133. }