mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
add essai route
This commit is contained in:
parent
46d6d21c6b
commit
38fdbf8e85
@ -6,6 +6,7 @@ use App\Entity\Poll;
|
|||||||
use App\Form\PollType;
|
use App\Form\PollType;
|
||||||
use App\Repository\PollRepository;
|
use App\Repository\PollRepository;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
@ -14,6 +15,23 @@ use Symfony\Component\Routing\Annotation\Route;
|
|||||||
* @Route("/poll")
|
* @Route("/poll")
|
||||||
*/
|
*/
|
||||||
class PollController extends AbstractController {
|
class PollController extends AbstractController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Post(
|
||||||
|
* path = "/essai",
|
||||||
|
* name = "essai"
|
||||||
|
* )
|
||||||
|
* @param Request $request
|
||||||
|
* essai poll
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function essaiAction(Request $request)
|
||||||
|
{
|
||||||
|
$data = $request->getContent();
|
||||||
|
$data = json_decode($data, true);
|
||||||
|
return $this->json(["message"=> 'essai', 'data'=>$data], 400 );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/", name="poll_index", methods={"GET"})
|
* @Route("/", name="poll_index", methods={"GET"})
|
||||||
*/
|
*/
|
||||||
|
@ -275,24 +275,28 @@ class PollController extends EmailsController
|
|||||||
200);
|
200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Post(
|
* @Post(
|
||||||
* path = "/",
|
* path = "/",
|
||||||
* name = "new_poll",
|
* name = "new_poll"
|
||||||
* requirements = {"creator"="\w+"}
|
|
||||||
* )
|
* )
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* create a new poll
|
* create a new poll
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function newPollAction(Request $request)
|
public function newPollAction(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = $request->getContent();
|
$data = $request->getContent();
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
|
|
||||||
// search for existing custom url, which must be unique
|
// search for existing custom url, which must be unique
|
||||||
|
if(! isset($data) || !isset($data['custom_url'])){
|
||||||
|
return $this->json(["message"=> 'NOPE, pas de data ou de custom url'], 403 );
|
||||||
|
}
|
||||||
$custom_url = $data['custom_url'];
|
$custom_url = $data['custom_url'];
|
||||||
|
|
||||||
$repository = $this->getDoctrine()->getRepository(Poll::class);
|
$repository = $this->getDoctrine()->getRepository(Poll::class);
|
||||||
$poll = $repository->findOneByCustomUrl($custom_url);
|
$poll = $repository->findOneByCustomUrl($custom_url);
|
||||||
if ($poll) {
|
if ($poll) {
|
||||||
|
Loading…
Reference in New Issue
Block a user