src/Entity/DemandUpload.php line 76

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