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

View File

@ -1,18 +1,16 @@
<?php
namespace App\Entity;
namespace App\Entity;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
/**
/**
* @ORM\Entity(repositoryClass="App\Repository\PollRepository")
* @Serializer\ExclusionPolicy("all")
*/
class Poll {
class Poll {
/**
* @ORM\Id()
* @ORM\GeneratedValue()
@ -570,7 +568,7 @@
return $this->choices;
}
public function addTextChoiceArray( Array $choiceTextArray ): self {
public function addTextChoiceArray( array $choiceTextArray ): self {
foreach ( $choiceTextArray as $text ) {
$newChoice = new Choice();
$newChoice->setName( $text );
@ -639,51 +637,43 @@
return $this;
}
public function getVotesAllowed(): ?bool
{
public function getVotesAllowed(): ?bool {
return $this->votesAllowed;
}
public function setVotesAllowed(?bool $votesAllowed): self
{
public function setVotesAllowed( ?bool $votesAllowed ): self {
$this->votesAllowed = $votesAllowed;
return $this;
}
public function getVotesMax()
{
public function getVotesMax() {
return $this->votesMax;
}
public function setVotesMax($votesMax): self
{
public function setVotesMax( $votesMax ): self {
$this->votesMax = $votesMax;
return $this;
}
public function getChoicesMax()
{
public function getChoicesMax() {
return $this->choicesMax;
}
public function setChoicesMax($choicesMax): self
{
public function setChoicesMax( $choicesMax ): self {
$this->choicesMax = $choicesMax;
return $this;
}
public function getCommentsAllowed(): ?bool
{
public function getCommentsAllowed(): ?bool {
return $this->commentsAllowed;
}
public function setCommentsAllowed(?bool $commentsAllowed): self
{
public function setCommentsAllowed( ?bool $commentsAllowed ): self {
$this->commentsAllowed = $commentsAllowed;
return $this;
}
}
}