mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
⚡ ugly way to retrieve poll properties because of jsmserializer config not working as expected
This commit is contained in:
parent
a3cc53126f
commit
0ce0e4f427
@ -173,18 +173,36 @@ class DefaultController extends AbstractController {
|
||||
$pass = $poll->getPassword();
|
||||
$data = $request->getContent();
|
||||
$data = json_decode( $data, true );
|
||||
|
||||
$comments = [];
|
||||
$stacks = [];
|
||||
$choices = [];
|
||||
foreach ( $poll->getComments() as $c ) {
|
||||
$comments[] = $c;
|
||||
}
|
||||
foreach ( $poll->getStacksOfVotes() as $c ) {
|
||||
$stacks[] = $c;
|
||||
}
|
||||
foreach ( $poll->getChoices() as $c ) {
|
||||
$choices[] = $c;
|
||||
}
|
||||
$returnedPoll = [
|
||||
'message' => 'your poll config',
|
||||
'data' => $poll,
|
||||
'stacks_count' => count( $stacks ),
|
||||
'stacks' => $stacks,
|
||||
'choices_count' => count( $choices ),
|
||||
'choices' => $choices,
|
||||
'comments' => $comments,
|
||||
];
|
||||
/**
|
||||
* password protected content
|
||||
*/
|
||||
if ( $pass ) {
|
||||
|
||||
if ( $pass == md5( $data[ 'password_input' ] ) ) {
|
||||
return $this->json( [
|
||||
'message' => 'your poll config',
|
||||
'data' => $poll,
|
||||
'stacks' => $poll->getStacksOfVotes(),
|
||||
'comments' => $poll->getComments(),
|
||||
],
|
||||
return $this->json(
|
||||
$returnedPoll,
|
||||
200 );
|
||||
} else {
|
||||
return $this->json( [
|
||||
@ -194,12 +212,9 @@ class DefaultController extends AbstractController {
|
||||
403 );
|
||||
}
|
||||
} else {
|
||||
return $this->json( [
|
||||
'message' => 'your poll config',
|
||||
'data' => $poll,
|
||||
'stacks' => $poll->getStacksOfVotes(),
|
||||
'comments' => $poll->getComments(),
|
||||
],
|
||||
return $this->json(
|
||||
$returnedPoll
|
||||
,
|
||||
200 );
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ class Choice {
|
||||
* @ORM\Column(type="integer")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
private $id;
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
|
@ -112,25 +112,21 @@ class Poll {
|
||||
public $showResultEvenIfPasswords;
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
|
||||
* @Serializer\Type("App\Entity\Vote")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $votes;
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
|
||||
* @Serializer\Type("App\Entity\StackOfVotes")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $stacksOfVotes;
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
|
||||
* @Serializer\Type("App\Entity\Choice")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $choices;
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"})
|
||||
* @Serializer\Type("App\Entity\Comment")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $comments;
|
||||
|
Loading…
Reference in New Issue
Block a user