|
4 | 4 |
|
5 | 5 | use ApiPlatform\Core\Annotation\ApiResource;
|
6 | 6 | use App\Repository\MovieRepository;
|
| 7 | +use Doctrine\Common\Collections\ArrayCollection; |
| 8 | +use Doctrine\Common\Collections\Collection; |
7 | 9 | use Doctrine\ORM\Mapping as ORM;
|
8 | 10 | use App\Controller\CustomMovieAction;
|
9 | 11 | use Symfony\Component\Serializer\Annotation\Groups;
|
| 12 | +use ApiPlatform\Core\Annotation\ApiSubresource; |
10 | 13 |
|
11 | 14 | /**
|
12 | 15 | * @ApiResource(
|
@@ -49,6 +52,17 @@ class Movie
|
49 | 52 | */
|
50 | 53 | private $isPublished;
|
51 | 54 |
|
| 55 | + /** |
| 56 | + * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="movie") |
| 57 | + * @ApiSubresource() |
| 58 | + */ |
| 59 | + private $comments; |
| 60 | + |
| 61 | + public function __construct() |
| 62 | + { |
| 63 | + $this->comments = new ArrayCollection(); |
| 64 | + } |
| 65 | + |
52 | 66 | public function getId(): ?int
|
53 | 67 | {
|
54 | 68 | return $this->id;
|
@@ -77,4 +91,34 @@ public function setIsPublished(bool $isPublished): self
|
77 | 91 |
|
78 | 92 | return $this;
|
79 | 93 | }
|
| 94 | + |
| 95 | + /** |
| 96 | + * @return Collection|Comment[] |
| 97 | + */ |
| 98 | + public function getComments(): Collection |
| 99 | + { |
| 100 | + return $this->comments; |
| 101 | + } |
| 102 | + |
| 103 | + public function addComment(Comment $comment): self |
| 104 | + { |
| 105 | + if (!$this->comments->contains($comment)) { |
| 106 | + $this->comments[] = $comment; |
| 107 | + $comment->setMovie($this); |
| 108 | + } |
| 109 | + |
| 110 | + return $this; |
| 111 | + } |
| 112 | + |
| 113 | + public function removeComment(Comment $comment): self |
| 114 | + { |
| 115 | + if ($this->comments->removeElement($comment)) { |
| 116 | + // set the owning side to null (unless already changed) |
| 117 | + if ($comment->getMovie() === $this) { |
| 118 | + $comment->setMovie(null); |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + return $this; |
| 123 | + } |
80 | 124 | }
|
0 commit comments