src/Containers/CrmSection/EquipmentContainer/Entities/PhotoEntity.php line 108

Open in your IDE?
  1. <?php
  2. namespace App\Containers\CrmSection\EquipmentContainer\Entities;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\ApiProperty;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Patch;
  9. use ApiPlatform\Metadata\Put;
  10. use ApiPlatform\Metadata\Post;
  11. use ApiPlatform\Metadata\ApiFilter;
  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 Symfony\Component\Serializer\Annotation\MaxDepth;
  20. use App\Containers\CrmSection\EquipmentContainer\Data\Repositories\PhotoRepository;
  21. use App\Containers\CrmSection\EquipmentContainer\UI\ApiPlatform\Controllers\PostPhotoSetByBinaryController;
  22. use App\Containers\CrmSection\EquipmentContainer\UI\ApiPlatform\Controllers\DeletePhotoController;
  23. use App\Containers\CrmSection\EquipmentContainer\Entities\ApplicationEntity;
  24. use App\Containers\CrmSection\EquipmentContainer\Entities\FileEntity;
  25. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  26. /** 
  27.  * Фото
  28. */
  29. #[ApiResource(
  30.     routePrefix'/crm',
  31.     normalizationContext: [
  32.         'groups' => 'read',
  33.         'enable_max_depth' => true
  34.     ],
  35.     operations: [
  36.         new Get(
  37.             uriTemplate'/application_photos/{id}'requirements: ['id' => '\d+'],
  38.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_INSTALLER') or is_granted('ROLE_READONLY')"
  39.         ),
  40.         // new Patch(
  41.         //     uriTemplate: '/application_photos/{id}', requirements: ['id' => '\d+'],
  42.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  43.         // ),
  44.         // new Put(
  45.         //     uriTemplate: '/application_photos/{id}', requirements: ['id' => '\d+'],
  46.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  47.         // ),
  48.         new Delete(
  49.             uriTemplate'/application_photos/{id}'requirements: ['id' => '\d+'],
  50.             controllerDeletePhotoController::class,
  51.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_INSTALLER')"
  52.         ),
  53.         // new Post(
  54.         //     uriTemplate: '/application_photos',
  55.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  56.         // ),
  57.         new Post(
  58.             uriTemplate'/application_photos/set_by_binary',
  59.             controllerPostPhotoSetByBinaryController::class,
  60.             deserializefalse
  61.             validationContext: ['groups' => ['read''equipments_object_create']], 
  62.             openapiContext: [
  63.                 'requestBody' => [
  64.                     'required' => true,
  65.                     'content' => [
  66.                         'multipart/form-data' => [
  67.                             'schema' => [
  68.                                 'type' => 'object'
  69.                                 'properties' => [
  70.                                     'application' => [
  71.                                         'type' => 'string'
  72.                                     ],
  73.                                     'file' => [
  74.                                         'type' => 'string'
  75.                                         'format' => 'binary'
  76.                                     ]
  77.                                 ],
  78.                                 'required' => [
  79.                                     'application',
  80.                                     'file'
  81.                                 ]
  82.                             ]
  83.                         ]
  84.                     ]
  85.                 ]
  86.             ],
  87.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_INSTALLER')"
  88.         ),
  89.         new GetCollection(
  90.             uriTemplate'/application_photos',
  91.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_INSTALLER') or is_granted('ROLE_READONLY')"
  92.         )
  93.     ],
  94.     shortName'CRM_Equipments'
  95. )]
  96. #[ApiFilter(SearchFilter::class, properties: [
  97.     'id' => 'exact'
  98.     'application' => 'exact'
  99. ])]
  100. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  101. #[ApiFilter(RangeFilter::class, properties: ['id'])]
  102. #[ApiFilter(OrderFilter::class)]
  103. #[ORM\Entity(repositoryClassPhotoRepository::class)]
  104. #[ORM\Table(name'`crm_equipments_photos`')]
  105. class PhotoEntity
  106. {   
  107.     #[ORM\Id]
  108.     #[ORM\GeneratedValue]
  109.     #[ORM\Column(typeTypes::INTEGER)]
  110.     #[Groups(['read'])]
  111.     private ?int $id null;
  112.     // Заявка
  113.     #[ORM\ManyToOne(targetEntityApplicationEntity::class)]
  114.     #[ORM\JoinColumn(name'application_id'referencedColumnName'id'nullablefalse)]
  115.     #[Groups(['read'])]
  116.     #[MaxDepth(2)]
  117.     private ApplicationEntity $application;
  118.     // Файл
  119.     #[ORM\ManyToOne(targetEntityFileEntity::class)]
  120.     #[ORM\JoinColumn(name'file_id'referencedColumnName'id'nullablefalse)]
  121.     private FileEntity $file;
  122.     #[ApiProperty(types: ['https://schema.org/contentUrl'])]
  123.     #[Groups(['read''equipments_object:read'])]
  124.     public ?string $contentUrl null;
  125.     #[Gedmo\Timestampable(on'create')]
  126.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  127.     protected $createdAt;
  128.     #[Gedmo\Timestampable(on'update')]
  129.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  130.     protected $updatedAt;
  131.     public function getId(): ?int
  132.     {
  133.         return $this->id;
  134.     }
  135.     public function setId($value)
  136.     {
  137.         $this->id $value;
  138.         return $this;
  139.     }
  140.     public function getApplication()
  141.     {
  142.         return $this->application;
  143.     }
  144.     public function setApplication($application)
  145.     {
  146.         $this->application $application;
  147.         return $this;
  148.     }
  149.     public function getFile()
  150.     {
  151.         return $this->file;
  152.     }
  153.     public function setFile($file)
  154.     {
  155.         $this->file $file;
  156.         return $this;
  157.     }
  158.     public function setCreatedAt(\DateTimeImmutable|null $date)
  159.     {
  160.         $this->createdAt $date;
  161.         return $this;
  162.     }
  163.     public function setUpdatedAt(\DateTimeImmutable|null $date)
  164.     {
  165.         $this->updatedAt $date;
  166.         return $this;
  167.     }
  168. }