src/Entity/ItemLabel.php line 39

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Annotation\ApiSubresource;
  6. use App\Controller\Api\Action\ItemLabel\ItemLabelGetAction;
  7. use App\Entity\Mapped\Entity;
  8. use App\Repository\ItemLabelRepository;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. #[ORM\Entity(
  12.     repositoryClassItemLabelRepository::class
  13. )]
  14. #[ORM\Table(
  15.     name'item_label'
  16. )]
  17. #[ApiResource(
  18.     collectionOperations: [
  19.         'post' => [
  20.             'validation_groups' => [
  21.                 'create'
  22.             ]
  23.         ],
  24.         'get_list' => [
  25.             'controller' => ItemLabelGetAction::class,
  26.             'method' => 'GET',
  27.             'path' => '/item/{id}/labels'
  28.         ]
  29.     ],
  30.     itemOperations: [
  31.         'get',
  32.         'delete',
  33.     ]
  34. )]
  35. class ItemLabel extends Entity
  36. {
  37.     #[ORM\ManyToOne(
  38.         targetEntityItem::class,
  39.         cascade: ['persist'],
  40.         inversedBy'label'
  41.     )]
  42.     #[ORM\JoinColumn(
  43.         name'item',
  44.         onDelete'CASCADE'
  45.     )]
  46.     #[Assert\NotBlank(
  47.         groups: ['create']
  48.     )]
  49.     #[ApiSubresource]
  50.     private ?Item $item null;
  51.     #[ORM\ManyToOne(
  52.         targetEntityLabel::class,
  53.         cascade: ['persist'],
  54.         inversedBy'itemLabel'
  55.     )]
  56.     #[ORM\JoinColumn(
  57.         name'label',
  58.         onDelete'CASCADE'
  59.     )]
  60.     #[Assert\NotBlank(
  61.         groups: ['create']
  62.     )]
  63.     #[ApiSubresource]
  64.     private ?Label $label null;
  65.     public function getItem(): ?Item
  66.     {
  67.         return $this->item;
  68.     }
  69.     public function setItem(?Item $item): self
  70.     {
  71.         $this->item $item;
  72.         return $this;
  73.     }
  74.     public function getLabel(): ?Label
  75.     {
  76.         return $this->label;
  77.     }
  78.     public function setLabel(?Label $label): self
  79.     {
  80.         $this->label $label;
  81.         return $this;
  82.     }
  83. }