src/Entity/Notification.php line 32

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use ApiPlatform\Metadata\Post;
  7. use ApiPlatform\Metadata\Put;
  8. use ApiPlatform\Metadata\Patch;
  9. use App\Repository\NotificationRepository;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  13. use ApiPlatform\Metadata\ApiFilter;
  14. #[ORM\Entity(repositoryClassNotificationRepository::class)]
  15. #[ApiResource(
  16.     normalizationContext: ['groups' => ['read:notification']],
  17.     denormalizationContext: ['groups' => ['write:notification']],
  18.     operations: [
  19.         new Get(),
  20.         new GetCollection(),
  21.         new Post(),
  22.         new Put(),
  23.         new Patch(),
  24.     ],
  25.     paginationEnabledtrue,
  26.     paginationItemsPerPage50
  27. ),
  28. ApiFilter(SearchFilter::class, properties: ['user' => 'exact''lu' => 'exact'])]
  29. class Notification
  30. {
  31.     #[ORM\Id]
  32.     #[ORM\GeneratedValue]
  33.     #[ORM\Column]
  34.     #[Groups(['read:notification''write:notification'])]
  35.     private ?int $id null;
  36.     #[ORM\ManyToOne(targetEntityUser::class)]
  37.     #[ORM\JoinColumn(nullablefalse)]
  38.     #[Groups(['read:notification''write:notification'])]
  39.     private ?User $user null;
  40.     #[ORM\Column(length255)]
  41.     #[Groups(['read:notification''write:notification'])]
  42.     private ?string $titre null;
  43.     #[ORM\Column(type'text')]
  44.     #[Groups(['read:notification''write:notification'])]
  45.     private ?string $message null;
  46.     #[ORM\Column(type'boolean')]
  47.     #[Groups(['read:notification''write:notification'])]
  48.     private ?bool $lu false;
  49.     #[ORM\Column(type'datetime')]
  50.     #[Groups(['read:notification''write:notification'])]
  51.     private ?\DateTimeInterface $dateCreation null;
  52.     #[ORM\Column(length50nullabletrue)]
  53.     #[Groups(['read:notification''write:notification'])]
  54.     private ?string $type null// 'bienvenue', 'achat', 'preuve_soumise'
  55.     public function __construct()
  56.     {
  57.         $this->dateCreation = new \DateTime();
  58.         $this->lu false;
  59.     }
  60.     public function getId(): ?int
  61.     {
  62.         return $this->id;
  63.     }
  64.     public function getUser(): ?User
  65.     {
  66.         return $this->user;
  67.     }
  68.     public function setUser(?User $user): self
  69.     {
  70.         $this->user $user;
  71.         return $this;
  72.     }
  73.     public function getTitre(): ?string
  74.     {
  75.         return $this->titre;
  76.     }
  77.     public function setTitre(string $titre): self
  78.     {
  79.         $this->titre $titre;
  80.         return $this;
  81.     }
  82.     public function getMessage(): ?string
  83.     {
  84.         return $this->message;
  85.     }
  86.     public function setMessage(string $message): self
  87.     {
  88.         $this->message $message;
  89.         return $this;
  90.     }
  91.     public function isLu(): bool
  92.     {
  93.         return $this->lu ?? false;
  94.     }
  95.     public function getLu(): bool
  96.     {
  97.         return $this->lu ?? false;
  98.     }
  99.     public function setLu(bool $lu): self
  100.     {
  101.         $this->lu $lu;
  102.         return $this;
  103.     }
  104.     public function getDateCreation(): ?\DateTimeInterface
  105.     {
  106.         return $this->dateCreation;
  107.     }
  108.     public function setDateCreation(\DateTimeInterface $dateCreation): self
  109.     {
  110.         $this->dateCreation $dateCreation;
  111.         return $this;
  112.     }
  113.     public function getType(): ?string
  114.     {
  115.         return $this->type;
  116.     }
  117.     public function setType(?string $type): self
  118.     {
  119.         $this->type $type;
  120.         return $this;
  121.     }
  122. }