src/Entity/Berth.php line 50

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use ApiPlatform\Core\Annotation\ApiProperty;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  9. use App\Trait\TimestampableEntity;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use Ramsey\Uuid\Uuid;
  14. use Ramsey\Uuid\UuidInterface;
  15. #[ORM\Entity]
  16. #[ApiResource(
  17.     iri'Berth',
  18.     collectionOperations: [],
  19.     itemOperations: [
  20.         'get' => [
  21.             'security' => "is_granted('ROLE_USER')",
  22.             'method' => 'GET',
  23.             'path' => '/ports/berths/{id}',
  24.             'openapi_context' => [
  25.                 'tags' => ['Port / Berth']
  26.             ]
  27.         ]
  28.     ],
  29.     attributes: ['pagination_enabled' => false]
  30. )]
  31. #[ApiFilter(
  32.     SearchFilter::class,
  33.     properties: [
  34.         'port' => 'exact'
  35.         'berthName' => 'partial'
  36.         'createdAt' => 'start'
  37.     ],
  38. )]
  39. #[ApiFilter(
  40.     OrderFilter::class,
  41.     properties: [
  42.         'berthName'
  43.         'createdAt'
  44.     ],
  45. )]
  46. class Berth
  47. {
  48.     use TimestampableEntity;
  49.     
  50.     #[ORM\Id]
  51.     #[ORM\GeneratedValue(strategy'NONE')]
  52.     #[ORM\Column(type'uuid'uniquetrue)]
  53.     private ?UuidInterface $id null;
  54.     #[ORM\Column(type'string'nullablefalse)]
  55.     #[ApiProperty()]
  56.     #[Assert\NotBlank]
  57.     #[Groups([
  58.         // 'port:collection:get', 
  59.         'port:collection:post'
  60.         'port:item:get'
  61.         'port:item:put',
  62.     ])]
  63.     private ?string $berthName null;
  64.     #[ORM\Column(type'string'nullabletrue)]
  65.     #[ApiProperty()]
  66.     #[Groups([
  67.         // 'port:collection:get', 
  68.         'port:collection:post'
  69.         'port:item:get'
  70.         'port:item:put'
  71.     ])]
  72.     private ?string $restrictionInfoSource null;
  73.     #[ORM\Column(type'text'nullabletrue)]
  74.     #[ApiProperty()]
  75.     #[Groups([
  76.         // 'port:collection:get', 
  77.         'port:collection:post'
  78.         'port:item:get'
  79.         'port:item:put'
  80.     ])]
  81.     private ?string $observations null;
  82.     #[ORM\ManyToOne(
  83.         targetEntityPort::class, 
  84.         inversedBy'berths'
  85.     )]
  86.     #[ORM\JoinColumn(nullabletrue)]
  87.     private ?Port $port null;
  88.     public function __construct()
  89.     {
  90.         $this->id Uuid::uuid4();
  91.     }
  92.     public function getId(): ?UuidInterface
  93.     {
  94.         return $this->id;
  95.     }
  96.     public function setBerthName(?string $berthName): void
  97.     {
  98.         $this->berthName $berthName;
  99.     }
  100.     public function getBerthName(): ?string
  101.     {
  102.         return $this->berthName;
  103.     }
  104.     public function setRestrictionInfoSource(?string $restrictionInfoSource): void
  105.     {
  106.         $this->restrictionInfoSource $restrictionInfoSource;
  107.     }
  108.     public function getRestrictionInfoSource(): ?string
  109.     {
  110.         return $this->restrictionInfoSource;
  111.     }
  112.     public function setObservations(?string $observations): void
  113.     {
  114.         $this->observations $observations;
  115.     }
  116.     public function getObservations(): ?string
  117.     {
  118.         return $this->observations;
  119.     }
  120.     public function setPort(?Port $port): void
  121.     {
  122.         $this->port $port;
  123.     }
  124.     public function getPort(): ?Port
  125.     {
  126.         return $this->port;
  127.     }
  128. }