1
0
mirror of https://framagit.org/tykayn/date-poll-api synced 2023-08-25 08:23:11 +02:00

handle vote stack

This commit is contained in:
Baptiste Lemoine 2020-01-23 14:47:26 +01:00
parent c2b53a488a
commit 4de3dd7ca3
2 changed files with 16 additions and 2 deletions

@ -1 +0,0 @@
Subproject commit 47adf12bc89e48914c8b801e34b261c23b827fd2

View File

@ -423,6 +423,7 @@ class DefaultController extends AbstractController {
$emOwner = $this->getDoctrine()->getRepository( Owner::class );
$emChoice = $this->getDoctrine()->getRepository( Choice::class );
$existingOwner = false;
$foundOwner = $emOwner->findOneByEmail( trim( $data[ 'email' ] ) );
// manage existing or new Owner
@ -443,8 +444,21 @@ class DefaultController extends AbstractController {
->setPseudo( $data[ 'pseudo' ] )
->setPoll( $poll );
foreach ( $data[ 'votes' ] as $voteInfo ) {
if ( ! isset( $voteInfo[ 'value' ] ) ) {
continue;
}
$allowedValuesToAnswer = [ 'yes', 'maybe', 'no' ];
if ( ! in_array( $voteInfo[ 'value' ], $allowedValuesToAnswer ) ) {
return $this->json( [
'message' => 'answer ' . $voteInfo[ 'value' ] . ' is not allowed. should be yes, maybe, or no.',
'vote_stack' => $stack,
],
404 );
}
$vote = new Vote();
$foundChoice = $poll->findChoiceById( $voteInfo[ 'choice_id' ] );
$foundChoice = $emChoice->find( $voteInfo[ 'choice_id' ] );
if ( ! $foundChoice ) {
return $this->json( [
'message' => 'choice ' . $voteInfo[ 'choice_id' ] . ' was not found',
@ -474,6 +488,7 @@ class DefaultController extends AbstractController {
return $this->json( [
'message' => 'you created a vote stack' . $precision,
'poll' => $poll,
'vote_stack' => $stack->display(),
'vote_count' => count( $poll->getStacksOfVotes() ),
'owner_modifier_token' => $foundOwner->getModifierToken(),