src/Containers/CrmSection/InsuranceCaseContainer/Entities/InsuranceCaseFilesEntity.php line 118

Open in your IDE?
  1. <?php
  2. namespace App\Containers\CrmSection\InsuranceCaseContainer\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\SearchFilter;
  13. use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
  14. use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
  15. use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
  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 App\Ship\Entities\MediaEntity;
  23. use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
  24. use App\Containers\CrmSection\InsuranceCaseContainer\Data\Repositories\InsuranceCaseFilesRepository;
  25. use App\Containers\CrmSection\InsuranceCaseContainer\UI\ApiPlatform\Controllers\PostSetFileByBinaryController;
  26. use App\Containers\CrmSection\InsuranceCaseContainer\UI\ApiPlatform\Controllers\DeleteFileController;
  27. use App\Containers\CrmSection\InsuranceCaseContainer\Entities\InsuranceCaseEntity;
  28. use App\Containers\CrmSection\InsuranceCaseContainer\Entities\InsuranceCaseFileSectionEntity;
  29. // use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  30. /** 
  31.  * Файлы
  32. */
  33. #[ApiResource(
  34.     routePrefix'/crm',
  35.     normalizationContext: [
  36.         'groups' => 'read',
  37.         'enable_max_depth' => true
  38.     ],
  39.     operations: [
  40.         new Get(
  41.             uriTemplate'/insurance_case/files/{id}'requirements: ['id' => '\d+'],
  42.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  43.         ),
  44.         // new Post(
  45.         //     uriTemplate: '/insurance_case/files',
  46.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  47.         // ),
  48.         new Post(
  49.             uriTemplate'/insurance_case/files/set_by_binary',
  50.             controllerPostSetFileByBinaryController::class,
  51.             deserializefalse
  52.             validationContext: ['groups' => ['read''media_object_create']], 
  53.             openapiContext: [
  54.                 'requestBody' => [
  55.                     'content' => [
  56.                         'multipart/form-data' => [
  57.                             'schema' => [
  58.                                 'type' => 'object'
  59.                                 'properties' => [
  60.                                     'insuranceCase' => [
  61.                                         'type' => 'string'
  62.                                     ],
  63.                                     'section' => [
  64.                                         'type' => 'string'
  65.                                     ],
  66.                                     'file' => [
  67.                                         'type' => 'string'
  68.                                         'format' => 'binary'
  69.                                     ]
  70.                                 ],
  71.                                 'required' => [
  72.                                     'insuranceCase',
  73.                                     'section',
  74.                                     'file'
  75.                                 ]
  76.                             ]
  77.                         ]
  78.                     ]
  79.                 ]
  80.             ],
  81.             security"is_granted('ROLE_USER_CLIENT')"
  82.         ),
  83.         // new Patch(
  84.         //     uriTemplate: '/insurance_case/files/{id}', requirements: ['id' => '\d+'],
  85.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  86.         // ),
  87.         new Delete(
  88.             uriTemplate'/insurance_case/files/{id}'requirements: ['id' => '\d+'],
  89.             controllerDeleteFileController::class,
  90.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  91.         ),
  92.         new GetCollection(
  93.             uriTemplate'/insurance_case/files',
  94.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  95.         ),
  96.     ],
  97.     shortName'CRM_InsuranceCases'
  98. )]
  99. #[ApiFilter(SearchFilter::class, properties: [
  100.     'id' => 'exact'
  101.     'client' => 'exact'
  102.     'insuranceCase' => 'exact',
  103.     'section' => 'exact',
  104.     'client.name' => 'exact'
  105.     'client.lastName' => 'exact'
  106.     'client.patronymic' => 'exact'
  107. ])]
  108. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  109. #[ApiFilter(RangeFilter::class, properties: ['id'])]
  110. #[ApiFilter(DateFilter::class, properties: ['createdAt''updatedAt'])]
  111. #[ApiFilter(OrderFilter::class)]
  112. // #[ApiFilter(filterClass: SimpleSearchFilter::class, properties: ['lastName'])]
  113. #[ORM\Entity(repositoryClassInsuranceCaseFilesRepository::class)]
  114. #[ORM\Table(name'`crm_insurance_case_files`')]
  115. class InsuranceCaseFilesEntity
  116. {
  117.     #[ORM\Id]
  118.     #[ORM\GeneratedValue]
  119.     #[ORM\Column(typeTypes::INTEGER)]
  120.     #[Groups(['read'])]
  121.     private ?int $id null;
  122.     // Клиент
  123.     #[ORM\ManyToOne(targetEntityClientEntity::class)]
  124.     #[ORM\JoinColumn(name'client_id'referencedColumnName'id'nullablefalse)]
  125.     #[MaxDepth(2)]
  126.     private ClientEntity $client;
  127.     // Страховой случай
  128.     #[ORM\ManyToOne(targetEntityInsuranceCaseEntity::class)]
  129.     #[ORM\JoinColumn(name'insurance_case_id'referencedColumnName'id'nullablefalse)]
  130.     #[Groups(['read'])]
  131.     #[MaxDepth(2)]
  132.     private InsuranceCaseEntity $insuranceCase;
  133.     // Раздел
  134.     #[ORM\ManyToOne(targetEntityInsuranceCaseFileSectionEntity::class)]
  135.     #[ORM\JoinColumn(name'section_id'referencedColumnName'id'nullablefalse)]
  136.     #[Groups(['read'])]
  137.     #[MaxDepth(1)]
  138.     private InsuranceCaseFileSectionEntity $section;
  139.     // Файл
  140.     #[ORM\ManyToOne(targetEntityMediaEntity::class)]
  141.     #[ORM\JoinColumn(name'file_id'referencedColumnName'id'nullablefalse)]
  142.     private MediaEntity $file;
  143.     #[ApiProperty(types: ['https://schema.org/contentUrl'])]
  144.     #[Groups(['read''media_object:read'])]
  145.     public ?string $contentUrl null;
  146.     #[Gedmo\Timestampable(on'create')]
  147.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  148.     protected $createdAt;
  149.     #[Gedmo\Timestampable(on'update')]
  150.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  151.     protected $updatedAt;
  152.     public function getId()
  153.     {
  154.         return $this->id;
  155.     }
  156.     public function getClient()
  157.     {
  158.         return $this->client;
  159.     }
  160.     public function setClient($client)
  161.     {
  162.         $this->client $client;
  163.         return $this;
  164.     }
  165.     public function getInsuranceCase()
  166.     {
  167.         return $this->insuranceCase;
  168.     }
  169.     public function setInsuranceCase($insuranceCase)
  170.     {
  171.         $this->insuranceCase $insuranceCase;
  172.         return $this;
  173.     }
  174.     public function getSection()
  175.     {
  176.         return $this->section;
  177.     }
  178.     public function setSection($section)
  179.     {
  180.         $this->section $section;
  181.         return $this;
  182.     }
  183.     public function getFile()
  184.     {
  185.         return $this->file;
  186.     }
  187.     public function setFile($file)
  188.     {
  189.         $this->file $file;
  190.         return $this;
  191.     }
  192. }