mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
Fix serialization with JMS Serializer for remainitn controllers anc methods.
This commit is contained in:
parent
1605754a63
commit
4bd70f0fc7
@ -11,8 +11,10 @@ use FOS\RestBundle\Controller\Annotations\Get;
|
||||
use FOS\RestBundle\Controller\Annotations\Post;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use JMS\Serializer\SerializerBuilder;
|
||||
use JMS\Serializer\SerializerInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Class DefaultController
|
||||
@ -30,13 +32,19 @@ class CommentController extends FramadateController {
|
||||
*/
|
||||
public
|
||||
function getPollCommentsAction(
|
||||
SerializerInterface $serializer,
|
||||
Poll $poll
|
||||
) {
|
||||
return $this->json( [
|
||||
$jsonResponse = $serializer->serialize([
|
||||
'message' => 'here are your comments of the poll',
|
||||
'data' => $poll->getComments(),
|
||||
],
|
||||
200 );
|
||||
'data' => $poll->getComments()], 'json');
|
||||
|
||||
$response = new Response($jsonResponse);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
$response->setStatusCode(200);
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,6 +50,7 @@ class PollController extends FramadateController {
|
||||
* @param SerializerInterface $serializer
|
||||
* @param Poll $poll
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function getPollConfig(
|
||||
@ -102,8 +103,7 @@ class PollController extends FramadateController {
|
||||
* requirements = {"content"="\w+", "poll_id"="\d+"}
|
||||
* )
|
||||
*/
|
||||
public
|
||||
function updatePollConfig(
|
||||
public function updatePollConfig(
|
||||
Poll $poll,
|
||||
string $token,
|
||||
Request $request
|
||||
@ -211,7 +211,7 @@ class PollController extends FramadateController {
|
||||
// different hours spans
|
||||
$choices = $data[ 'dateList' ];
|
||||
} else {
|
||||
|
||||
//TODO (Sébastien) I assume this shouldn't be empty ?
|
||||
// all days have the same hour spans
|
||||
}
|
||||
|
||||
@ -350,46 +350,46 @@ class PollController extends FramadateController {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Admin poll config
|
||||
* @Get(
|
||||
* path = "/admin/{token}",
|
||||
* name = "get_admin_config",
|
||||
* )
|
||||
* @param SerializerInterface $serializer
|
||||
* @param $token
|
||||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function getAdministrationConfig( $token ) {
|
||||
public function getAdministrationConfig(SerializerInterface $serializer, $token ) {
|
||||
$emPoll = $this->getDoctrine()->getRepository( Poll::class );
|
||||
$pollFound = $emPoll->findOneByAdminKey( $token );
|
||||
|
||||
if ( $pollFound ) {
|
||||
|
||||
$poll = $pollFound;
|
||||
$comments = [];
|
||||
$stacks = [];
|
||||
$choices = [];
|
||||
foreach ( $poll->getComments() as $c ) {
|
||||
$comments[] = $c->display();
|
||||
}
|
||||
foreach ( $poll->getStacksOfVotes() as $c ) {
|
||||
$stacks[] = $c->display();
|
||||
}
|
||||
foreach ( $poll->getChoices() as $c ) {
|
||||
$choices[] = $c->display();
|
||||
}
|
||||
$comments = $poll->getComments();
|
||||
$stacks = $poll->getStacksOfVotes();
|
||||
|
||||
$returnedPoll = [
|
||||
'message' => 'your poll config',
|
||||
'poll' => $poll,
|
||||
'stacks_count' => count( $poll->getStacksOfVotes() ),
|
||||
'stacks_count' => count( $stacks ),
|
||||
'stacks' => $stacks,
|
||||
'choices_count' => $poll->computeAnswers(),
|
||||
'choices' => $choices,
|
||||
'choices' => $poll->getChoices(),
|
||||
'comments' => $comments,
|
||||
'comments_count' => count( $comments ),
|
||||
'token' => $token,
|
||||
];
|
||||
|
||||
return $this->json( $returnedPoll,
|
||||
200 );
|
||||
$jsonResponse = $serializer->serialize($returnedPoll, 'json');
|
||||
|
||||
$response = new Response($jsonResponse);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
$response->setStatusCode(200);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $this->json( [
|
||||
|
@ -11,8 +11,10 @@ use FOS\RestBundle\Controller\Annotations\Delete;
|
||||
use FOS\RestBundle\Controller\Annotations\Patch;
|
||||
use FOS\RestBundle\Controller\Annotations\Post;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use JMS\Serializer\SerializerInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Class DefaultController
|
||||
@ -28,9 +30,14 @@ class VoteController extends FramadateController {
|
||||
* name = "new_vote_stack",
|
||||
* requirements = {"content"="\w+", "poll_id"="\d+"}
|
||||
* )
|
||||
* @param SerializerInterface $serializer
|
||||
* @param Poll $poll
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public
|
||||
function newVoteStackAction(
|
||||
public function newVoteStackAction(
|
||||
SerializerInterface $serializer,
|
||||
Poll $poll,
|
||||
Request $request
|
||||
) {
|
||||
@ -106,40 +113,35 @@ class VoteController extends FramadateController {
|
||||
if ( $existingOwner ) {
|
||||
$precision = ' from an existing owner : ' . $foundOwner->getEmail();
|
||||
}
|
||||
$comments = [];
|
||||
$stacks = [];
|
||||
$choices = [];
|
||||
foreach ( $poll->getComments() as $c ) {
|
||||
$comments[] = $c->display();
|
||||
}
|
||||
foreach ( $poll->getStacksOfVotes() as $c ) {
|
||||
$stacks[] = $c->display();
|
||||
}
|
||||
foreach ( $poll->getChoices() as $c ) {
|
||||
$choices[] = $c->display();
|
||||
}
|
||||
|
||||
$stacks = $poll->getStacksOfVotes();
|
||||
|
||||
if($poll->getMailOnVote()){
|
||||
$this->sendVoteNotificationAction($stack->getOwner(), $stack);
|
||||
}
|
||||
|
||||
|
||||
return $this->json( [
|
||||
$returnedVoteStack = [
|
||||
'message' => 'you created a vote stack' . $precision,
|
||||
'poll' => $poll,
|
||||
'vote_stack' => $stack->display(),
|
||||
'vote_stack' => $stack,
|
||||
'stacks' => $stacks,
|
||||
'comments' => $comments,
|
||||
'choices' => $choices,
|
||||
'comments' => $poll->getComments(),
|
||||
'choices' => $poll->getChoices(),
|
||||
'choices_count' => $poll->computeAnswers(),
|
||||
'vote_count' => count( $poll->getStacksOfVotes() ),
|
||||
'vote_count' => count( $stacks ),
|
||||
'owner' => $stack->getOwner(),
|
||||
'owner_modifier_token' => $stack->getOwner()->getModifierToken(),
|
||||
'admin_key' => $poll->getAdminKey(),
|
||||
'json_you_sent' => $data,
|
||||
],
|
||||
201 );
|
||||
];
|
||||
|
||||
$jsonResponse = $serializer->serialize($returnedVoteStack, 'json');
|
||||
|
||||
$response = new Response($jsonResponse);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
$response->setStatusCode(200);
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,9 +151,16 @@ class VoteController extends FramadateController {
|
||||
* name = "update_vote_stack",
|
||||
* requirements = { "id"="\d+"}
|
||||
* )
|
||||
* @param SerializerInterface $serializer
|
||||
* @param StackOfVotes $id
|
||||
* @param $modifierToken
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public
|
||||
function updateVoteStackAction(
|
||||
SerializerInterface $serializer,
|
||||
StackOfVotes $id,
|
||||
$modifierToken,
|
||||
Request $request
|
||||
@ -173,12 +182,18 @@ class VoteController extends FramadateController {
|
||||
// update answers
|
||||
// save evrything
|
||||
|
||||
return $this->json( [
|
||||
|
||||
$jsonResponse = $serializer->serialize([
|
||||
'message' => 'ok',
|
||||
'modifier_token' => $voteStack->getOwner()->getModifierToken(),
|
||||
'vote_stack' => $voteStack->display(),
|
||||
],
|
||||
200 );
|
||||
'vote_stack' => $voteStack,
|
||||
], 'json');
|
||||
|
||||
$response = new Response($jsonResponse);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
$response->setStatusCode(200);
|
||||
|
||||
return $response;
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user