From fdee3f07fe8c831fb1679f07b88439db03d6798a Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Fri, 17 Apr 2020 16:02:23 +0200 Subject: [PATCH] add call to check for uniq slug --- src/Controller/PollController.php | 34 +++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Controller/PollController.php b/src/Controller/PollController.php index 751498c..c7665b2 100644 --- a/src/Controller/PollController.php +++ b/src/Controller/PollController.php @@ -5,7 +5,6 @@ namespace App\Controller; use App\Entity\Choice; use App\Entity\Owner; use App\Entity\Poll; -use App\Service\MailService; use FOS\RestBundle\Controller\Annotations\Delete; use FOS\RestBundle\Controller\Annotations\Get; use FOS\RestBundle\Controller\Annotations\Post; @@ -268,7 +267,7 @@ class PollController extends FramadateController { $sent = $this->sendOwnerPollsAction( $foundOwner, $poll ); if ( $sent ) { - return $this->json( [ "message" => "test email sent to ".$foundOwner->getEmail()."!" ], 200 ); + return $this->json( [ "message" => "test email sent to " . $foundOwner->getEmail() . "!" ], 200 ); } } @@ -347,4 +346,35 @@ class PollController extends FramadateController { 200 ); } + /** + * Delete all expired polls and their children + * @Get( + * path = "/check-slug-is-unique/{slug}", + * name = "check_slug_is_unique", + * ) + */ + public function checkSlugIsUnique( $slug ) { + $emPoll = $this->getDoctrine()->getRepository( Poll::class ); + $found = $emPoll->findOneBySlug( $slug ); + if ( $found ) { + // we should not find an other poll + return $this->json( [ + 'message' => ' NO, this slug is already taken on this Framadate instance ', + 'data' => [ + 'slug' => $slug, + ], + ], + 403 ); + } + + return $this->json( [ + 'message' => ' yes this slug is available on this Framadate instance ', + 'data' => [ + 'slug' => $slug, + ], + ], + 200 ); + + } + }