src/Entity/Order.php line 20

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\OrderRepository;
  4. use DateTime;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. use Gedmo\Blameable\Traits\BlameableEntity;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use ApiPlatform\Metadata\ApiResource;
  10. use ApiPlatform\Metadata\ApiFilter;
  11. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  12. #[ORM\Entity(repositoryClassOrderRepository::class)]
  13. #[ORM\Table(name'`order`')]
  14. #[ApiResource]
  15. #[ApiFilter(SearchFilter::class, properties: ["user" => "exact"])]
  16. class Order
  17. {
  18.     use BlameableEntity;
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column(type'integer')]
  22.     #[Groups([
  23.         'order_get',
  24.         'order_getc',
  25.         'user_get_me'
  26.     ])]
  27.     private ?int $id null;
  28.     #[ORM\Column]
  29.     #[Groups([
  30.         'order_get',
  31.         'order_getc',
  32.         'order_post',
  33.         'user_get_me'
  34.     ])]
  35.     private ?int $quantity null;
  36.     #[ORM\Column]
  37.     #[Groups([
  38.         'order_get''order_getc''order_post',
  39.         'user_get_me'
  40.     ])]
  41.     private ?float $price null;
  42.     #[ORM\ManyToOne(
  43.         targetEntityUser::class,
  44.         inversedBy'orders',
  45.         fetch'EAGER'
  46.         )
  47.     ]
  48.     #[ORM\JoinColumn(nullablefalse)]
  49.     #[Groups([
  50.         'order_get',
  51.         'order_getc',
  52.         'order_post',
  53.         'order_put',
  54.         'user_get_me',
  55.         'user_get'
  56.     ])]
  57.     #[Assert\NotNull(groups: [ 'order_post''order_put' ])]
  58.     private ?User $user null;
  59.     #[ORM\Column]
  60.     #[Groups([
  61.         'order_get''order_getc''order_post''user_get_me'
  62.     ])]
  63.     private ?DateTime $createdAt null;
  64.     #[ORM\Column]
  65.     #[Groups([
  66.         'order_get''order_getc''order_post''order_put''user_get_me'
  67.     ])]
  68.     private ?bool $isPayed null;
  69.     public function __construct()
  70.     {
  71.         $this->createdAt = new DateTime();
  72.     }
  73.     public function getId(): ?int
  74.     {
  75.         return $this->id;
  76.     }
  77.     public function getQuantity(): ?int
  78.     {
  79.         return $this->quantity;
  80.     }
  81.     public function setQuantity(int $quantity): static
  82.     {
  83.         $this->quantity $quantity;
  84.         return $this;
  85.     }
  86.     public function getPrice(): ?float
  87.     {
  88.         return $this->price;
  89.     }
  90.     public function setPrice(float $price): static
  91.     {
  92.         $this->price $price;
  93.         return $this;
  94.     }
  95.     public function getUser(): ?User
  96.     {
  97.         return $this->user;
  98.     }
  99.     public function setUser(?User $user): static
  100.     {
  101.         $this->user $user;
  102.         return $this;
  103.     }
  104.     public function getCreatedAt(): ?DateTime
  105.     {
  106.         return $this->createdAt;
  107.     }
  108.     public function setCreatedAt(DateTime $createdAt): static
  109.     {
  110.         $this->createdAt $createdAt;
  111.         return $this;
  112.     }
  113.     public function isIsPayed(): ?bool
  114.     {
  115.         return $this->isPayed;
  116.     }
  117.     public function setIsPayed(bool $isPayed): static
  118.     {
  119.         $this->isPayed $isPayed;
  120.         return $this;
  121.     }
  122. }