Browse Source

add list of title in api/v1/poll

master
Tykayn 1 year ago committed by tykayn
parent
commit
45cf5887ce
  1. 9
      src/Controller/PollController.php
  2. 34
      src/Controller/api/PollController.php
  3. 1274
      src/Entity/Poll.php

9
src/Controller/PollController.php

@ -21,8 +21,15 @@ class PollController extends AbstractController
*/
public function index(PollRepository $pollRepository): Response
{
$polls = $pollRepository->findAll();
$titles=[];
foreach ( $polls as $poll ) {
$titles[] = $poll->getTitle();
}
return $this->render('poll/index.html.twig', [
'polls' => count($pollRepository->findAll()),
'count' => count($polls),
'polls' => $titles,
]);
}

34
src/Controller/api/PollController.php

@ -6,6 +6,7 @@ use App\Controller\FramadateController;
use App\Entity\Choice;
use App\Entity\Owner;
use App\Entity\Poll;
use App\Repository\PollRepository;
use JMS\Serializer\Exception\RuntimeException;
use JMS\Serializer\SerializerBuilder;
use JMS\Serializer\SerializerInterface;
@ -33,15 +34,32 @@ class PollController extends FramadateController {
* name = "get_all_polls"
* )
*/
public function getAllPollsAction() {
$repository = $this->getDoctrine()->getRepository( Poll::class );
$data = $repository->findAll();
public function getAllPollsAction(PollRepository $pollRepository): Response {
$data = $pollRepository->findAll();
return $this->json( [
$polls = $data;
$titles=[];
$pollData = [
'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
* @return JsonResponse
*/
public function notFoundPoll($id){
public function notFoundPoll($id): Response{
return $this->json( [
'message' => $id . ' : poll not found',
],
@ -72,7 +90,7 @@ class PollController extends FramadateController {
SerializerInterface $serializer,
$id,
Request $request
) {
): Response {
$repository = $this->getDoctrine()->getRepository( Poll::class );
$poll = $repository->findOneByCustomUrl( $id );

1274
src/Entity/Poll.php

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save