handle creation of mixed subset of datechoice

This commit is contained in:
Tykayn 2022-02-10 11:02:03 +01:00 committed by tykayn
parent e488b76a2d
commit 9cfb974c27
3 changed files with 90 additions and 77 deletions

View File

@ -8,50 +8,52 @@ https://framagit.org/framasoft/framadate/funky-framadate-front
------------------------------------ --------------- -------- ------ -------------------------------------------------- ------------------------------------ --------------- -------- ------ --------------------------------------------------
Name Method Scheme Host Path Name Method Scheme Host Path
------------------------------------ --------------- -------- ------ -------------------------------------------------- ------------------------------------ --------------- -------- ------ --------------------------------------------------
_preview_error ANY ANY ANY /_error/{code}.{_format} _preview_error ANY ANY ANY /_error/{code}.{_format}
_wdt ANY ANY ANY /_wdt/{token} _wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/ _profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search _profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar _profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo _profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results _profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open _profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token} _profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router _profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception _profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css _profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
admin_homepage_get_default GET ANY ANY /admin/ admin_homepage_get_default GET ANY ANY /admin/
admin_homepage_clean_expired_polls GET ANY ANY /admin/polls/clean/{token} admin_homepage_clean_expired_polls GET ANY ANY /admin/polls/clean/{token}
admin_homepage_migrate_framadate GET ANY ANY /admin/polls/migrate admin_homepage_migrate_framadate GET ANY ANY /admin/polls/migrate
home_sweet_home GET ANY ANY / home_sweet_home GET ANY ANY /
admin_homepage_migrate_from_v1 GET ANY ANY /migration-from-v1/{unique_key} admin_homepage_migrate_from_v1 GET ANY ANY /migration-from-v1/{unique_key}
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_get_all_polls GET ANY ANY /api/v1/poll/ api_essai GET ANY ANY /api/v1/poll/essai
api_get_poll GET ANY ANY /api/v1/poll/{customUrl} api_get_all_polls GET ANY ANY /api/v1/poll/
api_get_owner_poll GET ANY ANY /api/v1/poll/owner/{owner_email}/ api_get_poll GET ANY ANY /api/v1/poll/{customUrl}
api_get_protected_poll GET ANY ANY /api/v1/poll/{customUrl}/pass/{md5} api_get_owner_poll GET ANY ANY /api/v1/poll/owner/{owner_email}/
api_get_admin_poll GET ANY ANY /api/v1/polladmin/{admin_key} api_get_protected_poll GET ANY ANY /api/v1/poll/{customUrl}/pass/{md5}
api_update_poll PUT ANY ANY /api/v1/poll/{customUrl}/update/{token} api_get_admin_poll GET ANY ANY /api/v1/polladmin/{admin_key}
api_new_poll POST ANY ANY /api/v1/poll/ api_update_poll PUT ANY ANY /api/v1/poll/{customUrl}/update/{token}
api_test-mail-poll GET ANY ANY /api/v1/poll/mail/test-mail-poll/{emailChoice} api_app_api_v1_poll_newpoll POST ANY ANY /api/v1/poll/
api_poll_delete DELETE ANY ANY /api/v1/poll/{admin_key} api_app_api_v1_poll_newpoll.1 POST ANY ANY /api/v1/poll_new_poll
api_check_slug_is_unique GET ANY ANY /api/v1/poll/slug/{customUrl} api_test-mail-poll GET ANY ANY /api/v1/poll/mail/test-mail-poll/{emailChoice}
api_get_admin_config GET ANY ANY /api/v1/poll/admin/{token} api_poll_delete DELETE ANY ANY /api/v1/poll/{admin_key}
api_clean_expired_polls GET ANY ANY /api/v1/poll/admin/clean_expired_polls/{token} api_check_slug_is_unique GET ANY ANY /api/v1/poll/slug/{customUrl}
api_new_vote_stack POST|OPTIONS ANY ANY /api/v1/vote-stack/ api_get_admin_config GET ANY ANY /api/v1/poll/admin/{token}
api_update_vote_stack PATCH|OPTIONS ANY ANY /api/v1/vote-stack/{id}/token/{modifierToken} api_clean_expired_polls GET ANY ANY /api/v1/poll/admin/clean_expired_polls/{token}
api_delete_vote_stack DELETE ANY ANY /api/v1/vote-stack/{id}/token/{modifierToken} api_new_vote_stack POST|OPTIONS ANY ANY /api/v1/vote-stack/
api_poll_votes_delete DELETE ANY ANY /api/v1/vote-stack/poll/{id}/votes/{accessToken} api_update_vote_stack PATCH|OPTIONS ANY ANY /api/v1/vote-stack/{id}/token/{modifierToken}
app.swagger GET ANY ANY /api/doc.json 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: ## TODO:

View File

@ -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();

View File

@ -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,31 +293,32 @@ 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();
$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'])){ if (!isset($data) || !isset($data['custom_url'])) {
return $this->json(["message"=> 'NOPE, pas de data ou de custom url'], 403 ); 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) {
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 = new Poll();
$newpoll $newpoll
@ -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
->setPoll($newpoll)
->setName($currentDate . ' >>> ' . $t['literal']);
$newpoll->addChoice($newChoice);
$em->persist($newChoice);
$em->persist($newpoll);
}
} else {
$newChoice = new Choice(); $newChoice = new Choice();
$newChoice $newChoice
->setPoll($newpoll) ->setPoll($newpoll)
->setName($currentDate . ' >>> ' . $t['literal']); ->setName($currentDate);
$em->persist($newChoice);
$newpoll->addChoice($newChoice); $newpoll->addChoice($newChoice);
$em->persist($newChoice);
$em->persist($newpoll);
} }
} }