src/Entity/PolicyUpload.php line 74

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiProperty;
  5. use ApiPlatform\Core\Annotation\ApiResource;
  6. use ApiPlatform\Core\Annotation\ApiFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  9. use App\Trait\TimestampableEntity;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Serializer\Annotation\MaxDepth;
  14. #[ORM\Entity]
  15. #[ApiResource(
  16.     iri'PolicyUpload',
  17.     itemOperations: [
  18.         'get' => [
  19.             // 'security' => "is_granted('ROLE_USER')",
  20.             'normalization_context' => [
  21.                 'groups' => 'policy_upload:item:get',
  22.                 'enable_max_depth' => true
  23.             ]
  24.         ],
  25.         'put' => [
  26.             // 'security' => "is_granted('ROLE_USER')",
  27.             'normalization_context' => [
  28.                 'groups' => 'policy_upload:item:put',
  29.                 'enable_max_depth' => true
  30.             ],
  31.             'denormalization_context' => [
  32.                 'groups' => 'policy_upload:item:put',
  33.                 'enable_max_depth' => true
  34.             ]
  35.         ],
  36.         'delete' => [
  37.             // 'security' => "is_granted('ROLE_USER')",
  38.         ]
  39.     ],
  40.     collectionOperations: [
  41.         'get' => [
  42.             // 'security' => "is_granted('ROLE_USER')",
  43.             'normalization_context' => [
  44.                 'groups' => ['policy_upload:collection:get''createdAt'],
  45.                 'enable_max_depth' => true
  46.             ]
  47.         ],
  48.         'post' => [
  49.             // 'security' => "is_granted('ROLE_USER')",
  50.             'normalization_context' => [
  51.                 'groups' => 'policy_upload:collection:post',
  52.                 'enable_max_depth' => true
  53.             ],
  54.             'denormalization_context' => [
  55.                 'groups' => 'policy_upload:collection:post',
  56.                 'enable_max_depth' => true
  57.             ]
  58.         ],
  59.     ]
  60. )]
  61. #[ApiFilter(SearchFilter::class, properties: [
  62.     'policy' => 'exact',
  63.     'uploadType' => 'exact',
  64.     'createdAt' => 'start',
  65. ])]
  66. #[ApiFilter(OrderFilter::class, properties: [
  67.     'uploadType',
  68.     'createdAt'
  69. ])]
  70. class PolicyUpload
  71. {
  72.     use TimestampableEntity;
  73.     
  74.     #[ORM\Id]
  75.     #[ORM\GeneratedValue(strategy'AUTO')]
  76.     #[ORM\Column(type'integer')]
  77.     #[Groups([
  78.         'policy_upload:collection:get',
  79.         'policy_upload:collection:post',
  80.         'policy_upload:item:get',
  81.         'policy_upload:item:put',
  82.     ])]
  83.     private ?int $id null;
  84.     #[ORM\Column(type'string')]
  85.     #[ApiProperty(iri'https://schema.org/Text')]
  86.     #[Assert\Type('string')]
  87.     #[Groups([
  88.         'policy_upload:collection:get',
  89.         'policy_upload:collection:post',
  90.         'policy_upload:item:get',
  91.         'policy_upload:item:put',
  92.         'policy:item:get',
  93.     ])]
  94.     private ?string $uploadType null;
  95.     #[ORM\ManyToOne(targetEntityPolicy::class, inversedBy'uploads')]
  96.     #[Groups([
  97.         'policy_upload:collection:get',
  98.         'policy_upload:collection:post',
  99.         'policy_upload:item:get',
  100.         'policy_upload:item:put',
  101.     ])]
  102.     private $policy;
  103.     #[ORM\OneToOne(inversedBy'policyUpload'targetEntityMedia::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  104.     #[Groups([
  105.         'policy_upload:collection:get',
  106.         'policy_upload:collection:post',
  107.         'policy_upload:item:get',
  108.         'policy_upload:item:put',
  109.         'policy:item:get',
  110.     ])]
  111.     private $upload;
  112.     public function getId(): ?int
  113.     {
  114.         return $this->id;
  115.     }
  116.     /**
  117.      * @param string|null $uploadType
  118.      */
  119.     public function setUploadType($uploadType): void
  120.     {
  121.         $this->uploadType $uploadType;
  122.     }
  123.     public function getUploadType(): ?string
  124.     {
  125.         return $this->uploadType;
  126.     }
  127.     public function getPolicy(): ?Policy
  128.     {
  129.         return $this->policy;
  130.     }
  131.     public function setPolicy(?Policy $policy): self
  132.     {
  133.         $this->policy $policy;
  134.         return $this;
  135.     }
  136.     public function getUpload(): ?Media
  137.     {
  138.         return $this->upload;
  139.     }
  140.     public function setUpload(?Media $upload): self
  141.     {
  142.         $this->upload $upload;
  143.         return $this;
  144.     }
  145. }