88 lines
1.9 KiB
PHP
88 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use ApiPlatform\Doctrine\Common\Filter\SearchFilterInterface;
|
|
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
|
|
use ApiPlatform\Metadata\ApiFilter;
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
use ApiPlatform\Metadata\Get;
|
|
use ApiPlatform\Metadata\GetCollection;
|
|
use ApiPlatform\Metadata\QueryParameter;
|
|
use App\Repository\CarRepository;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
#[ORM\Entity(repositoryClass: CarRepository::class)]
|
|
#[ApiResource(
|
|
operations: [
|
|
new Get(),
|
|
new GetCollection(),
|
|
]
|
|
)]
|
|
#[QueryParameter(key: ':property', filter: SearchFilter::class)]
|
|
class Car
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
|
|
public function __construct(
|
|
#[ORM\Column(length: 6, unique: true)]
|
|
#[ApiFilter(SearchFilter::class, strategy: 'exact')]
|
|
private ?string $registrationPlate = null,
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $location = null,
|
|
|
|
#[ORM\ManyToOne(inversedBy: 'cars')]
|
|
#[ORM\JoinColumn(nullable: false)]
|
|
private ?CarModel $model = null,
|
|
) {
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getRegistrationPlate(): ?string
|
|
{
|
|
return $this->registrationPlate;
|
|
}
|
|
|
|
public function setRegistrationPlate(string $registrationPlate): static
|
|
{
|
|
$this->registrationPlate = $registrationPlate;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getLocation(): ?string
|
|
{
|
|
return $this->location;
|
|
}
|
|
|
|
public function setLocation(string $location): static
|
|
{
|
|
$this->location = $location;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getModel(): ?CarModel
|
|
{
|
|
return $this->model;
|
|
}
|
|
|
|
public function setModel(?CarModel $model): static
|
|
{
|
|
$this->model = $model;
|
|
|
|
return $this;
|
|
}
|
|
}
|