mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
Revert "add graphql bundle"
rearrange controllers for api and no api
This reverts commit 8fbd5462
This commit is contained in:
parent
21c594a2fd
commit
aab2d74b19
@ -11,7 +11,7 @@ use FOS\RestBundle\Controller\Annotations\Route;
|
||||
* @package App\Controller
|
||||
* @Route("/admin",name="admin_homepage")
|
||||
*/
|
||||
class AdminController extends FramadateController {
|
||||
class AdminController extends EmailsController {
|
||||
/**
|
||||
* @Get(path ="/",
|
||||
* name = "_get_default")
|
||||
|
@ -17,7 +17,7 @@ use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
* @package App\Controller
|
||||
* @Route("/",name="home_")
|
||||
*/
|
||||
class DefaultController extends FramadateController {
|
||||
class DefaultController extends EmailsController {
|
||||
|
||||
/**
|
||||
* @Get(path ="/",
|
||||
@ -27,7 +27,7 @@ class DefaultController extends FramadateController {
|
||||
|
||||
$polls = $this->getDoctrine()->getRepository( Poll::class )->findAll();
|
||||
|
||||
return $this->render( 'pages/home.html.twig',[ ]);
|
||||
return $this->render( 'pages/home.html.twig', [] );
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,10 +11,10 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
/**
|
||||
* sending emails controller
|
||||
*
|
||||
* Class FramadateController
|
||||
* Class EmailsController
|
||||
* @package App\Controller
|
||||
*/
|
||||
class FramadateController extends AbstractController {
|
||||
class EmailsController extends AbstractController {
|
||||
|
||||
private $mail_service;
|
||||
|
||||
@ -86,7 +86,7 @@ class FramadateController extends AbstractController {
|
||||
|
||||
$config = [
|
||||
'owner' => $owner,
|
||||
'title' => 'Framadate | Mes sondages',
|
||||
'title' => $this->getParameter( 'WEBSITE_NAME' ) . ' | Mes sondages',
|
||||
'email_template' => 'emails/owner-list.html.twig',
|
||||
];
|
||||
$this->sendMailWithVars( $config );
|
@ -21,7 +21,7 @@ use App\Entity\Poll;
|
||||
* @package App\Controller
|
||||
* @Route("/migration-from-v1",name="admin_homepage")
|
||||
*/
|
||||
class MigrationController extends FramadateController {
|
||||
class MigrationController extends EmailsController {
|
||||
/**
|
||||
* @Get(path ="/{unique_key}",
|
||||
* name = "_migrate_from_v1")
|
||||
|
@ -14,7 +14,7 @@ use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
* @package App\Controller
|
||||
* @Route("/user",name="user_homepage")
|
||||
*/
|
||||
class OwnerController extends FramadateController {
|
||||
class OwnerController extends EmailsController {
|
||||
/**
|
||||
* @Get(path ="/",
|
||||
* name = "get_default")
|
||||
|
@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
namespace App\Controller\api;
|
||||
|
||||
use App\Controller\EmailsController;
|
||||
use App\Entity\Comment;
|
||||
use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
@ -21,7 +22,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
* @package App\Controller
|
||||
* @Route("/api/v1",name="api_")
|
||||
*/
|
||||
class CommentController extends FramadateController {
|
||||
class CommentController extends EmailsController {
|
||||
|
||||
/**
|
||||
* @Get(
|
||||
@ -32,18 +33,18 @@ class CommentController extends FramadateController {
|
||||
*/
|
||||
public
|
||||
function getPollCommentsAction(
|
||||
SerializerInterface $serializer,
|
||||
Poll $poll
|
||||
SerializerInterface $serializer,
|
||||
Poll $poll
|
||||
) {
|
||||
$jsonResponse = $serializer->serialize([
|
||||
'message' => 'here are your comments of the poll',
|
||||
'data' => $poll->getComments()], 'json');
|
||||
$jsonResponse = $serializer->serialize([
|
||||
'message' => 'here are your comments of the poll',
|
||||
'data' => $poll->getComments()], 'json');
|
||||
|
||||
$response = new Response($jsonResponse);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
$response->setStatusCode(200);
|
||||
$response = new Response($jsonResponse);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
$response->setStatusCode(200);
|
||||
|
||||
return $response;
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
@ -80,8 +81,8 @@ class CommentController extends FramadateController {
|
||||
if ( ! $foundOwner ) {
|
||||
$foundOwner = new Owner();
|
||||
$foundOwner->setPseudo( $data[ 'email' ] )
|
||||
->setEmail( $data[ 'email' ] )
|
||||
->setModifierToken( uniqid( '', true ) );
|
||||
->setEmail( $data[ 'email' ] )
|
||||
->setModifierToken( uniqid( '', true ) );
|
||||
}
|
||||
// anti flood
|
||||
$seconds_limit_lastpost = 5;
|
||||
@ -117,8 +118,8 @@ class CommentController extends FramadateController {
|
||||
}
|
||||
}
|
||||
$comment->setOwner( $foundOwner )
|
||||
->setCreatedAt( new DateTime() )
|
||||
->setPoll( $poll );
|
||||
->setCreatedAt( new DateTime() )
|
||||
->setPoll( $poll );
|
||||
$foundOwner->addComment( $comment );
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Controller\api;
|
||||
|
||||
use App\Controller\FramadateController;
|
||||
use App\Controller\EmailsController;
|
||||
use App\Entity\Choice;
|
||||
use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
@ -27,15 +27,15 @@ use FOS\RestBundle\Controller\Annotations\Route;
|
||||
* @package App\Controller
|
||||
* @Route("/api/v1/poll",name="api_")
|
||||
*/
|
||||
class PollController extends FramadateController {
|
||||
class PollController extends EmailsController {
|
||||
/**
|
||||
* @Get(
|
||||
* path = "/",
|
||||
* name = "get_all_polls"
|
||||
* )
|
||||
*/
|
||||
public function getAllPollsAction(PollRepository $pollRepository): Response {
|
||||
$data = $pollRepository->findAll();
|
||||
public function getAllPollsAction( PollRepository $pollRepository ): Response {
|
||||
$data = $pollRepository->findAll();
|
||||
|
||||
|
||||
$polls = $data;
|
||||
@ -76,9 +76,9 @@ class PollController extends FramadateController {
|
||||
/**
|
||||
* get a poll config by its custom URL, we do not want polls to be reachable by their numeric id
|
||||
* @Get(
|
||||
* path = "/{id}",
|
||||
* path = "/{customUrl}",
|
||||
* name = "get_poll",
|
||||
* requirements = {"id"="\w+"}
|
||||
* requirements = {"customUrl"="\w+"}
|
||||
* )
|
||||
*
|
||||
* @param SerializerInterface $serializer
|
||||
@ -88,14 +88,14 @@ class PollController extends FramadateController {
|
||||
*/
|
||||
public function getPollConfig(
|
||||
SerializerInterface $serializer,
|
||||
$id,
|
||||
$customUrl,
|
||||
Request $request
|
||||
): Response {
|
||||
$repository = $this->getDoctrine()->getRepository( Poll::class );
|
||||
$poll = $repository->findOneByCustomUrl( $id );
|
||||
$poll = $repository->findOneByCustomUrl( $customUrl );
|
||||
|
||||
if ( ! $poll ) {
|
||||
return $this->notFoundPoll($id);
|
||||
return $this->notFoundPoll( $customUrl );
|
||||
}
|
||||
|
||||
$comments = $poll->getComments();
|
||||
@ -134,9 +134,9 @@ class PollController extends FramadateController {
|
||||
/**
|
||||
* get a poll config by its custom URL, we do not want polls to be reachable by their numeric id
|
||||
* @Get(
|
||||
* path = "/{id}/pass/{md5}",
|
||||
* path = "/{customUrl}/pass/{md5}",
|
||||
* name = "get_protected_poll",
|
||||
* requirements = {"id"="\w+"}
|
||||
* requirements = {"customUrl"="\w+"}
|
||||
* )
|
||||
*
|
||||
* @param SerializerInterface $serializer
|
||||
@ -180,7 +180,7 @@ class PollController extends FramadateController {
|
||||
|
||||
/**
|
||||
* @Put(
|
||||
* path = "/{id}/{token}",
|
||||
* path = "/{customUrl}/{token}",
|
||||
* name = "update_poll",
|
||||
* requirements = {"content"="\w+", "poll_id"="\d+"}
|
||||
* )
|
||||
@ -363,7 +363,7 @@ class PollController extends FramadateController {
|
||||
|
||||
/**
|
||||
* @Delete(
|
||||
* path = "/{id}",
|
||||
* path = "/{customUrl}",
|
||||
* name = "poll_delete",
|
||||
* requirements = {"accessToken"="\w+", "poll_id"="\d+"}
|
||||
* )
|
||||
@ -397,13 +397,13 @@ class PollController extends FramadateController {
|
||||
/**
|
||||
* Checks if a slug is already taken by a poll
|
||||
* @Get(
|
||||
* path = "/slug/{slug}",
|
||||
* path = "/slug/{customUrl}",
|
||||
* name = "check_slug_is_unique",
|
||||
* )
|
||||
*/
|
||||
public function checkSlugIsUniqueAction( string $slug ) {
|
||||
public function checkSlugIsUniqueAction( string $customUrl ) {
|
||||
$emPoll = $this->getDoctrine()->getRepository( Poll::class );
|
||||
$found = $emPoll->findOneByCustomUrl( $slug );
|
||||
$found = $emPoll->findOneByCustomUrl( $customUrl );
|
||||
$elaborated_message_version = false;
|
||||
|
||||
if ( $found ) {
|
||||
@ -416,7 +416,7 @@ class PollController extends FramadateController {
|
||||
return $this->json( [
|
||||
'message' => ' NO, this slug is already taken on this Framadate instance ',
|
||||
'data' => [
|
||||
'slug' => $slug,
|
||||
'slug' => $customUrl,
|
||||
],
|
||||
],
|
||||
204 );
|
||||
@ -429,7 +429,7 @@ class PollController extends FramadateController {
|
||||
return $this->json( [
|
||||
'message' => ' yes this slug is available on this Framadate instance ',
|
||||
'data' => [
|
||||
'slug' => $slug,
|
||||
'slug' => $customUrl,
|
||||
],
|
||||
],
|
||||
404 );
|
||||
|
@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
namespace App\Controller\api;
|
||||
|
||||
use App\Controller\EmailsController;
|
||||
use App\Entity\Choice;
|
||||
use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
@ -21,25 +22,25 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
* @package App\Controller
|
||||
* @Route("/api/v1",name="api_")
|
||||
*/
|
||||
class VoteController extends FramadateController {
|
||||
class VoteController extends EmailsController {
|
||||
|
||||
/**
|
||||
* add a vote stack on a poll
|
||||
* @Post(
|
||||
* path = "/poll/{id}/answer",
|
||||
* name = "new_vote_stack",
|
||||
* requirements = {"content"="\w+", "poll_id"="\d+"}
|
||||
* )
|
||||
* @param SerializerInterface $serializer
|
||||
* @param Poll $poll
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
/**
|
||||
* add a vote stack on a poll
|
||||
* @Post(
|
||||
* path = "/poll/{id}/answer",
|
||||
* name = "new_vote_stack",
|
||||
* requirements = {"content"="\w+", "poll_id"="\d+"}
|
||||
* )
|
||||
* @param SerializerInterface $serializer
|
||||
* @param Poll $poll
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function newVoteStackAction(
|
||||
SerializerInterface $serializer,
|
||||
Poll $poll,
|
||||
Request $request
|
||||
SerializerInterface $serializer,
|
||||
Poll $poll,
|
||||
Request $request
|
||||
) {
|
||||
if ( ! $poll ) {
|
||||
return $this->json( [ 'message' => 'poll not found' ], 404 );
|
||||
@ -95,8 +96,8 @@ class VoteController extends FramadateController {
|
||||
404 );
|
||||
}
|
||||
$vote->setPoll( $poll )
|
||||
->setChoice( $foundChoice )
|
||||
->setValue( $voteInfo[ 'value' ] );
|
||||
->setChoice( $foundChoice )
|
||||
->setValue( $voteInfo[ 'value' ] );
|
||||
$vote->setPoll( $poll );
|
||||
$stack->addVote( $vote );
|
||||
$poll->addVote( $vote );
|
||||
@ -113,7 +114,7 @@ class VoteController extends FramadateController {
|
||||
if ( $existingOwner ) {
|
||||
$precision = ' from an existing owner : ' . $foundOwner->getEmail();
|
||||
}
|
||||
$stacks = $poll->getStacksOfVotes();
|
||||
$stacks = $poll->getStacksOfVotes();
|
||||
|
||||
if($poll->getMailOnVote()){
|
||||
$this->sendVoteNotificationAction($stack->getOwner(), $stack);
|
||||
@ -121,36 +122,36 @@ class VoteController extends FramadateController {
|
||||
|
||||
$returnedVoteStack = $stack;
|
||||
|
||||
$jsonResponse = $serializer->serialize($returnedVoteStack, 'json');
|
||||
$jsonResponse = $serializer->serialize($returnedVoteStack, 'json');
|
||||
|
||||
$response = new Response($jsonResponse);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
$response->setStatusCode(200);
|
||||
$response = new Response($jsonResponse);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
$response->setStatusCode(200);
|
||||
|
||||
return $response;
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* update vote stack
|
||||
* @Patch(
|
||||
* path = "/vote-stack/{id}/token/{modifierToken}",
|
||||
* name = "update_vote_stack",
|
||||
* requirements = { "id"="\d+"}
|
||||
* )
|
||||
* @param SerializerInterface $serializer
|
||||
* @param StackOfVotes $id
|
||||
* @param $modifierToken
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
/**
|
||||
* update vote stack
|
||||
* @Patch(
|
||||
* path = "/vote-stack/{id}/token/{modifierToken}",
|
||||
* name = "update_vote_stack",
|
||||
* requirements = { "id"="\d+"}
|
||||
* )
|
||||
* @param SerializerInterface $serializer
|
||||
* @param StackOfVotes $id
|
||||
* @param $modifierToken
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public
|
||||
function updateVoteStackAction(
|
||||
SerializerInterface $serializer,
|
||||
StackOfVotes $id,
|
||||
$modifierToken,
|
||||
Request $request
|
||||
SerializerInterface $serializer,
|
||||
StackOfVotes $id,
|
||||
$modifierToken,
|
||||
Request $request
|
||||
) {
|
||||
$voteStack = $id;
|
||||
if ( ! $voteStack ) {
|
||||
@ -170,17 +171,17 @@ class VoteController extends FramadateController {
|
||||
// save evrything
|
||||
|
||||
|
||||
$jsonResponse = $serializer->serialize([
|
||||
'message' => 'ok',
|
||||
'modifier_token' => $voteStack->getOwner()->getModifierToken(),
|
||||
'vote_stack' => $voteStack,
|
||||
], 'json');
|
||||
$jsonResponse = $serializer->serialize([
|
||||
'message' => 'ok',
|
||||
'modifier_token' => $voteStack->getOwner()->getModifierToken(),
|
||||
'vote_stack' => $voteStack,
|
||||
], 'json');
|
||||
|
||||
$response = new Response($jsonResponse);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
$response->setStatusCode(200);
|
||||
$response = new Response($jsonResponse);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
$response->setStatusCode(200);
|
||||
|
||||
return $response;
|
||||
return $response;
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user