src/Entity/Industry.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\IndustryRepository")
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. #[ApiResource(
  15.     attributes: ['security' => "is_granted('ROLE_USER')"],
  16.     collectionOperations: [
  17.         'get',
  18.         'post' => ['security' => "is_granted('ROLE_ADMIN')"],
  19.     ],
  20.     itemOperations: [
  21.         'get',
  22.         'put' => ['security' => "is_granted('ROLE_ADMIN') or object.owner == user"],
  23.     ],
  24. )]
  25. #[ApiFilter(PropertyFilter::class)]
  26. #[ApiFilter(SearchFilter::class, properties: ['id''name' => 'partial'])]
  27. #[ApiFilter(OrderFilter::class, properties: ['id''name''average'], arguments: ['orderParameterName' => 'order'])]
  28. class Industry
  29. {
  30.     /**
  31.      * @ORM\Id()
  32.      * @ORM\GeneratedValue()
  33.      * @ORM\Column(type="integer")
  34.      */
  35.     private $id;
  36.     /**
  37.      * @var string
  38.      *
  39.      * @ORM\Column(name="name", type="string", length=128)
  40.      * @Assert\NotBlank()
  41.      * @Assert\Length(max="128")
  42.      */
  43.     public $name;
  44.     /**
  45.      * @ORM\Column(type="decimal", precision=8, scale=6, nullable=true)
  46.      * @Assert\Range(min="0", max="10")
  47.      */
  48.     public $average;
  49.     /**
  50.      * @return string
  51.      */
  52.     public function __toString()
  53.     {
  54.         return $this->name;
  55.     }
  56.     public function getId(): ?int
  57.     {
  58.         return $this->id;
  59.     }
  60.     public function getName(): ?string
  61.     {
  62.         return $this->name;
  63.     }
  64.     public function setName(string $name): self
  65.     {
  66.         $this->name $name;
  67.         return $this;
  68.     }
  69.     public function getAverage()
  70.     {
  71.         return $this->average;
  72.     }
  73.     public function setAverage($average): self
  74.     {
  75.         $this->average $average;
  76.         return $this;
  77.     }
  78. }