1
0
mirror of https://framagit.org/tykayn/date-poll-api synced 2023-08-25 08:23:11 +02:00

up debug message in poll creation

This commit is contained in:
Tykayn 2022-02-10 09:53:24 +01:00 committed by tykayn
parent 9414951370
commit 46d6d21c6b
2 changed files with 528 additions and 513 deletions

View File

@ -25,14 +25,16 @@ use Symfony\Component\HttpFoundation\Response;
* @package App\Controller
* @Route("/api/v1/poll",name="api_")
*/
class PollController extends EmailsController {
class PollController extends EmailsController
{
/**
* @Get(
* path = "/",
* name = "get_all_polls"
* )
*/
public function getAllPollsAction( PollRepository $pollRepository ): Response {
public function getAllPollsAction(PollRepository $pollRepository): Response
{
$data = $pollRepository->findAll();
@ -62,7 +64,7 @@ class PollController extends EmailsController {
}
/**
* get a poll config by its custom URL, we do not want polls to be reachable by their numeric id
* get a poll config by its public custom URL, we do not want polls to be reachable by their numeric id
* @Get(
* path = "/{customUrl}",
* name = "get_poll"
@ -77,7 +79,8 @@ class PollController extends EmailsController {
SerializerInterface $serializer,
$customUrl,
Request $request
) {
)
{
$repository = $this->getDoctrine()->getRepository(Poll::class);
$poll = $repository->findOneByCustomUrl($customUrl);
@ -116,7 +119,8 @@ class PollController extends EmailsController {
*
* @return JsonResponse
*/
public function notFoundPoll( $id ): Response {
public function notFoundPoll($id): Response
{
return $this->json([
'message' => $id . ' : poll not found',
],
@ -132,7 +136,8 @@ class PollController extends EmailsController {
*
* @return JsonResponse|Response
*/
function getOwnerPolls( $owner_email , LoggerInterface $logger ) {
function getOwnerPolls($owner_email, LoggerInterface $logger)
{
$repository = $this->getDoctrine()->getRepository(Owner::class);
$owner = $repository->findOneByEmail($owner_email);
if (!$owner) {
@ -165,7 +170,8 @@ class PollController extends EmailsController {
*
* @return JsonResponse|Response
*/
function getProtectedPoll( $customUrl, $md5, SerializerInterface $serializer ) {
function getProtectedPoll($customUrl, $md5, SerializerInterface $serializer)
{
$repository = $this->getDoctrine()->getRepository(Poll::class);
$poll = $repository->findOneByCustomUrl($customUrl);
@ -193,7 +199,9 @@ class PollController extends EmailsController {
/**
* as an administrator of a poll, get a poll config by its custom URL, we do not want polls to be reachable by their numeric id
* as an administrator of a poll,
* get a poll config by its custom URL,
* we do not want polls to be reachable by their numeric id
* @Get(
* path = "admin/{admin_key}",
* name = "get_admin_poll",
@ -204,7 +212,8 @@ class PollController extends EmailsController {
*
* @return JsonResponse|Response
*/
function getAdminPoll( $admin_key, $md5, SerializerInterface $serializer ) {
function getAdminPoll($admin_key, $md5, SerializerInterface $serializer)
{
$repository = $this->getDoctrine()->getRepository(Poll::class);
$poll = $repository->findOneByAdminKey($admin_key);
@ -224,7 +233,8 @@ class PollController extends EmailsController {
* @param $serializer
* @return Response
*/
function returnPollData( $poll, $serializer ) {
function returnPollData($poll, $serializer)
{
$jsonResponse = $serializer->serialize($poll, 'json');
$response = new Response($jsonResponse);
@ -245,7 +255,8 @@ class PollController extends EmailsController {
Poll $poll,
string $token,
Request $request
) {
)
{
if ($poll->getAdminKey() !== $token) {
return $this->json([
'message' => 'you are NOT allowed to update the poll ' . $poll->getTitle(),
@ -274,7 +285,8 @@ class PollController extends EmailsController {
* create a new poll
* @return JsonResponse
*/
public function newPollAction( Request $request ) {
public function newPollAction(Request $request)
{
$data = $request->getContent();
$data = json_decode($data, true);
@ -284,7 +296,7 @@ class PollController extends EmailsController {
$repository = $this->getDoctrine()->getRepository(Poll::class);
$poll = $repository->findOneByCustomUrl($custom_url);
if ($poll) {
throw new \JsonException( 'NOPE, ce sondage existe déjà: ' . $custom_url );
return $this->json(["message"=> 'NOPE, ce sondage existe déjà: ' . $custom_url], 403 );
}
$newpoll = new Poll();
@ -292,7 +304,7 @@ class PollController extends EmailsController {
->setModificationPolicy(isset($data['modification_policy']) ? $data['modification_policy'] : 'everybody')
->setTitle($data['title'])
->setKind($data['kind'])
->setCustomUrl( $data[ 'custom_url' ] );
->setCustomUrl($custom_url);
if (count($data['allowed_answers'])) {
// TODO check this one
$newpoll->setAllowedAnswers($data['allowed_answers']);
@ -346,10 +358,11 @@ class PollController extends EmailsController {
$newpoll->setPassword($data['password']);
}
$choices_debug = '';
// text kind of answers, dates are below
if ($data['kind'] == 'text') {
// manage choices
$choices = $data[ 'choices' ];
$choices = $data['choicesText'];
foreach ($choices as $c) {
$newChoice = new Choice();
$newChoice
@ -362,12 +375,12 @@ class PollController extends EmailsController {
elseif ($data['kind'] == 'date') {
$choices = $data['dateChoices'];
$choices_debug .= 'debug count recieved' . count($choices);
if (isset($data['hasSeveralHours']) && $data['hasSeveralHours'] == true) {
// different hours spans make more choices
foreach ($choices as $c) {
$currentDate = $c['literal'];
$timeSlicesOfThisChoice = $c['timeSlices'];
foreach ($timeSlicesOfThisChoice as $t) {
@ -413,10 +426,9 @@ class PollController extends EmailsController {
$this->sendCreationMailAction($foundOwner, $newpoll);
$newChoices = $newpoll->display()[ 'choices' ];
return $this->json([
'message' => 'you created the poll ' . $newpoll->getCustomUrl() . $precision,
'message' => 'you created the poll ' . $newpoll->getCustomUrl() . ' ' . $precision,
'debug' => $choices_debug,
'id' => $newpoll->getId(),
'poll' => $newpoll->displayForAdmin(),
'password_protected' => is_string($newpoll->getPassword()),
@ -444,7 +456,8 @@ class PollController extends EmailsController {
// public function sendCreationMailAction( Owner $admin_user, Poll $poll, \Swift_Mailer $mailer) {
public function testSendCreationMailAction(
$emailChoice = 'tktest_commentateur@tktest.com'
) {
)
{
$em = $this->getDoctrine()->getRepository(Poll::class);
$foundPoll = $em->findOneByCustomUrl('dessin-anime');
$em = $this->getDoctrine()->getRepository(Owner::class);
@ -470,7 +483,8 @@ class PollController extends EmailsController {
public
function deletePollAction(
$admin_key
) {
)
{
$emPoll = $this->getDoctrine()->getRepository(Poll::class);
$found = $emPoll->findOneByAdminKey($admin_key);
@ -499,7 +513,8 @@ class PollController extends EmailsController {
* name = "check_slug_is_unique",
* )
*/
public function checkSlugIsUniqueAction( string $customUrl ) {
public function checkSlugIsUniqueAction(string $customUrl)
{
$emPoll = $this->getDoctrine()->getRepository(Poll::class);
$found = $emPoll->findOneByCustomUrl($customUrl);
$elaborated_message_version = false;
@ -546,7 +561,8 @@ class PollController extends EmailsController {
*
* @return JsonResponse|Response
*/
public function getAdministrationConfig( SerializerInterface $serializer, $token ) {
public function getAdministrationConfig(SerializerInterface $serializer, $token)
{
$emPoll = $this->getDoctrine()->getRepository(Poll::class);
$pollFound = $emPoll->findOneByAdminKey($token);
@ -584,7 +600,8 @@ class PollController extends EmailsController {
*
* @return JsonResponse|Response
*/
public function getExpiredPollsCleanup( $token ) {
public function getExpiredPollsCleanup($token)
{
if ($token !== 'superCaligistriixpirlidouciousse') {
return $this->json([

View File

@ -306,8 +306,6 @@ class Poll
// handle sub time slices
if (count($boom) == 2) {
if (!isset($grouped_dates[$boom[0]])) {
$grouped_dates[$boom[0]] = [