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

View File

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

View File

@ -5,8 +5,6 @@
use DateTimeInterface; use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/** /**
* @ORM\Entity(repositoryClass="App\Repository\PollRepository") * @ORM\Entity(repositoryClass="App\Repository\PollRepository")
@ -570,7 +568,7 @@
return $this->choices; return $this->choices;
} }
public function addTextChoiceArray( Array $choiceTextArray ): self { public function addTextChoiceArray( array $choiceTextArray ): self {
foreach ( $choiceTextArray as $text ) { foreach ( $choiceTextArray as $text ) {
$newChoice = new Choice(); $newChoice = new Choice();
$newChoice->setName( $text ); $newChoice->setName( $text );
@ -639,49 +637,41 @@
return $this; return $this;
} }
public function getVotesAllowed(): ?bool public function getVotesAllowed(): ?bool {
{
return $this->votesAllowed; return $this->votesAllowed;
} }
public function setVotesAllowed(?bool $votesAllowed): self public function setVotesAllowed( ?bool $votesAllowed ): self {
{
$this->votesAllowed = $votesAllowed; $this->votesAllowed = $votesAllowed;
return $this; return $this;
} }
public function getVotesMax() public function getVotesMax() {
{
return $this->votesMax; return $this->votesMax;
} }
public function setVotesMax($votesMax): self public function setVotesMax( $votesMax ): self {
{
$this->votesMax = $votesMax; $this->votesMax = $votesMax;
return $this; return $this;
} }
public function getChoicesMax() public function getChoicesMax() {
{
return $this->choicesMax; return $this->choicesMax;
} }
public function setChoicesMax($choicesMax): self public function setChoicesMax( $choicesMax ): self {
{
$this->choicesMax = $choicesMax; $this->choicesMax = $choicesMax;
return $this; return $this;
} }
public function getCommentsAllowed(): ?bool public function getCommentsAllowed(): ?bool {
{
return $this->commentsAllowed; return $this->commentsAllowed;
} }
public function setCommentsAllowed(?bool $commentsAllowed): self public function setCommentsAllowed( ?bool $commentsAllowed ): self {
{
$this->commentsAllowed = $commentsAllowed; $this->commentsAllowed = $commentsAllowed;
return $this; return $this;