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

add call to check for uniq slug

This commit is contained in:
Baptiste Lemoine 2020-04-17 16:02:23 +02:00
parent ac8242a443
commit fdee3f07fe

View File

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