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:
parent
c2b53a488a
commit
4de3dd7ca3
@ -1 +0,0 @@
|
|||||||
Subproject commit 47adf12bc89e48914c8b801e34b261c23b827fd2
|
|
@ -423,6 +423,7 @@ class DefaultController extends AbstractController {
|
|||||||
|
|
||||||
|
|
||||||
$emOwner = $this->getDoctrine()->getRepository( Owner::class );
|
$emOwner = $this->getDoctrine()->getRepository( Owner::class );
|
||||||
|
$emChoice = $this->getDoctrine()->getRepository( Choice::class );
|
||||||
$existingOwner = false;
|
$existingOwner = false;
|
||||||
$foundOwner = $emOwner->findOneByEmail( trim( $data[ 'email' ] ) );
|
$foundOwner = $emOwner->findOneByEmail( trim( $data[ 'email' ] ) );
|
||||||
// manage existing or new Owner
|
// manage existing or new Owner
|
||||||
@ -443,8 +444,21 @@ class DefaultController extends AbstractController {
|
|||||||
->setPseudo( $data[ 'pseudo' ] )
|
->setPseudo( $data[ 'pseudo' ] )
|
||||||
->setPoll( $poll );
|
->setPoll( $poll );
|
||||||
foreach ( $data[ 'votes' ] as $voteInfo ) {
|
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();
|
$vote = new Vote();
|
||||||
$foundChoice = $poll->findChoiceById( $voteInfo[ 'choice_id' ] );
|
$foundChoice = $emChoice->find( $voteInfo[ 'choice_id' ] );
|
||||||
if ( ! $foundChoice ) {
|
if ( ! $foundChoice ) {
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
'message' => 'choice ' . $voteInfo[ 'choice_id' ] . ' was not found',
|
'message' => 'choice ' . $voteInfo[ 'choice_id' ] . ' was not found',
|
||||||
@ -474,6 +488,7 @@ class DefaultController extends AbstractController {
|
|||||||
|
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
'message' => 'you created a vote stack' . $precision,
|
'message' => 'you created a vote stack' . $precision,
|
||||||
|
'poll' => $poll,
|
||||||
'vote_stack' => $stack->display(),
|
'vote_stack' => $stack->display(),
|
||||||
'vote_count' => count( $poll->getStacksOfVotes() ),
|
'vote_count' => count( $poll->getStacksOfVotes() ),
|
||||||
'owner_modifier_token' => $foundOwner->getModifierToken(),
|
'owner_modifier_token' => $foundOwner->getModifierToken(),
|
||||||
|
Loading…
Reference in New Issue
Block a user