mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
handle creation of mixed subset of datechoice
This commit is contained in:
parent
e488b76a2d
commit
9cfb974c27
@ -28,20 +28,22 @@ https://framagit.org/framasoft/framadate/funky-framadate-front
|
|||||||
user_homepageget_default GET ANY ANY /user/
|
user_homepageget_default GET ANY ANY /user/
|
||||||
user_homepage_polls_send_by_email GET ANY ANY /user/{email}/polls/send-by-email
|
user_homepage_polls_send_by_email GET ANY ANY /user/{email}/polls/send-by-email
|
||||||
poll_index GET ANY ANY /poll/
|
poll_index GET ANY ANY /poll/
|
||||||
poll_new GET|POST ANY ANY /poll/new
|
poll_new POST ANY ANY /poll/new
|
||||||
poll_show GET ANY ANY /poll/{id}
|
poll_show GET ANY ANY /poll/id/{id}
|
||||||
poll_edit GET|POST ANY ANY /poll/{id}/edit
|
poll_edit GET|POST ANY ANY /poll/{id}/edit
|
||||||
poll_delete DELETE ANY ANY /poll/{id}
|
poll_delete DELETE ANY ANY /poll/{id}
|
||||||
api_get_poll_comment GET ANY ANY /api/v1/comment/poll/{id}/comments
|
api_get_poll_comment GET ANY ANY /api/v1/comment/poll/{id}/comments
|
||||||
api_new_comment POST ANY ANY /api/v1/comment/poll/{id}/comment
|
api_new_comment POST ANY ANY /api/v1/comment/poll/{id}/comment
|
||||||
api_poll_comments_delete DELETE ANY ANY /api/v1/comment/poll/{id}/comments
|
api_poll_comments_delete DELETE ANY ANY /api/v1/comment/poll/{id}/comments
|
||||||
|
api_essai GET ANY ANY /api/v1/poll/essai
|
||||||
api_get_all_polls GET ANY ANY /api/v1/poll/
|
api_get_all_polls GET ANY ANY /api/v1/poll/
|
||||||
api_get_poll GET ANY ANY /api/v1/poll/{customUrl}
|
api_get_poll GET ANY ANY /api/v1/poll/{customUrl}
|
||||||
api_get_owner_poll GET ANY ANY /api/v1/poll/owner/{owner_email}/
|
api_get_owner_poll GET ANY ANY /api/v1/poll/owner/{owner_email}/
|
||||||
api_get_protected_poll GET ANY ANY /api/v1/poll/{customUrl}/pass/{md5}
|
api_get_protected_poll GET ANY ANY /api/v1/poll/{customUrl}/pass/{md5}
|
||||||
api_get_admin_poll GET ANY ANY /api/v1/polladmin/{admin_key}
|
api_get_admin_poll GET ANY ANY /api/v1/polladmin/{admin_key}
|
||||||
api_update_poll PUT ANY ANY /api/v1/poll/{customUrl}/update/{token}
|
api_update_poll PUT ANY ANY /api/v1/poll/{customUrl}/update/{token}
|
||||||
api_new_poll POST ANY ANY /api/v1/poll/
|
api_app_api_v1_poll_newpoll POST ANY ANY /api/v1/poll/
|
||||||
|
api_app_api_v1_poll_newpoll.1 POST ANY ANY /api/v1/poll_new_poll
|
||||||
api_test-mail-poll GET ANY ANY /api/v1/poll/mail/test-mail-poll/{emailChoice}
|
api_test-mail-poll GET ANY ANY /api/v1/poll/mail/test-mail-poll/{emailChoice}
|
||||||
api_poll_delete DELETE ANY ANY /api/v1/poll/{admin_key}
|
api_poll_delete DELETE ANY ANY /api/v1/poll/{admin_key}
|
||||||
api_check_slug_is_unique GET ANY ANY /api/v1/poll/slug/{customUrl}
|
api_check_slug_is_unique GET ANY ANY /api/v1/poll/slug/{customUrl}
|
||||||
|
@ -15,24 +15,6 @@ use Symfony\Component\Routing\Annotation\Route;
|
|||||||
* @Route("/poll")
|
* @Route("/poll")
|
||||||
*/
|
*/
|
||||||
class PollController extends AbstractController {
|
class PollController extends AbstractController {
|
||||||
|
|
||||||
/**
|
|
||||||
* @Route(
|
|
||||||
* "/essai",
|
|
||||||
* name = "essai",
|
|
||||||
* methods={"GET"}
|
|
||||||
* )
|
|
||||||
* @param Request $request
|
|
||||||
* essai poll
|
|
||||||
* @return JsonResponse
|
|
||||||
*/
|
|
||||||
public function essai(Request $request): JsonResponse
|
|
||||||
{
|
|
||||||
$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"})
|
||||||
*/
|
*/
|
||||||
@ -53,7 +35,7 @@ class PollController extends AbstractController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/new", name="poll_new", methods={"GET","POST"})
|
* @Route("/new", name="poll_new", methods={"POST"})
|
||||||
*/
|
*/
|
||||||
public function new( Request $request ): Response {
|
public function new( Request $request ): Response {
|
||||||
$poll = new Poll();
|
$poll = new Poll();
|
||||||
|
@ -10,7 +10,6 @@ use App\Repository\PollRepository;
|
|||||||
use DateTime;
|
use DateTime;
|
||||||
use FOS\RestBundle\Controller\Annotations\Delete;
|
use FOS\RestBundle\Controller\Annotations\Delete;
|
||||||
use FOS\RestBundle\Controller\Annotations\Get;
|
use FOS\RestBundle\Controller\Annotations\Get;
|
||||||
use FOS\RestBundle\Controller\Annotations\Post;
|
|
||||||
use FOS\RestBundle\Controller\Annotations\Put;
|
use FOS\RestBundle\Controller\Annotations\Put;
|
||||||
use FOS\RestBundle\Controller\Annotations\Route;
|
use FOS\RestBundle\Controller\Annotations\Route;
|
||||||
use JMS\Serializer\SerializerInterface;
|
use JMS\Serializer\SerializerInterface;
|
||||||
@ -27,6 +26,23 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
*/
|
*/
|
||||||
class PollController extends EmailsController
|
class PollController extends EmailsController
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @Route(
|
||||||
|
* "/essai",
|
||||||
|
* name = "essai",
|
||||||
|
* methods={"GET"}
|
||||||
|
* )
|
||||||
|
* @param Request $request
|
||||||
|
* essai poll
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function essai(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$data = $request->getContent();
|
||||||
|
$data = json_decode($data, true);
|
||||||
|
return $this->json(["message" => 'essai', 'data' => $data], 400);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Get(
|
* @Get(
|
||||||
* path = "/",
|
* path = "/",
|
||||||
@ -277,15 +293,16 @@ class PollController extends EmailsController
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Post(
|
* @Route(
|
||||||
* path = "/",
|
* "/",
|
||||||
* name = "new_poll"
|
* "_new_poll",
|
||||||
|
* methods={"POST"}
|
||||||
* )
|
* )
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* create a new poll
|
* create a new poll
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function newPollAction(Request $request): JsonResponse
|
public function newPoll(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = $request->getContent();
|
$data = $request->getContent();
|
||||||
@ -379,21 +396,33 @@ class PollController extends EmailsController
|
|||||||
elseif ($data['kind'] == 'date') {
|
elseif ($data['kind'] == 'date') {
|
||||||
|
|
||||||
$choices = $data['dateChoices'];
|
$choices = $data['dateChoices'];
|
||||||
$choices_debug .= 'debug count recieved' . count($choices);
|
$choices_debug .= '\n debug count recieved' . count($choices);
|
||||||
if (isset($data['hasSeveralHours']) && $data['hasSeveralHours'] == true) {
|
if (isset($data['hasSeveralHours']) && $data['hasSeveralHours'] == true) {
|
||||||
// different hours spans make more choices
|
// different hours spans make more choices
|
||||||
|
|
||||||
foreach ($choices as $c) {
|
foreach ($choices as $c) {
|
||||||
|
$choices_debug .= '\n c ' . $c['literal'];
|
||||||
$currentDate = $c['literal'];
|
$currentDate = $c['literal'];
|
||||||
$timeSlicesOfThisChoice = $c['timeSlices'];
|
$timeSlicesOfThisChoice = $c['timeSlices'];
|
||||||
foreach ($timeSlicesOfThisChoice as $t) {
|
if (count($timeSlicesOfThisChoice)) {
|
||||||
|
|
||||||
|
foreach ($timeSlicesOfThisChoice as $t) {
|
||||||
|
$choices_debug .= '\n timeSlicesOfThisChoice ' . $t['literal'];
|
||||||
$newChoice = new Choice();
|
$newChoice = new Choice();
|
||||||
$newChoice
|
$newChoice
|
||||||
->setPoll($newpoll)
|
->setPoll($newpoll)
|
||||||
->setName($currentDate . ' >>> ' . $t['literal']);
|
->setName($currentDate . ' >>> ' . $t['literal']);
|
||||||
$em->persist($newChoice);
|
|
||||||
$newpoll->addChoice($newChoice);
|
$newpoll->addChoice($newChoice);
|
||||||
|
$em->persist($newChoice);
|
||||||
|
$em->persist($newpoll);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$newChoice = new Choice();
|
||||||
|
$newChoice
|
||||||
|
->setPoll($newpoll)
|
||||||
|
->setName($currentDate);
|
||||||
|
$newpoll->addChoice($newChoice);
|
||||||
|
$em->persist($newChoice);
|
||||||
|
$em->persist($newpoll);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user