<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use App\Trait\TimestampableEntity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
#[ORM\Entity]
#[ApiResource(
iri: 'Berth',
collectionOperations: [],
itemOperations: [
'get' => [
'security' => "is_granted('ROLE_USER')",
'method' => 'GET',
'path' => '/ports/berths/{id}',
'openapi_context' => [
'tags' => ['Port / Berth']
]
]
],
attributes: ['pagination_enabled' => false]
)]
#[ApiFilter(
SearchFilter::class,
properties: [
'port' => 'exact',
'berthName' => 'partial',
'createdAt' => 'start'
],
)]
#[ApiFilter(
OrderFilter::class,
properties: [
'berthName',
'createdAt'
],
)]
class Berth
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: 'uuid', unique: true)]
private ?UuidInterface $id = null;
#[ORM\Column(type: 'string', nullable: false)]
#[ApiProperty()]
#[Assert\NotBlank]
#[Groups([
// 'port:collection:get',
'port:collection:post',
'port:item:get',
'port:item:put',
])]
private ?string $berthName = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Groups([
// 'port:collection:get',
'port:collection:post',
'port:item:get',
'port:item:put'
])]
private ?string $restrictionInfoSource = null;
#[ORM\Column(type: 'text', nullable: true)]
#[ApiProperty()]
#[Groups([
// 'port:collection:get',
'port:collection:post',
'port:item:get',
'port:item:put'
])]
private ?string $observations = null;
#[ORM\ManyToOne(
targetEntity: Port::class,
inversedBy: 'berths'
)]
#[ORM\JoinColumn(nullable: true)]
private ?Port $port = null;
public function __construct()
{
$this->id = Uuid::uuid4();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function setBerthName(?string $berthName): void
{
$this->berthName = $berthName;
}
public function getBerthName(): ?string
{
return $this->berthName;
}
public function setRestrictionInfoSource(?string $restrictionInfoSource): void
{
$this->restrictionInfoSource = $restrictionInfoSource;
}
public function getRestrictionInfoSource(): ?string
{
return $this->restrictionInfoSource;
}
public function setObservations(?string $observations): void
{
$this->observations = $observations;
}
public function getObservations(): ?string
{
return $this->observations;
}
public function setPort(?Port $port): void
{
$this->port = $port;
}
public function getPort(): ?Port
{
return $this->port;
}
}