mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
⚡ expose config for poll
This commit is contained in:
parent
9123faf3f1
commit
7e79048b59
@ -42,19 +42,6 @@ class DefaultController extends AbstractController {
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get(
|
||||
* path = "/poll/{id}/comments",
|
||||
* name = "get_poll_comment",
|
||||
* requirements = {"id"="\d+"}
|
||||
* )
|
||||
*/
|
||||
public function getPollCommentsAction() {
|
||||
return $this->json( [
|
||||
'message' => 'here are your comments of the poll',
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get(
|
||||
* path = "/poll/all",
|
||||
@ -109,7 +96,6 @@ class DefaultController extends AbstractController {
|
||||
$owner->setEmail( $data[ 'owner' ][ 'email' ] );
|
||||
$foundOwner = $owner;
|
||||
} else {
|
||||
// die( $foundOwner->getPseudo() );
|
||||
$userWasFound = true;
|
||||
}
|
||||
// link the owner and the poll
|
||||
@ -133,6 +119,20 @@ class DefaultController extends AbstractController {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get(
|
||||
* path = "/poll/{id}/comments",
|
||||
* name = "get_poll_comment",
|
||||
* requirements = {"id"="\d+"}
|
||||
* )
|
||||
*/
|
||||
public function getPollCommentsAction( Poll $poll ) {
|
||||
return $this->json( [
|
||||
'message' => 'here are your comments of the poll',
|
||||
'data' => $poll->getComments(),
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get(
|
||||
* path = "/poll/{id}",
|
||||
|
@ -5,6 +5,7 @@ namespace App\Entity;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass="App\Repository\ChoiceRepository")
|
||||
@ -19,113 +20,110 @@ class Choice {
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @Serializer\Type("string")
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime", nullable=true)
|
||||
* @Serializer\Type("datetime")
|
||||
*/
|
||||
private $dateTime;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Poll", mappedBy="choices")
|
||||
* @Serializer\Type("App\Entity\Poll")
|
||||
*/
|
||||
private $poll;
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="choice")
|
||||
* @Serializer\Type("App\Entity\Choice")
|
||||
*/
|
||||
private $votes;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->poll = new ArrayCollection();
|
||||
$this->votes = new ArrayCollection();
|
||||
}
|
||||
public function __construct() {
|
||||
$this->poll = new ArrayCollection();
|
||||
$this->votes = new ArrayCollection();
|
||||
}
|
||||
|
||||
|
||||
public function getId(): ?int {
|
||||
return $this->id;
|
||||
}
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): ?string {
|
||||
return $this->name;
|
||||
}
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName( string $name ): self {
|
||||
$this->name = $name;
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateTime(): ?\DateTimeInterface {
|
||||
return $this->dateTime;
|
||||
}
|
||||
return $this->dateTime;
|
||||
}
|
||||
|
||||
public function setDateTime( ?\DateTimeInterface $dateTime ): self {
|
||||
$this->dateTime = $dateTime;
|
||||
$this->dateTime = $dateTime;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Poll[]
|
||||
*/
|
||||
public function getPoll(): Collection
|
||||
{
|
||||
return $this->poll;
|
||||
}
|
||||
/**
|
||||
* @return Collection|Poll[]
|
||||
*/
|
||||
public function getPoll(): Collection {
|
||||
return $this->poll;
|
||||
}
|
||||
|
||||
public function addPoll(Poll $poll): self
|
||||
{
|
||||
if (!$this->poll->contains($poll)) {
|
||||
$this->poll[] = $poll;
|
||||
$poll->setChoices($this);
|
||||
}
|
||||
public function addPoll( Poll $poll ): self {
|
||||
if ( ! $this->poll->contains( $poll ) ) {
|
||||
$this->poll[] = $poll;
|
||||
$poll->setChoices( $this );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removePoll(Poll $poll): self
|
||||
{
|
||||
if ($this->poll->contains($poll)) {
|
||||
$this->poll->removeElement($poll);
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($poll->getChoices() === $this) {
|
||||
$poll->setChoices(null);
|
||||
}
|
||||
}
|
||||
public function removePoll( Poll $poll ): self {
|
||||
if ( $this->poll->contains( $poll ) ) {
|
||||
$this->poll->removeElement( $poll );
|
||||
// set the owning side to null (unless already changed)
|
||||
if ( $poll->getChoices() === $this ) {
|
||||
$poll->setChoices( null );
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Choice[]
|
||||
*/
|
||||
public function getVotes(): Collection
|
||||
{
|
||||
return $this->votes;
|
||||
}
|
||||
/**
|
||||
* @return Collection|Choice[]
|
||||
*/
|
||||
public function getVotes(): Collection {
|
||||
return $this->votes;
|
||||
}
|
||||
|
||||
public function addVote(Choice $vote): self
|
||||
{
|
||||
if (!$this->votes->contains($vote)) {
|
||||
$this->votes[] = $vote;
|
||||
$vote->setChoice($this);
|
||||
}
|
||||
public function addVote( Choice $vote ): self {
|
||||
if ( ! $this->votes->contains( $vote ) ) {
|
||||
$this->votes[] = $vote;
|
||||
$vote->setChoice( $this );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeVote(Choice $vote): self
|
||||
{
|
||||
if ($this->votes->contains($vote)) {
|
||||
$this->votes->removeElement($vote);
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($vote->getChoice() === $this) {
|
||||
$vote->setChoice(null);
|
||||
}
|
||||
}
|
||||
public function removeVote( Choice $vote ): self {
|
||||
if ( $this->votes->contains( $vote ) ) {
|
||||
$this->votes->removeElement( $vote );
|
||||
// set the owning side to null (unless already changed)
|
||||
if ( $vote->getChoice() === $this ) {
|
||||
$vote->setChoice( null );
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
81
src/Entity/Comment.php
Normal file
81
src/Entity/Comment.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass="App\Repository\CommentRepository")
|
||||
*/
|
||||
class Comment {
|
||||
/**
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="text")
|
||||
*/
|
||||
private $owner;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text")
|
||||
*/
|
||||
private $text;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
*/
|
||||
private $createdAt;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="comments")
|
||||
*/
|
||||
private $poll;
|
||||
|
||||
public function getId(): ?int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getOwner(): ?Owner {
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function setOwner( ?Owner $owner ): self {
|
||||
$this->owner = $owner;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getText(): ?string {
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
public function setText( string $text ): self {
|
||||
$this->text = $text;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): ?\DateTimeInterface {
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function setCreatedAt( \DateTimeInterface $createdAt ): self {
|
||||
$this->createdAt = $createdAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPoll(): ?Poll {
|
||||
return $this->poll;
|
||||
}
|
||||
|
||||
public function setPoll( ?Poll $poll ): self {
|
||||
$this->poll = $poll;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -38,8 +38,14 @@ class Owner {
|
||||
*/
|
||||
private $polls;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="owner")
|
||||
*/
|
||||
private $comments;
|
||||
|
||||
public function __construct() {
|
||||
$this->polls = new ArrayCollection();
|
||||
$this->polls = new ArrayCollection();
|
||||
$this->comments = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int {
|
||||
@ -93,4 +99,32 @@ class Owner {
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Comment[]
|
||||
*/
|
||||
public function getComments(): Collection {
|
||||
return $this->comments;
|
||||
}
|
||||
|
||||
public function addText( Comment $text ): self {
|
||||
if ( ! $this->comments->contains( $text ) ) {
|
||||
$this->comments[] = $text;
|
||||
$text->setOwner( $this );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeText( Comment $text ): self {
|
||||
if ( $this->comments->contains( $text ) ) {
|
||||
$this->comments->removeElement( $text );
|
||||
// set the owning side to null (unless already changed)
|
||||
if ( $text->getOwner() === $this ) {
|
||||
$text->setOwner( null );
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class Poll {
|
||||
* @Serializer\Expose()
|
||||
* @Serializer\Type("string")
|
||||
*/
|
||||
private $customUrl;
|
||||
public $customUrl;
|
||||
|
||||
/**
|
||||
* vote restricted by a password in md5 format
|
||||
@ -44,25 +44,25 @@ class Poll {
|
||||
* @Serializer\Expose()
|
||||
* @Serializer\Type("string")
|
||||
*/
|
||||
private $description;
|
||||
public $description;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
private $creationDate;
|
||||
public $creationDate;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
*/
|
||||
private $expiracyDate;
|
||||
public $expiracyDate;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="polls",cascade={"persist"})
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
* @Serializer\Type("App\Entity\Owner")
|
||||
*/
|
||||
private $owner;
|
||||
public $owner;
|
||||
|
||||
/**
|
||||
* used to allow administration
|
||||
@ -91,40 +91,47 @@ class Poll {
|
||||
* @ORM\Column(type="boolean", nullable=true)
|
||||
* @Serializer\Type("boolean")
|
||||
*/
|
||||
private $mailOnComment;
|
||||
public $mailOnComment;
|
||||
/**
|
||||
* send a mail on a new vote
|
||||
* @ORM\Column(type="boolean", nullable=true)
|
||||
* @Serializer\Type("boolean")
|
||||
*/
|
||||
private $mailOnVote;
|
||||
public $mailOnVote;
|
||||
/**
|
||||
* hide publicly results
|
||||
* @ORM\Column(type="boolean", nullable=true)
|
||||
* @Serializer\Type("boolean")
|
||||
*/
|
||||
private $hideResults;
|
||||
public $hideResults;
|
||||
/**
|
||||
* show publicly results even if there is a password to access the vote
|
||||
* @ORM\Column(type="boolean", nullable=true)
|
||||
* @Serializer\Type("boolean")
|
||||
*/
|
||||
private $showResultEvenIfPasswords;
|
||||
public $showResultEvenIfPasswords;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true,cascade={"persist"})
|
||||
* @Serializer\Type("App\Entity\Vote")
|
||||
*/
|
||||
private $votes;
|
||||
public $votes;
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true,cascade={"persist"})
|
||||
* @Serializer\Type("App\Entity\Choice")
|
||||
*/
|
||||
private $choices;
|
||||
public $choices;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll")
|
||||
* @Serializer\Type("App\Entity\Comment")
|
||||
*/
|
||||
public $comments;
|
||||
|
||||
public function __construct() {
|
||||
$this->votes = new ArrayCollection();
|
||||
$this->choices = new ArrayCollection();
|
||||
$this->votes = new ArrayCollection();
|
||||
$this->choices = new ArrayCollection();
|
||||
$this->comments = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int {
|
||||
@ -326,4 +333,32 @@ class Poll {
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Comment[]
|
||||
*/
|
||||
public function getComments(): Collection {
|
||||
return $this->comments;
|
||||
}
|
||||
|
||||
public function addComment( Comment $comment ): self {
|
||||
if ( ! $this->comments->contains( $comment ) ) {
|
||||
$this->comments[] = $comment;
|
||||
$comment->setPoll( $this );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeComment( Comment $comment ): self {
|
||||
if ( $this->comments->contains( $comment ) ) {
|
||||
$this->comments->removeElement( $comment );
|
||||
// set the owning side to null (unless already changed)
|
||||
if ( $comment->getPoll() === $this ) {
|
||||
$comment->setPoll( null );
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass="App\Repository\VoteRepository")
|
||||
@ -12,104 +13,107 @@ class Vote {
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
* @ORM\Column(type="integer")
|
||||
* @Serializer\Type("integer")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @Serializer\Type("string")
|
||||
*/
|
||||
private $pseudo;
|
||||
public $pseudo;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @Serializer\Type("string")
|
||||
*/
|
||||
private $answerTxt;
|
||||
public $answerTxt;
|
||||
/**
|
||||
* @ORM\Column(type="datetime", nullable=true)
|
||||
* @Serializer\Type("datetime")
|
||||
*/
|
||||
private $answerDate;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
* @Serializer\Type("datetime")
|
||||
*/
|
||||
private $creationDate;
|
||||
public $creationDate;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="votes")
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
* @Serializer\Type("App\Entity\Poll")
|
||||
*/
|
||||
private $poll;
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Choice", inversedBy="votes")
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
* @Serializer\Type("App\Entity\choice")
|
||||
*/
|
||||
private $choice;
|
||||
public $choice;
|
||||
|
||||
public function getId(): ?int {
|
||||
return $this->id;
|
||||
}
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getAnswerTxt(): ?string {
|
||||
return $this->answerTxt;
|
||||
}
|
||||
return $this->answerTxt;
|
||||
}
|
||||
|
||||
public function setAnswerTxt( ?string $answerTxt ): self {
|
||||
$this->answerTxt = $answerTxt;
|
||||
$this->answerTxt = $answerTxt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAnswerDate(): ?\DateTimeInterface {
|
||||
return $this->answerDate;
|
||||
}
|
||||
return $this->answerDate;
|
||||
}
|
||||
|
||||
public function setAnswerDate( ?\DateTimeInterface $answerDate ): self {
|
||||
$this->answerDate = $answerDate;
|
||||
$this->answerDate = $answerDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreationDate(): ?\DateTimeInterface {
|
||||
return $this->creationDate;
|
||||
}
|
||||
return $this->creationDate;
|
||||
}
|
||||
|
||||
public function setCreationDate( \DateTimeInterface $creationDate ): self {
|
||||
$this->creationDate = $creationDate;
|
||||
$this->creationDate = $creationDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPoll(): ?Poll {
|
||||
return $this->poll;
|
||||
}
|
||||
return $this->poll;
|
||||
}
|
||||
|
||||
public function setPoll( ?Poll $poll ): self {
|
||||
$this->poll = $poll;
|
||||
$this->poll = $poll;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPseudo(): ?string
|
||||
{
|
||||
return $this->pseudo;
|
||||
}
|
||||
public function getPseudo(): ?string {
|
||||
return $this->pseudo;
|
||||
}
|
||||
|
||||
public function setPseudo(?string $pseudo): self
|
||||
{
|
||||
$this->pseudo = $pseudo;
|
||||
public function setPseudo( ?string $pseudo ): self {
|
||||
$this->pseudo = $pseudo;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getChoice(): ?Choice
|
||||
{
|
||||
return $this->choice;
|
||||
}
|
||||
public function getChoice(): ?Choice {
|
||||
return $this->choice;
|
||||
}
|
||||
|
||||
public function setChoice(?Choice $choice): self
|
||||
{
|
||||
$this->choice = $choice;
|
||||
public function setChoice( ?Choice $choice ): self {
|
||||
$this->choice = $choice;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
50
src/Repository/CommentRepository.php
Normal file
50
src/Repository/CommentRepository.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Comment;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @method Comment|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Comment|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Comment[] findAll()
|
||||
* @method Comment[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class CommentRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Comment::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Comment[] Returns an array of Comment objects
|
||||
// */
|
||||
/*
|
||||
public function findByExampleField($value)
|
||||
{
|
||||
return $this->createQueryBuilder('c')
|
||||
->andWhere('c.exampleField = :val')
|
||||
->setParameter('val', $value)
|
||||
->orderBy('c.id', 'ASC')
|
||||
->setMaxResults(10)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
public function findOneBySomeField($value): ?Comment
|
||||
{
|
||||
return $this->createQueryBuilder('c')
|
||||
->andWhere('c.exampleField = :val')
|
||||
->setParameter('val', $value)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
*/
|
||||
}
|
Loading…
Reference in New Issue
Block a user