src/Entity/Race.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 App\Controller\RaceController;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Gedmo\Mapping\Annotation as Gedmo;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * @ORM\Entity(repositoryClass="App\Repository\RaceRepository")
  14.  * @ORM\HasLifecycleCallbacks()
  15.  */
  16. #[ApiResource(collectionOperations: [
  17.     'get',
  18.     'post',
  19.     'race_list' => [
  20.         'method' => 'GET',
  21.         'path' => '/race/list',
  22.         'controller' => RaceController::class,
  23.     ],
  24. ], itemOperations: ['get''put'])]
  25. #[ApiFilter(PropertyFilter::class)]
  26. #[ApiFilter(SearchFilter::class, properties: ['id''name' => 'partial'])]
  27. #[ApiFilter(OrderFilter::class, properties: ['id''name'], arguments: ['orderParameterName' => 'order'])]
  28. class Race
  29. {
  30.     /**
  31.      * @ORM\Id()
  32.      * @ORM\GeneratedValue()
  33.      * @ORM\Column(type="integer")
  34.      */
  35.     private $id;
  36.     /**
  37.      * @ORM\Column(type="string", length=128)
  38.      * @Assert\NotBlank()
  39.      * @Assert\Length(max=128)
  40.      */
  41.     private $name;
  42.     /**
  43.      * @ORM\Column(type="text", nullable=true)
  44.      */
  45.     private $detail;
  46.     /**
  47.      * @var string
  48.      *
  49.      * @ORM\Column(type="string", length=128)
  50.      * @Gedmo\Slug(fields={"name"})
  51.      */
  52.     private $slug;
  53.     /**
  54.      * @var bool
  55.      *
  56.      * @ORM\Column(type="boolean")
  57.      * @Assert\Type(type="boolean")
  58.      */
  59.     private $other;
  60.     public function __toString(): string
  61.     {
  62.         return $this->getName().((null !== $this->getDetail()) ? ' '.$this->getDetail() : '');
  63.     }
  64.     public function getId(): ?int
  65.     {
  66.         return $this->id;
  67.     }
  68.     public function getName(): ?string
  69.     {
  70.         return $this->name;
  71.     }
  72.     public function setName(string $name): self
  73.     {
  74.         $this->name $name;
  75.         return $this;
  76.     }
  77.     /**
  78.      * @param mixed $detail
  79.      */
  80.     public function setDetail(string $detail): self
  81.     {
  82.         $this->detail $detail;
  83.         return $this;
  84.     }
  85.     public function getDetail(): ?string
  86.     {
  87.         return $this->detail;
  88.     }
  89.     public function getOther(): ?bool
  90.     {
  91.         return $this->other;
  92.     }
  93.     public function setOther(bool $other): self
  94.     {
  95.         $this->other $other;
  96.         return $this;
  97.     }
  98.     public function getSlug(): ?string
  99.     {
  100.         return $this->slug;
  101.     }
  102.     public function setSlug(string $slug): self
  103.     {
  104.         $this->slug $slug;
  105.         return $this;
  106.     }
  107. }