2019-11-05 12:16:16 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
2019-11-05 16:31:27 +01:00
|
|
|
use App\Entity\Poll;
|
2019-11-05 12:16:16 +01:00
|
|
|
use FOS\RestBundle\Controller\Annotations\Get;
|
2019-11-05 16:31:27 +01:00
|
|
|
use FOS\RestBundle\Controller\Annotations\Post;
|
|
|
|
use FOS\RestBundle\Controller\Annotations\Route;
|
2019-11-05 12:16:16 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class DefaultController
|
|
|
|
* @package App\Controller
|
|
|
|
* @Route("/api",name="api_")
|
|
|
|
*/
|
|
|
|
class DefaultController extends AbstractController {
|
|
|
|
/**
|
|
|
|
* @Get(path ="/",
|
2019-11-05 16:31:27 +01:00
|
|
|
* name = "get_default")
|
2019-11-05 12:16:16 +01:00
|
|
|
*/
|
|
|
|
public function index() {
|
|
|
|
return $this->json( [
|
|
|
|
'message' => 'Welcome to your new controller!',
|
|
|
|
'path' => 'src/Controller/DefaultController.php',
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Get(
|
|
|
|
* path = "/my-polls",
|
2019-11-05 16:31:27 +01:00
|
|
|
* name = "get_my_polls",
|
2019-11-05 12:16:16 +01:00
|
|
|
* requirements = {"access_token"="\w+"}
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function showMyPollsAction() {
|
|
|
|
return $this->json( [
|
|
|
|
'message' => 'here are your polls',
|
2019-11-05 16:31:27 +01:00
|
|
|
'data' => new Poll(),
|
2019-11-05 12:16:16 +01:00
|
|
|
] );
|
|
|
|
}
|
2019-11-05 16:31:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Get(
|
|
|
|
* path = "/poll/{id}/comments",
|
|
|
|
* name = "get_poll_comment",
|
|
|
|
* requirements = {"id"="\d+"}
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function getPollCommentsAction() {
|
|
|
|
return $this->json( [
|
|
|
|
'message' => 'here are your comments of the poll',
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Get(
|
|
|
|
* path = "/poll/all",
|
|
|
|
* name = "get_all_polls"
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function getAllPollsAction() {
|
|
|
|
$repository = $this->getDoctrine()->getRepository( Poll::class );
|
2019-11-05 17:31:07 +01:00
|
|
|
$data = $repository->findall();
|
2019-11-05 16:31:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
return $this->json( [
|
|
|
|
'message' => 'here are your polls',
|
2019-11-05 17:31:07 +01:00
|
|
|
'data' => $data,
|
2019-11-05 16:31:27 +01:00
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Post(
|
|
|
|
* path = "/poll/new",
|
|
|
|
* name = "new_polls",
|
|
|
|
* requirements = {"creator"="\w+"}
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function newPollAction( Poll $poll ) {
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
|
|
|
|
$em->persist( $poll );
|
|
|
|
$em->flush();
|
|
|
|
|
|
|
|
// return $poll;
|
|
|
|
|
|
|
|
return $this->json( $poll );
|
|
|
|
|
|
|
|
// return $this->json( [
|
|
|
|
// 'message' => 'you created a poll',
|
|
|
|
// ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Get(
|
|
|
|
* path = "/poll/{id}",
|
|
|
|
* name = "get_poll",
|
|
|
|
* requirements = {"id"="\d+"}
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function getPollConfig( Poll $poll ) {
|
|
|
|
return $this->json( [
|
|
|
|
'message' => 'your poll config',
|
|
|
|
'data' => $poll,
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Post(
|
|
|
|
* path = "/poll/{id}/up",
|
|
|
|
* name = "up_poll",
|
|
|
|
* requirements = {"content"="\w+"}
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function updatePollConfig( Poll $poll ) {
|
|
|
|
return $this->json( [
|
|
|
|
'message' => 'you updated the poll',
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Post(
|
|
|
|
* path = "/comment/new",
|
|
|
|
* name = "new_comment",
|
|
|
|
* requirements = {"content"="\w+"}
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function newCommentAction() {
|
|
|
|
return $this->json( [
|
|
|
|
'message' => 'you created a comment',
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
2019-11-05 17:22:30 +01:00
|
|
|
|
|
|
|
public function deletePollAction() {
|
|
|
|
return $this->json( [
|
|
|
|
'message' => 'boom',
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deletePollCommentsAction() {
|
|
|
|
return $this->json( [
|
|
|
|
'message' => 'boom',
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deletePollVotesAction() {
|
|
|
|
return $this->json( [
|
|
|
|
'message' => 'boom',
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
2019-11-05 12:16:16 +01:00
|
|
|
}
|