add list of title in api/v1/poll
This commit is contained in:
parent
b63b84d5bf
commit
45cf5887ce
@ -21,8 +21,15 @@ class PollController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
public function index(PollRepository $pollRepository): Response
|
public function index(PollRepository $pollRepository): Response
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$polls = $pollRepository->findAll();
|
||||||
|
$titles=[];
|
||||||
|
foreach ( $polls as $poll ) {
|
||||||
|
$titles[] = $poll->getTitle();
|
||||||
|
}
|
||||||
return $this->render('poll/index.html.twig', [
|
return $this->render('poll/index.html.twig', [
|
||||||
'polls' => count($pollRepository->findAll()),
|
'count' => count($polls),
|
||||||
|
'polls' => $titles,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ use App\Controller\FramadateController;
|
|||||||
use App\Entity\Choice;
|
use App\Entity\Choice;
|
||||||
use App\Entity\Owner;
|
use App\Entity\Owner;
|
||||||
use App\Entity\Poll;
|
use App\Entity\Poll;
|
||||||
|
use App\Repository\PollRepository;
|
||||||
use JMS\Serializer\Exception\RuntimeException;
|
use JMS\Serializer\Exception\RuntimeException;
|
||||||
use JMS\Serializer\SerializerBuilder;
|
use JMS\Serializer\SerializerBuilder;
|
||||||
use JMS\Serializer\SerializerInterface;
|
use JMS\Serializer\SerializerInterface;
|
||||||
@ -33,15 +34,32 @@ class PollController extends FramadateController {
|
|||||||
* name = "get_all_polls"
|
* name = "get_all_polls"
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function getAllPollsAction() {
|
public function getAllPollsAction(PollRepository $pollRepository): Response {
|
||||||
$repository = $this->getDoctrine()->getRepository( Poll::class );
|
$data = $pollRepository->findAll();
|
||||||
$data = $repository->findAll();
|
|
||||||
|
|
||||||
|
|
||||||
return $this->json( [
|
$polls = $data;
|
||||||
|
$titles=[];
|
||||||
|
|
||||||
|
$pollData = [
|
||||||
'message' => 'here are your polls',
|
'message' => 'here are your polls',
|
||||||
'poll' => count( $data ),
|
'count' => count($polls),
|
||||||
] );
|
|
||||||
|
];
|
||||||
|
|
||||||
|
$debug=1;
|
||||||
|
|
||||||
|
if($debug){
|
||||||
|
foreach ( $polls as $poll ) {
|
||||||
|
$titles[] = ['title' => $poll->getTitle(),
|
||||||
|
'slug' => $poll->getCustomUrl()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$pollData['polls'] = $titles;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->json( $pollData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +67,7 @@ class PollController extends FramadateController {
|
|||||||
* message when the poll is not found
|
* message when the poll is not found
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function notFoundPoll($id){
|
public function notFoundPoll($id): Response{
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
'message' => $id . ' : poll not found',
|
'message' => $id . ' : poll not found',
|
||||||
],
|
],
|
||||||
@ -72,7 +90,7 @@ class PollController extends FramadateController {
|
|||||||
SerializerInterface $serializer,
|
SerializerInterface $serializer,
|
||||||
$id,
|
$id,
|
||||||
Request $request
|
Request $request
|
||||||
) {
|
): Response {
|
||||||
$repository = $this->getDoctrine()->getRepository( Poll::class );
|
$repository = $this->getDoctrine()->getRepository( Poll::class );
|
||||||
$poll = $repository->findOneByCustomUrl( $id );
|
$poll = $repository->findOneByCustomUrl( $id );
|
||||||
|
|
||||||
|
1274
src/Entity/Poll.php
1274
src/Entity/Poll.php
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user