src/Containers/OscpvSection/ListContainer/Entities/CityEntity.php line 87

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\CityRepository;
  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'/cities/{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'/cities/{id}'requirements: ['id' => '\d+'],
  43.             security"is_granted('ROLE_ADMIN')"
  44.         ),
  45.         // new Put(
  46.         //     uriTemplate: '/cities/{id}', requirements: ['id' => '\d+'],
  47.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  48.         // ),
  49.         new Delete(
  50.             uriTemplate'/cities/{id}'requirements: ['id' => '\d+'],
  51.             security"is_granted('ROLE_ADMIN')"
  52.         ),
  53.         new Post(
  54.             uriTemplate'/cities',
  55.             security"is_granted('ROLE_ADMIN')"
  56.         ),
  57.         new GetCollection(
  58.             uriTemplate'/cities',
  59.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  60.         )
  61.     ],
  62.     shortName'OSCPV_List_Cities'
  63. )]
  64. #[ApiFilter(SearchFilter::class, properties: [
  65.     'id' => 'exact',
  66.     'dmreoCityId' => 'exact',
  67.     'externalCode' => 'partial',
  68.     'name' => 'partial'
  69.     'koatuu' => 'partial'
  70.     'zoneCode' => 'partial'
  71.     'typeOp' => 'exact',
  72. ])]
  73. #[ApiFilter(NumericFilter::class, properties: ['id''dmreoCityId'])]
  74. #[ApiFilter(RangeFilter::class, properties: ['id''dmreoCityId'])]
  75. #[ApiFilter(BooleanFilter::class, properties: ['isActive'])]
  76. #[ApiFilter(DateFilter::class, properties: ['dateExternalUpdate''createdAt''updatedAt'])]
  77. #[ApiFilter(OrderFilter::class)]
  78. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: [
  79.     'name''dmreoCityId''externalCode''koatuu''zoneCode''typeOp'
  80. ])]
  81. #[ORM\Entity(repositoryClassCityRepository::class)]
  82. #[ORM\Table(name'`oscpv_list_cities`')]
  83. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  84. class CityEntity
  85. {
  86.     #[ORM\Id]
  87.     #[ORM\GeneratedValue]
  88.     #[ORM\Column(typeTypes::INTEGER)]
  89.     #[Groups(['read'])]
  90.     private ?int $id null;
  91.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  92.     #[Groups(['read'])]
  93.     private ?string $externalCode null;
  94.     // ДМРЕО города
  95.     #[ORM\Column(typeTypes::INTEGERnullabletrueuniquetrue)]
  96.     #[Groups(['read'])]
  97.     private ?int $dmreoCityId null;
  98.     // Название
  99.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  100.     #[Groups(['read'])]
  101.     private ?string $name null;
  102.     // Активность
  103.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => true])]
  104.     #[Groups(['read'])]
  105.     private bool $isActive true;
  106.     // КОАТУУ
  107.     #[ORM\Column(typeTypes::STRINGlength25nullabletrue)]
  108.     #[Groups(['read'])]
  109.     private ?string $koatuu null;
  110.     // Зона
  111.     #[ORM\Column(typeTypes::STRINGlength25nullabletrue)]
  112.     #[Groups(['read'])]
  113.     private ?string $zoneCode null;
  114.     // Дата изменения
  115.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  116.     #[Context(
  117.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  118.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  119.     )]
  120.     #[Groups(['read'])]
  121.     private ?\DateTimeInterface $dateExternalUpdate null;
  122.     // Тип
  123.     #[ORM\Column(typeTypes::STRINGlength25nullabletrue)]
  124.     #[Groups(['read'])]
  125.     private ?string $typeOp null;
  126.     #[Gedmo\Timestampable(on'create')]
  127.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  128.     #[Groups(['read'])]
  129.     protected $createdAt;
  130.     #[Gedmo\Timestampable(on'update')]
  131.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  132.     #[Groups(['read'])]
  133.     protected $updatedAt;
  134.     /**
  135.      * Used locale to override Translation listener`s locale
  136.      * this is not a mapped field of entity metadata, just a simple property
  137.      */
  138.     #[Gedmo\Locale]
  139.     private $locale;
  140.     public function getId(): ?int
  141.     {
  142.         return $this->id;
  143.     }
  144.     public function getExternalCode()
  145.     {
  146.         return $this->externalCode;
  147.     }
  148.     public function setExternalCode($code)
  149.     {
  150.         $this->externalCode $code;
  151.         return $this;
  152.     }
  153.     public function getDmreoCityId()
  154.     {
  155.         return $this->dmreoCityId;
  156.     }
  157.     public function setDmreoCityId($id)
  158.     {
  159.         $this->dmreoCityId $id;
  160.         return $this;
  161.     }
  162.     public function getName()
  163.     {
  164.         return $this->name;
  165.     }
  166.     public function setName($name)
  167.     {
  168.         $this->name $name;
  169.         return $this;
  170.     }
  171.     public function getIsActive()
  172.     {
  173.         return $this->isActive;
  174.     }
  175.     public function setIsActive($isActive)
  176.     {
  177.         $this->isActive $isActive;
  178.         return $this;
  179.     }
  180.     public function getKoatuu()
  181.     {
  182.         return $this->koatuu;
  183.     }
  184.     public function setKoatuu($value)
  185.     {
  186.         $this->koatuu $value;
  187.         return $this;
  188.     }
  189.     public function getZoneCode()
  190.     {
  191.         return $this->zoneCode;
  192.     }
  193.     public function setZoneCode($value)
  194.     {
  195.         $this->zoneCode $value;
  196.         return $this;
  197.     }
  198.     public function setDateExternalUpdate(\DateTimeImmutable|null $date)
  199.     {
  200.         $this->dateExternalUpdate $date;
  201.         return $this;
  202.     }
  203.     public function getDateExternalUpdate()
  204.     {
  205.         return $this->dateExternalUpdate;
  206.     }
  207.     public function getTypeOp()
  208.     {
  209.         return $this->typeOp;
  210.     }
  211.     public function setTypeOp($type)
  212.     {
  213.         $this->typeOp $type;
  214.         return $this;
  215.     }
  216.     public function getCreatedAt()
  217.     {
  218.         return $this->createdAt;
  219.     }
  220.     public function getUpdatedAt()
  221.     {
  222.         return $this->updatedAt;
  223.     }
  224.     public function setTranslatableLocale($locale)
  225.     {
  226.         $this->locale $locale;
  227.     }
  228. }