1
0
mirror of https://framagit.org/tykayn/date-poll-api synced 2023-08-25 08:23:11 +02:00
This commit is contained in:
Baptiste Lemoine 2019-11-12 17:26:56 +01:00
parent 216d1902cc
commit e2846a6c73
2 changed files with 225 additions and 179 deletions

View File

@ -215,6 +215,50 @@ class DefaultController extends AbstractController {
201 ); 201 );
} }
/**
* add a comment on a poll
* @Post(
* path = "poll/{id}/vote",
* name = "new_vote_stack",
* requirements = {"content"="\w+", "poll_id"="\d+"}
* )
*/
public function newVoteStackAction( Poll $poll, Request $request ) {
// if ( ! $poll ) {
// return $this->json( [ 'message' => 'poll not found' ], 404 );
// }
// $data = $request->getContent();
//
// $serializer = SerializerBuilder::create()->build();
// $comment = $serializer->deserialize( $data, 'App\Entity\Comment', 'json' );
//
// $em = $this->getDoctrine()->getRepository( Owner::class );
//
// $data = json_decode( $data, true );
//
// $foundOwner = $em->findByEmail( $data[ 'owner' ][ 'email' ] );
// // manage existing or new Owner
// if ( ! $foundOwner ) {
// $foundOwner = new Owner();
// $foundOwner->setPseudo( $data[ 'owner' ][ 'email' ] )
// ->setEmail( $data[ 'owner' ][ 'email' ] )
// ->setModifierToken( uniqid() );
// }
// $comment->setOwner( $foundOwner )
// ->setPoll( $poll );
// $foundOwner->addComment( $comment );
//
// $em = $this->getDoctrine()->getManager();
// $em->persist( $foundOwner );
// $em->persist( $comment );
// $em->flush();
return $this->json( [
'message' => 'you created a comment',
],
201 );
}
function newVoteAction( Poll $poll ) { function newVoteAction( Poll $poll ) {
return $this->json( [ return $this->json( [
'message' => 'you voted on the poll', 'message' => 'you voted on the poll',

View File

@ -161,10 +161,6 @@ class Poll {
return $this; return $this;
} }
public function getExpiracyDate(): ?DateTimeInterface {
return $this->expiracyDate;
}
public function setExpiracyDate( DateTimeInterface $expiracyDate ): self { public function setExpiracyDate( DateTimeInterface $expiracyDate ): self {
$this->expiracyDate = $expiracyDate; $this->expiracyDate = $expiracyDate;
@ -188,26 +184,6 @@ class Poll {
return $this->votes; return $this->votes;
} }
public function addVote( Vote $vote ): self {
if ( ! $this->votes->contains( $vote ) ) {
$this->votes[] = $vote;
$vote->setPoll( $this );
}
return $this;
}
public function removeVote( Vote $vote ): self {
if ( $this->votes->contains( $vote ) ) {
$this->votes->removeElement( $vote );
// set the owning side to null (unless already changed)
if ( $vote->getPoll() === $this ) {
$vote->setPoll( null );
}
}
return $this;
}
public function getAdminKey(): ?string { public function getAdminKey(): ?string {
return $this->adminKey; return $this->adminKey;
@ -309,33 +285,6 @@ class Poll {
return $this; return $this;
} }
/**
* @return Collection|Choice[]
*/
public function getChoices(): Collection {
return $this->choices;
}
public function addChoice( Choice $choice ): self {
if ( ! $this->choices->contains( $choice ) ) {
$this->choices[] = $choice;
$choice->setPoll( $this );
}
return $this;
}
public function removeChoice( Choice $choice ): self {
if ( $this->choices->contains( $choice ) ) {
$this->choices->removeElement( $choice );
// set the owning side to null (unless already changed)
if ( $choice->getPoll() === $this ) {
$choice->setPoll( null );
}
}
return $this;
}
/** /**
* @return Collection|Comment[] * @return Collection|Comment[]
@ -378,13 +327,11 @@ class Poll {
/** /**
* @return Collection|StackOfVotes[] * @return Collection|StackOfVotes[]
*/ */
public function getStackOfVotes(): Collection public function getStackOfVotes(): Collection {
{
return $this->stackOfVotes; return $this->stackOfVotes;
} }
public function addStackOfVote(StackOfVotes $stackOfVote): self public function addStackOfVote( StackOfVotes $stackOfVote ): self {
{
if ( ! $this->stackOfVotes->contains( $stackOfVote ) ) { if ( ! $this->stackOfVotes->contains( $stackOfVote ) ) {
$this->stackOfVotes[] = $stackOfVote; $this->stackOfVotes[] = $stackOfVote;
$stackOfVote->setPoll( $this ); $stackOfVote->setPoll( $this );
@ -393,8 +340,7 @@ class Poll {
return $this; return $this;
} }
public function removeStackOfVote(StackOfVotes $stackOfVote): self public function removeStackOfVote( StackOfVotes $stackOfVote ): self {
{
if ( $this->stackOfVotes->contains( $stackOfVote ) ) { if ( $this->stackOfVotes->contains( $stackOfVote ) ) {
$this->stackOfVotes->removeElement( $stackOfVote ); $this->stackOfVotes->removeElement( $stackOfVote );
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
@ -403,6 +349,62 @@ class Poll {
} }
} }
return $this;
}
public function getExpiracyDate(): ?\DateTimeInterface {
return $this->expiracyDate;
}
public function addVote( Vote $vote ): self {
if ( ! $this->votes->contains( $vote ) ) {
$this->votes[] = $vote;
$vote->setPoll( $this );
}
return $this;
}
public function removeVote( Vote $vote ): self {
if ( $this->votes->contains( $vote ) ) {
$this->votes->removeElement( $vote );
// set the owning side to null (unless already changed)
if ( $vote->getPoll() === $this ) {
$vote->setPoll( null );
}
}
return $this;
}
/**
* @return Collection|Choice[]
*/
public function getChoices(): Collection
{
return $this->choices;
}
public function addChoice(Choice $choice): self
{
if (!$this->choices->contains($choice)) {
$this->choices[] = $choice;
$choice->setPoll($this);
}
return $this;
}
public function removeChoice(Choice $choice): self
{
if ($this->choices->contains($choice)) {
$this->choices->removeElement($choice);
// set the owning side to null (unless already changed)
if ($choice->getPoll() === $this) {
$choice->setPoll(null);
}
}
return $this; return $this;
} }
} }