src/Entity/MarketRumorPort.php line 33

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiProperty;
  5. use ApiPlatform\Core\Annotation\ApiResource;
  6. use App\Trait\TimestampableEntity;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Component\Serializer\Annotation\MaxDepth;
  11. use Ramsey\Uuid\Uuid;
  12. use Ramsey\Uuid\UuidInterface;
  13. #[ORM\Entity]
  14. #[ApiResource(
  15.     iri'MarketRumorPort',
  16.     collectionOperations: [],
  17.     itemOperations: [
  18.         'get' => [
  19.             'security' => "is_granted('ROLE_USER')",
  20.             'method' => 'GET',
  21.             'path' => '/market_rumors/ports/{id}',
  22.             'openapi_context' => [
  23.                 'tags' => ['MarketRumor / Port']
  24.             ]
  25.         ]
  26.     ],
  27.     attributes: ['pagination_enabled' => false]
  28. )]
  29. class MarketRumorPort
  30. {
  31.     use TimestampableEntity;
  32.     public const PORT_CALL_TYPE_LOAD 'Load';
  33.     public const PORT_CALL_TYPE_DISCHARGE 'Discharge';
  34.     public const PORT_CALL_TYPES = [
  35.         self::PORT_CALL_TYPE_LOAD,
  36.         self::PORT_CALL_TYPE_DISCHARGE
  37.     ];
  38.     
  39.     #[ORM\Id]
  40.     #[ORM\GeneratedValue(strategy'NONE')]
  41.     #[ORM\Column(type'uuid'uniquetrue)]
  42.     private ?UuidInterface $id null;
  43.     #[ORM\Column(type'string'nullablefalse)]
  44.     #[ApiProperty()]
  45.     #[Assert\NotBlank]
  46.     #[Assert\Type('string')]
  47.     #[Assert\Choice(
  48.         choicesself::PORT_CALL_TYPES
  49.         message'The type is not valid.'
  50.     )]
  51.     #[Groups([
  52.         'market_rumor:item:get'
  53.         'market_rumor:item:put'
  54.         'market_rumor:collection:get'
  55.         'market_rumor:collection:post'
  56.     ])]
  57.     private ?string $portCallType null;
  58.     #[ORM\ManyToOne(
  59.         targetEntityPort::class, 
  60.         inversedBy'portCalls'
  61.     )]
  62.     #[ORM\JoinColumn(nullabletrue)]
  63.     #[ApiProperty()]
  64.     #[Groups([
  65.         'market_rumor:item:get'
  66.         'market_rumor:item:put'
  67.         'market_rumor:collection:get'
  68.         'market_rumor:collection:post'
  69.     ])]
  70.     #[MaxDepth(1)]
  71.     private ?Port $port null;
  72.     #[ORM\Column(type'integer')]
  73.     #[Assert\NotNull]
  74.     #[ApiProperty()]
  75.     #[Groups([
  76.         'market_rumor:item:get'
  77.         'market_rumor:item:put'
  78.         'market_rumor:collection:get'
  79.         'market_rumor:collection:post'
  80.     ])]
  81.     private ?int $portIndex 0;
  82.     #[ORM\ManyToOne(
  83.         targetEntityMarketRumor::class, 
  84.         inversedBy'portCalls'
  85.     )]
  86.     #[ORM\JoinColumn(nullabletrue)]
  87.     private ?MarketRumor $marketRumor 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 setPortCallType(?string $portCallType): void
  97.     {
  98.         $this->portCallType $portCallType;
  99.     }
  100.     public function getPortCallType(): ?string
  101.     {
  102.         return $this->portCallType;
  103.     }
  104.     public function setPort(?Port $port): void
  105.     {
  106.         $this->port $port;
  107.     }
  108.     public function getPort(): ?Port
  109.     {
  110.         return $this->port;
  111.     }
  112.     public function setPortIndex(?int $portIndex): void
  113.     {
  114.         $this->portIndex $portIndex;
  115.     }
  116.     public function getPortIndex(): ?int
  117.     {
  118.         return $this->portIndex;
  119.     }
  120.     public function setMarketRumor(?MarketRumor $marketRumor): void
  121.     {
  122.         $this->marketRumor $marketRumor;
  123.     }
  124.     public function getMarketRumor(): ?MarketRumor
  125.     {
  126.         return $this->marketRumor;
  127.     }
  128. }