src/Entity/Ethnicity.php line 29

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 App\Controller\EthnicityController;
  9. use Doctrine\ORM\Mapping as ORM;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\EthnicityRepository")
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. #[ApiResource(collectionOperations: [
  15.     'get''post',
  16.     'ethnicity_list' => [
  17.         'method' => 'GET',
  18.         'path' => '/ethnicity/list',
  19.         'controller' => EthnicityController::class,
  20.     ],
  21. ], itemOperations: ['get''put'])]
  22. #[ApiFilter(PropertyFilter::class)]
  23. #[ApiFilter(SearchFilter::class, properties: ['id''name' => SearchFilter::STRATEGY_PARTIAL])]
  24. #[ApiFilter(OrderFilter::class, properties: ['id''name'], arguments: ['orderParameterName' => 'order'])]
  25. class Ethnicity
  26. {
  27.     /**
  28.      * @ORM\Id
  29.      * @ORM\GeneratedValue
  30.      * @ORM\Column(type="integer")
  31.      */
  32.     private $id;
  33.     /**
  34.      * @ORM\Column(type="string", length=128)
  35.      */
  36.     private $name;
  37.     /**
  38.      * @var string
  39.      *
  40.      * @ORM\Column(type="text", nullable=true)
  41.      */
  42.     private $detail;
  43.     public function __toString(): string
  44.     {
  45.         return $this->getName() . ((null !== $this->getDetail()) ? ' ' $this->getDetail() : '');
  46.     }
  47.     public function getId(): ?int
  48.     {
  49.         return $this->id;
  50.     }
  51.     public function getName(): ?string
  52.     {
  53.         return $this->name;
  54.     }
  55.     public function setName(string $name): self
  56.     {
  57.         $this->name $name;
  58.         return $this;
  59.     }
  60.     public function getDetail(): ?string
  61.     {
  62.         return $this->detail;
  63.     }
  64.     public function setDetail(?string $detail): self
  65.     {
  66.         $this->detail $detail;
  67.         return $this;
  68.     }
  69. }