src/Entity/BlogImage.php line 53

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
  4. use ApiPlatform\Metadata\ApiFilter;
  5. use ApiPlatform\Metadata\ApiResource;
  6. use ApiPlatform\Metadata\Delete;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Patch;
  9. use ApiPlatform\Metadata\Post;
  10. use App\Controller\BlogUploadImgController;
  11. use App\Repository\BlogImageRepository;
  12. use App\State\BlogImgProcess;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Symfony\Component\HttpFoundation\File\UploadedFile;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. #[ApiResource(
  17.     operations: [
  18.         new GetCollection(),
  19.         new Post(
  20.             uriTemplate'/blog-images/{blogId}',
  21.             inputFormats: [
  22.                 'multipart' => ['multipart/form-data'],
  23.             ],
  24.             uriVariables: [ 'blogId' ],
  25.             controllerBlogUploadImgController::class,
  26.             denormalizationContext: [
  27.                 'groups' => ['img:write'],
  28.             ],
  29.             readfalse,
  30.             deserializefalse,
  31.         ),
  32.         new Patch(
  33.             openapiContext: [ 'summary'=> 'Update main value' ],
  34.             denormalizationContext: [
  35.                 'groups' => ['img:update'],
  36.             ],
  37.             processorBlogImgProcess::class
  38.         ),
  39.         new Delete(
  40.             processorBlogImgProcess::class
  41.         )
  42.     ],
  43.     normalizationContext: ['groups' => ['img:read']],
  44.     denormalizationContext: ['groups' => ['img:create''img:update']],
  45.     security"is_granted('ROLE_WRITER')"
  46. )]
  47. #[ApiFilter(NumericFilter::class, properties: ['blog.id'  ])]
  48. #[ORM\Entity(repositoryClassBlogImageRepository::class)]
  49. class BlogImage
  50. {
  51.     #[ORM\Id]
  52.     #[ORM\GeneratedValue]
  53.     #[ORM\Column]
  54.     #[Groups(['img:read'])]
  55.     private ?int $id null;
  56.     #[Groups(['dealer:create''dealer:read''img:read'])]
  57.     #[ORM\Column(length255)]
  58.     private ?string $name null;
  59.     #[Groups(['dealer:create''dealer:read''img:read''img:write''img:update'])]
  60.     #[ORM\Column(type'boolean'nullabletrue)]
  61.     private ?bool $main null;
  62.     #[Groups(['img:write'])]
  63.     private ?UploadedFile $file null;
  64.     #[Groups(['img:read'])]
  65.     #[ORM\ManyToOne(inversedBy'blogImages')]
  66.     private ?Blog $blog null;
  67.     public function getId(): ?int
  68.     {
  69.         return $this->id;
  70.     }
  71.     public function getName(): ?string
  72.     {
  73.         return $this->name;
  74.     }
  75.     public function setName(string $name): self
  76.     {
  77.         $this->name $name;
  78.         return $this;
  79.     }
  80.     public function isMain(): ?bool
  81.     {
  82.         return $this->main;
  83.     }
  84.     public function setMain(?bool $main): self
  85.     {
  86.         $this->main $main;
  87.         return $this;
  88.     }
  89.     /**
  90.      * @return UploadedFile|null
  91.      */
  92.     public function getFile(): ?UploadedFile
  93.     {
  94.         return $this->file;
  95.     }
  96.     /**
  97.      * @param UploadedFile|null $file
  98.      */
  99.     public function setFile(?UploadedFile $file): void
  100.     {
  101.         $this->file $file;
  102.     }
  103.     public function getBlog(): ?Blog
  104.     {
  105.         return $this->blog;
  106.     }
  107.     public function setBlog(?Blog $blog): self
  108.     {
  109.         $this->blog $blog;
  110.         return $this;
  111.     }
  112. }