src/Entity/NewsfeedSaved.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use App\Entity\Traits\TimestampableEntity;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use App\Entity\Interfaces\OwnerMappedInterface;
  8. use App\Repository\NewsfeedSavedRepository;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  11. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  12. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  13. /**
  14.  * @ApiResource(
  15.  *      attributes={"security"="is_granted('ROLE_ADMIN')", "filters"={"translation.groups"}},
  16.  *      normalizationContext={"groups"={"NewsfeedSaved:Read"}, "skip_null_values"=false},
  17.  *      denormalizationContext={"groups"={"NewsfeedSaved:Write"}},
  18.  *      collectionOperations={
  19.  *          "get"={"security"="is_granted('ROLE_ADMIN')"},
  20.  *          "get_my"={
  21.  *              "path"="/newsfeed_saveds/get-my",
  22.  *              "method"="GET",
  23.  *              "security"="is_granted('IS_AUTHENTICATED_FULLY')"
  24.  *          },
  25.  *          "post"={
  26.  *              "security"="is_granted('IS_AUTHENTICATED_FULLY')"
  27.  *          }
  28.  *      },
  29.  *      itemOperations={
  30.  *          "get"={"security"="is_granted('ROLE_ADMIN', object) || is_granted('IS_ANY_SPE', object)"},
  31.  *          "delete"={"security"="is_granted('ROLE_ADMIN', object) || is_granted('IS_ANY_SPE', object)"}
  32.  *     }
  33.  * )
  34.  * @ApiFilter(SearchFilter::class, properties={"newsfeed.id": "exact", "user.id": "exact"})
  35.  * @ApiFilter(DateFilter::class, properties={"createdAt"})
  36.  * @ApiFilter(OrderFilter::class, properties={"id": "DESC", "createdAt"})
  37.  * @ORM\Entity(repositoryClass=NewsfeedSavedRepository::class)
  38.  */
  39. class NewsfeedSaved implements OwnerMappedInterface
  40. {
  41.     /**
  42.      * Hook timestampable behavior
  43.      * updates createdAt, updatedAt fields
  44.      */
  45.     use TimestampableEntity;
  46.     /**
  47.      * @ORM\Id
  48.      * @ORM\GeneratedValue
  49.      * @ORM\Column(type="integer")
  50.      * @Groups({"NewsfeedSaved:Read"})
  51.      */
  52.     private $id;
  53.     /**
  54.      * @ORM\ManyToOne(targetEntity=User::class)
  55.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  56.      * @Groups({"NewsfeedSaved:Read"})
  57.      */
  58.     private $user;
  59.     /**
  60.      * @ORM\ManyToOne(targetEntity=Newsfeed::class, inversedBy="newsfeedSaved")
  61.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  62.      * @Groups({"NewsfeedSaved:Write", "NewsfeedSaved:Read"})
  63.      */
  64.     private $newsfeed;
  65.     public function getId(): ?int
  66.     {
  67.         return $this->id;
  68.     }
  69.     public function getUser(): ?User
  70.     {
  71.         return $this->user;
  72.     }
  73.     public function setUser(?User $user): self
  74.     {
  75.         $this->user $user;
  76.         return $this;
  77.     }
  78.     public function getNewsfeed(): ?Newsfeed
  79.     {
  80.         return $this->newsfeed;
  81.     }
  82.     public function setNewsfeed(?Newsfeed $newsfeed): self
  83.     {
  84.         $this->newsfeed $newsfeed;
  85.         return $this;
  86.     }
  87. }