<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiFilter;
use App\Entity\Traits\TimestampableEntity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Interfaces\OwnerMappedInterface;
use App\Repository\NewsfeedSavedRepository;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
/**
* @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')", "filters"={"translation.groups"}},
* normalizationContext={"groups"={"NewsfeedSaved:Read"}, "skip_null_values"=false},
* denormalizationContext={"groups"={"NewsfeedSaved:Write"}},
* collectionOperations={
* "get"={"security"="is_granted('ROLE_ADMIN')"},
* "get_my"={
* "path"="/newsfeed_saveds/get-my",
* "method"="GET",
* "security"="is_granted('IS_AUTHENTICATED_FULLY')"
* },
* "post"={
* "security"="is_granted('IS_AUTHENTICATED_FULLY')"
* }
* },
* itemOperations={
* "get"={"security"="is_granted('ROLE_ADMIN', object) || is_granted('IS_ANY_SPE', object)"},
* "delete"={"security"="is_granted('ROLE_ADMIN', object) || is_granted('IS_ANY_SPE', object)"}
* }
* )
* @ApiFilter(SearchFilter::class, properties={"newsfeed.id": "exact", "user.id": "exact"})
* @ApiFilter(DateFilter::class, properties={"createdAt"})
* @ApiFilter(OrderFilter::class, properties={"id": "DESC", "createdAt"})
* @ORM\Entity(repositoryClass=NewsfeedSavedRepository::class)
*/
class NewsfeedSaved implements OwnerMappedInterface
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"NewsfeedSaved:Read"})
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"NewsfeedSaved:Read"})
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity=Newsfeed::class, inversedBy="newsfeedSaved")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"NewsfeedSaved:Write", "NewsfeedSaved:Read"})
*/
private $newsfeed;
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getNewsfeed(): ?Newsfeed
{
return $this->newsfeed;
}
public function setNewsfeed(?Newsfeed $newsfeed): self
{
$this->newsfeed = $newsfeed;
return $this;
}
}