1
0
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:
Tykayn 2022-02-10 10:23:06 +01:00 committed by tykayn
parent 46d6d21c6b
commit 38fdbf8e85
2 changed files with 25 additions and 3 deletions

View File

@ -6,6 +6,7 @@ use App\Entity\Poll;
use App\Form\PollType;
use App\Repository\PollRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -14,6 +15,23 @@ use Symfony\Component\Routing\Annotation\Route;
* @Route("/poll")
*/
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"})
*/

View File

@ -275,24 +275,28 @@ class PollController extends EmailsController
200);
}
/**
* @Post(
* path = "/",
* name = "new_poll",
* requirements = {"creator"="\w+"}
* name = "new_poll"
* )
* @param Request $request
* create a new poll
* @return JsonResponse
*/
public function newPollAction(Request $request)
public function newPollAction(Request $request): JsonResponse
{
$data = $request->getContent();
$data = json_decode($data, true);
// 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'];
$repository = $this->getDoctrine()->getRepository(Poll::class);
$poll = $repository->findOneByCustomUrl($custom_url);
if ($poll) {