From 9cfb974c2719e9c838feb9f627700c70a9e25358 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Thu, 10 Feb 2022 11:02:03 +0100 Subject: [PATCH] handle creation of mixed subset of datechoice --- README.md | 90 ++++++++++++------------ src/Controller/PollController.php | 20 +----- src/Controller/api/v1/PollController.php | 57 +++++++++++---- 3 files changed, 90 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index 6a65e46..96a785b 100755 --- a/README.md +++ b/README.md @@ -8,50 +8,52 @@ https://framagit.org/framasoft/framadate/funky-framadate-front ------------------------------------ --------------- -------- ------ -------------------------------------------------- Name Method Scheme Host Path ------------------------------------ --------------- -------- ------ -------------------------------------------------- - _preview_error ANY ANY ANY /_error/{code}.{_format} - _wdt ANY ANY ANY /_wdt/{token} - _profiler_home ANY ANY ANY /_profiler/ - _profiler_search ANY ANY ANY /_profiler/search - _profiler_search_bar ANY ANY ANY /_profiler/search_bar - _profiler_phpinfo ANY ANY ANY /_profiler/phpinfo - _profiler_search_results ANY ANY ANY /_profiler/{token}/search/results - _profiler_open_file ANY ANY ANY /_profiler/open - _profiler ANY ANY ANY /_profiler/{token} - _profiler_router ANY ANY ANY /_profiler/{token}/router - _profiler_exception ANY ANY ANY /_profiler/{token}/exception - _profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css - admin_homepage_get_default GET ANY ANY /admin/ - admin_homepage_clean_expired_polls GET ANY ANY /admin/polls/clean/{token} - admin_homepage_migrate_framadate GET ANY ANY /admin/polls/migrate - home_sweet_home GET ANY ANY / - admin_homepage_migrate_from_v1 GET ANY ANY /migration-from-v1/{unique_key} - user_homepageget_default GET ANY ANY /user/ - user_homepage_polls_send_by_email GET ANY ANY /user/{email}/polls/send-by-email - poll_index GET ANY ANY /poll/ - poll_new GET|POST ANY ANY /poll/new - poll_show GET ANY ANY /poll/{id} - poll_edit GET|POST ANY ANY /poll/{id}/edit - poll_delete DELETE ANY ANY /poll/{id} - 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_poll_comments_delete DELETE ANY ANY /api/v1/comment/poll/{id}/comments - api_get_all_polls GET ANY ANY /api/v1/poll/ - 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_protected_poll GET ANY ANY /api/v1/poll/{customUrl}/pass/{md5} - 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_new_poll POST ANY ANY /api/v1/poll/ - 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_check_slug_is_unique GET ANY ANY /api/v1/poll/slug/{customUrl} - api_get_admin_config GET ANY ANY /api/v1/poll/admin/{token} - api_clean_expired_polls GET ANY ANY /api/v1/poll/admin/clean_expired_polls/{token} - api_new_vote_stack POST|OPTIONS ANY ANY /api/v1/vote-stack/ - api_update_vote_stack PATCH|OPTIONS ANY ANY /api/v1/vote-stack/{id}/token/{modifierToken} - api_delete_vote_stack DELETE ANY ANY /api/v1/vote-stack/{id}/token/{modifierToken} - api_poll_votes_delete DELETE ANY ANY /api/v1/vote-stack/poll/{id}/votes/{accessToken} - app.swagger GET ANY ANY /api/doc.json +_preview_error ANY ANY ANY /_error/{code}.{_format} +_wdt ANY ANY ANY /_wdt/{token} +_profiler_home ANY ANY ANY /_profiler/ +_profiler_search ANY ANY ANY /_profiler/search +_profiler_search_bar ANY ANY ANY /_profiler/search_bar +_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo +_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results +_profiler_open_file ANY ANY ANY /_profiler/open +_profiler ANY ANY ANY /_profiler/{token} +_profiler_router ANY ANY ANY /_profiler/{token}/router +_profiler_exception ANY ANY ANY /_profiler/{token}/exception +_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css +admin_homepage_get_default GET ANY ANY /admin/ +admin_homepage_clean_expired_polls GET ANY ANY /admin/polls/clean/{token} +admin_homepage_migrate_framadate GET ANY ANY /admin/polls/migrate +home_sweet_home GET ANY ANY / +admin_homepage_migrate_from_v1 GET ANY ANY /migration-from-v1/{unique_key} +user_homepageget_default GET ANY ANY /user/ +user_homepage_polls_send_by_email GET ANY ANY /user/{email}/polls/send-by-email +poll_index GET ANY ANY /poll/ +poll_new POST ANY ANY /poll/new +poll_show GET ANY ANY /poll/id/{id} +poll_edit GET|POST ANY ANY /poll/{id}/edit +poll_delete DELETE ANY ANY /poll/{id} +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_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_poll GET ANY ANY /api/v1/poll/{customUrl} +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_admin_poll GET ANY ANY /api/v1/polladmin/{admin_key} +api_update_poll PUT ANY ANY /api/v1/poll/{customUrl}/update/{token} +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_poll_delete DELETE ANY ANY /api/v1/poll/{admin_key} +api_check_slug_is_unique GET ANY ANY /api/v1/poll/slug/{customUrl} +api_get_admin_config GET ANY ANY /api/v1/poll/admin/{token} +api_clean_expired_polls GET ANY ANY /api/v1/poll/admin/clean_expired_polls/{token} +api_new_vote_stack POST|OPTIONS ANY ANY /api/v1/vote-stack/ +api_update_vote_stack PATCH|OPTIONS ANY ANY /api/v1/vote-stack/{id}/token/{modifierToken} +api_delete_vote_stack DELETE ANY ANY /api/v1/vote-stack/{id}/token/{modifierToken} +api_poll_votes_delete DELETE ANY ANY /api/v1/vote-stack/poll/{id}/votes/{accessToken} +app.swagger GET ANY ANY /api/doc.json ------------------------------------ --------------- -------- ------ -------------------------------------------------- ## TODO: diff --git a/src/Controller/PollController.php b/src/Controller/PollController.php index 5484760..d25a26b 100755 --- a/src/Controller/PollController.php +++ b/src/Controller/PollController.php @@ -15,24 +15,6 @@ use Symfony\Component\Routing\Annotation\Route; * @Route("/poll") */ 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"}) */ @@ -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 { $poll = new Poll(); diff --git a/src/Controller/api/v1/PollController.php b/src/Controller/api/v1/PollController.php index 8429ceb..030d4c1 100755 --- a/src/Controller/api/v1/PollController.php +++ b/src/Controller/api/v1/PollController.php @@ -10,7 +10,6 @@ use App\Repository\PollRepository; use DateTime; use FOS\RestBundle\Controller\Annotations\Delete; use FOS\RestBundle\Controller\Annotations\Get; -use FOS\RestBundle\Controller\Annotations\Post; use FOS\RestBundle\Controller\Annotations\Put; use FOS\RestBundle\Controller\Annotations\Route; use JMS\Serializer\SerializerInterface; @@ -27,6 +26,23 @@ use Symfony\Component\HttpFoundation\Response; */ 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( * path = "/", @@ -277,31 +293,32 @@ class PollController extends EmailsController /** - * @Post( - * path = "/", - * name = "new_poll" + * @Route( + * "/", + * "_new_poll", + * methods={"POST"} * ) * @param Request $request * create a new poll * @return JsonResponse */ - public function newPollAction(Request $request): JsonResponse + public function newPoll(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 ); + 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) { - return $this->json(["message"=> 'NOPE, ce sondage existe déjà: ' . $custom_url], 403 ); - } + return $this->json(["message" => 'NOPE, ce sondage existe déjà: ' . $custom_url], 403); + } $newpoll = new Poll(); $newpoll @@ -379,21 +396,33 @@ class PollController extends EmailsController elseif ($data['kind'] == 'date') { $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) { // different hours spans make more choices - foreach ($choices as $c) { + $choices_debug .= '\n c ' . $c['literal']; $currentDate = $c['literal']; $timeSlicesOfThisChoice = $c['timeSlices']; - foreach ($timeSlicesOfThisChoice as $t) { + if (count($timeSlicesOfThisChoice)) { + foreach ($timeSlicesOfThisChoice as $t) { + $choices_debug .= '\n timeSlicesOfThisChoice ' . $t['literal']; + $newChoice = new Choice(); + $newChoice + ->setPoll($newpoll) + ->setName($currentDate . ' >>> ' . $t['literal']); + $newpoll->addChoice($newChoice); + $em->persist($newChoice); + $em->persist($newpoll); + } + } else { $newChoice = new Choice(); $newChoice ->setPoll($newpoll) - ->setName($currentDate . ' >>> ' . $t['literal']); - $em->persist($newChoice); + ->setName($currentDate); $newpoll->addChoice($newChoice); + $em->persist($newChoice); + $em->persist($newpoll); } }