Skip to content
This repository was archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Add 26.3: Exposing an API for Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Feb 13, 2022
1 parent d13e0b2 commit 79d558b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Entity/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,58 @@

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use App\Repository\CommentRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;

#[ORM\Entity(repositoryClass: CommentRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[ApiResource(
collectionOperations: ['get' => ['normalization_context' => ['groups' => 'comment:list']]],
itemOperations: ['get' => ['normalization_context' => ['groups' => 'comment:item']]],
order: ['createdAt' => 'DESC'],
paginationEnabled: false,
)]
#[ApiFilter(SearchFilter::class, properties: ['conference' => 'exact'])]
class Comment
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Groups(['comment:list', 'comment:item'])]
private $id;

#[ORM\Column(type: 'string', length: 255)]
#[Assert\NotBlank]
#[Groups(['comment:list', 'comment:item'])]
private $author;

#[ORM\Column(type: 'text')]
#[Assert\NotBlank]
#[Groups(['comment:list', 'comment:item'])]
private $text;

#[ORM\Column(type: 'string', length: 255)]
#[Assert\NotBlank]
#[Assert\Email]
#[Groups(['comment:list', 'comment:item'])]
private $email;

#[ORM\Column(type: 'datetime_immutable')]
#[Groups(['comment:list', 'comment:item'])]
private $createdAt;

#[ORM\ManyToOne(targetEntity: Conference::class, inversedBy: 'comments')]
#[ORM\JoinColumn(nullable: false)]
#[Groups(['comment:list', 'comment:item'])]
private $conference;

#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['comment:list', 'comment:item'])]
private $photoFilename;

#[ORM\Column(type: 'string', length: 255, options: ["default" => "submitted"])]
Expand Down

0 comments on commit 79d558b

Please sign in to comment.