src/Entity/InsuredUpload.php line 77

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'InsuredUpload',
  17.     itemOperations: [
  18.         'get' => [
  19.             // 'security' => "is_granted('ROLE_USER')",
  20.             'normalization_context' => [
  21.                 'groups' => 'insured_upload:item:get',
  22.                 'enable_max_depth' => true
  23.             ]
  24.         ],
  25.         'put' => [
  26.             // 'security' => "is_granted('ROLE_USER')",
  27.             'normalization_context' => [
  28.                 'groups' => 'insured_upload:item:put',
  29.                 'enable_max_depth' => true
  30.             ],
  31.             'denormalization_context' => [
  32.                 'groups' => 'insured_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' => ['insured_upload:collection:get''createdAt'],
  45.                 'enable_max_depth' => true
  46.             ]
  47.         ],
  48.         'post' => [
  49.             // 'security' => "is_granted('ROLE_USER')",
  50.             'normalization_context' => [
  51.                 'groups' => 'insured_upload:collection:post',
  52.                 'enable_max_depth' => true
  53.             ],
  54.             'denormalization_context' => [
  55.                 'groups' => 'insured_upload:collection:post',
  56.                 'enable_max_depth' => true
  57.             ]
  58.         ],
  59.     ]
  60. )]
  61. #[ApiFilter(SearchFilter::class, properties: [
  62.     'insured' => 'exact',
  63.     'uploadType' => 'exact',
  64.     'year' => 'start',
  65.     'createdAt' => 'start',
  66.     'upload.name' => 'partial',
  67. ])]
  68. #[ApiFilter(OrderFilter::class, properties: [
  69.     'uploadType',
  70.     'year',
  71.     'createdAt'
  72. ])]
  73. class InsuredUpload
  74. {
  75.     use TimestampableEntity;
  76.     
  77.     #[ORM\Id]
  78.     #[ORM\GeneratedValue(strategy'AUTO')]
  79.     #[ORM\Column(type'integer')]
  80.     #[Groups([
  81.         'insured_upload:collection:get',
  82.         'insured_upload:collection:post',
  83.         'insured_upload:item:get',
  84.         'insured_upload:item:put',
  85.     ])]
  86.     private ?int $id null;
  87.     #[ORM\Column(type'string')]
  88.     #[ApiProperty(iri'https://schema.org/Text')]
  89.     #[Assert\Type('string')]
  90.     #[Groups([
  91.         'insured_upload:collection:get',
  92.         'insured_upload:collection:post',
  93.         'insured_upload:item:get',
  94.         'insured_upload:item:put',
  95.         'insured:item:get',
  96.     ])]
  97.     private ?string $uploadType null;
  98.     #[ORM\Column(type'integer'nullabletrue)]
  99.     #[ApiProperty()]
  100.     #[Groups([
  101.         'insured_upload:collection:get',
  102.         'insured_upload:collection:post',
  103.         'insured_upload:item:get',
  104.         'insured_upload:item:put',
  105.         'insured:item:get',
  106.     ])]
  107.     private ?int $year null;
  108.     #[ORM\ManyToOne(targetEntityInsured::class, inversedBy'uploads')]
  109.     #[Groups([
  110.         'insured_upload:collection:get',
  111.         'insured_upload:collection:post',
  112.         'insured_upload:item:get',
  113.         'insured_upload:item:put',
  114.     ])]
  115.     private $insured;
  116.     #[ORM\OneToOne(inversedBy'insuredUpload'targetEntityMedia::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  117.     #[Groups([
  118.         'insured_upload:collection:get',
  119.         'insured_upload:collection:post',
  120.         'insured_upload:item:get',
  121.         'insured_upload:item:put',
  122.         'insured:item:get',
  123.     ])]
  124.     private $upload;
  125.     public function getId(): ?int
  126.     {
  127.         return $this->id;
  128.     }
  129.     /**
  130.      * @param string|null $uploadType
  131.      */
  132.     public function setUploadType($uploadType): void
  133.     {
  134.         $this->uploadType $uploadType;
  135.     }
  136.     public function getUploadType(): ?string
  137.     {
  138.         return $this->uploadType;
  139.     }
  140.     public function setYear(?int $year): void
  141.     {
  142.         $this->year $year;
  143.     }
  144.     public function getYear(): ?int
  145.     {
  146.         return $this->year;
  147.     }
  148.     public function getInsured(): ?Insured
  149.     {
  150.         return $this->insured;
  151.     }
  152.     public function setInsured(?Insured $insured): self
  153.     {
  154.         $this->insured $insured;
  155.         return $this;
  156.     }
  157.     public function getUpload(): ?Media
  158.     {
  159.         return $this->upload;
  160.     }
  161.     public function setUpload(?Media $upload): self
  162.     {
  163.         $this->upload $upload;
  164.         return $this;
  165.     }
  166. }