<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use App\Controller\RaceController;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\RaceRepository")
* @ORM\HasLifecycleCallbacks()
*/
#[ApiResource(collectionOperations: [
'get',
'post',
'race_list' => [
'method' => 'GET',
'path' => '/race/list',
'controller' => RaceController::class,
],
], itemOperations: ['get', 'put'])]
#[ApiFilter(PropertyFilter::class)]
#[ApiFilter(SearchFilter::class, properties: ['id', 'name' => 'partial'])]
#[ApiFilter(OrderFilter::class, properties: ['id', 'name'], arguments: ['orderParameterName' => 'order'])]
class Race
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=128)
* @Assert\NotBlank()
* @Assert\Length(max=128)
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $detail;
/**
* @var string
*
* @ORM\Column(type="string", length=128)
* @Gedmo\Slug(fields={"name"})
*/
private $slug;
/**
* @var bool
*
* @ORM\Column(type="boolean")
* @Assert\Type(type="boolean")
*/
private $other;
public function __toString(): string
{
return $this->getName().((null !== $this->getDetail()) ? ' '.$this->getDetail() : '');
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @param mixed $detail
*/
public function setDetail(string $detail): self
{
$this->detail = $detail;
return $this;
}
public function getDetail(): ?string
{
return $this->detail;
}
public function getOther(): ?bool
{
return $this->other;
}
public function setOther(bool $other): self
{
$this->other = $other;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
}