add list of title in api/v1/poll

This commit is contained in:
Tykayn 2021-04-20 00:41:19 +02:00 committed by tykayn
parent b63b84d5bf
commit 45cf5887ce
3 changed files with 666 additions and 651 deletions

View File

@ -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,
]);
}

View File

@ -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 );

File diff suppressed because it is too large Load Diff