mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
⚡ continue newVoteStackAction
This commit is contained in:
parent
6dd7b46e7a
commit
a0842f3b7c
@ -18,7 +18,8 @@
|
||||
"symfony/maker-bundle": "^1.14",
|
||||
"symfony/orm-pack": "^1.0",
|
||||
"symfony/validator": "4.3.*",
|
||||
"symfony/yaml": "4.3.*"
|
||||
"symfony/yaml": "4.3.*",
|
||||
"ext-json": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/doctrine-fixtures-bundle": "^3.2",
|
||||
|
@ -4,6 +4,8 @@ namespace App\Controller;
|
||||
|
||||
use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
use App\Entity\StackOfVotes;
|
||||
use App\Entity\Vote;
|
||||
use FOS\RestBundle\Controller\Annotations\Delete;
|
||||
use FOS\RestBundle\Controller\Annotations\Get;
|
||||
use FOS\RestBundle\Controller\Annotations\Post;
|
||||
@ -263,17 +265,30 @@ class DefaultController extends AbstractController {
|
||||
if ( ! $poll ) {
|
||||
return $this->json( [ 'message' => 'poll not found' ], 404 );
|
||||
}
|
||||
// $data = $request->getContent();
|
||||
$data = $request->getContent();
|
||||
$data = json_decode( $data, true );
|
||||
|
||||
$newOwner = new Owner();
|
||||
$newOwner
|
||||
->setEmail( $data[ 'email' ] )
|
||||
->setPseudo( $data[ 'pseudo' ] );
|
||||
$stack = new StackOfVotes();
|
||||
foreach ( $data[ 'votes' ] as $voteInfo ) {
|
||||
$vote = new Vote();
|
||||
$foundChoice = $poll->findChoiceById( $voteInfo[ 'choice_id' ] );
|
||||
$vote->setPoll( $poll )
|
||||
->setChoice( $foundChoice )
|
||||
->setValue( $voteInfo[ 'value' ] );
|
||||
$stack->addVote( $vote );
|
||||
}
|
||||
|
||||
// find poll from choices
|
||||
$poll->addStackOfVote( $stack );
|
||||
//
|
||||
// $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
|
||||
// manage existing or new Owner
|
||||
// if ( ! $foundOwner ) {
|
||||
// $foundOwner = new Owner();
|
||||
// $foundOwner->setPseudo( $data[ 'owner' ][ 'email' ] )
|
||||
@ -284,13 +299,14 @@ class DefaultController extends AbstractController {
|
||||
// ->setPoll( $poll );
|
||||
// $foundOwner->addComment( $comment );
|
||||
//
|
||||
// $em = $this->getDoctrine()->getManager();
|
||||
// $em->persist( $foundOwner );
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist( $stack );
|
||||
// $em->persist( $comment );
|
||||
// $em->flush();
|
||||
$em->flush();
|
||||
|
||||
return $this->json( [
|
||||
'message' => 'you created a comment',
|
||||
'message' => 'you created a comment',
|
||||
'json_you_sent' => $data,
|
||||
],
|
||||
201 );
|
||||
}
|
||||
|
@ -155,6 +155,10 @@ class Poll {
|
||||
$this->setAllowedAnswers( [ 'yes' ] );
|
||||
}
|
||||
|
||||
public function findChoiceById( $id ) {
|
||||
return new Choice(); // TODO
|
||||
}
|
||||
|
||||
public function addDaysToDate( \DateTime $date, int $days ) {
|
||||
$st = strtotime( $date->getTimestamp() . ' + ' . $days . ' days' );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user