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

more endpoints

This commit is contained in:
Baptiste Lemoine 2019-11-05 16:31:27 +01:00
parent 8aa8be308e
commit 85f643bcce
9 changed files with 507 additions and 314 deletions

View File

@ -18,6 +18,7 @@
"symfony/yaml": "4.3.*"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.2",
"symfony/maker-bundle": "^1.14",
"symfony/web-server-bundle": "4.3.*"
},

513
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -3,11 +3,11 @@
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
FOS\RestBundle\FOSRestBundle::class => ['all' => true],
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
];

View File

@ -1,3 +0,0 @@
sensio_framework_extra:
router:
annotations: false

View File

@ -2,8 +2,10 @@
namespace App\Controller;
use App\Entity\Poll;
use FOS\RestBundle\Controller\Annotations\Get;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use FOS\RestBundle\Controller\Annotations\Post;
use FOS\RestBundle\Controller\Annotations\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
/**
@ -14,7 +16,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class DefaultController extends AbstractController {
/**
* @Get(path ="/",
* name = "app_get_default")
* name = "get_default")
*/
public function index() {
return $this->json( [
@ -26,13 +28,107 @@ class DefaultController extends AbstractController {
/**
* @Get(
* path = "/my-polls",
* name = "app_get_my_polls",
* name = "get_my_polls",
* requirements = {"access_token"="\w+"}
* )
*/
public function showMyPollsAction() {
return $this->json( [
'message' => 'here are your polls',
'data' => new Poll(),
] );
}
/**
* @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 );
$polls = $repository->findall();
return $this->json( [
'message' => 'here are your polls',
'data' => $polls,
] );
}
/**
* @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',
] );
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
class AppFixtures extends Fixture
{
public function load(ObjectManager $manager)
{
// $product = new Product();
// $manager->persist($product);
$manager->flush();
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\DataFixtures;
use App\Entity\Poll;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
class AppPollFixtures extends Fixture {
public function load( ObjectManager $manager ) {
// $product = new Product();
$poll = new Poll();
$poll->setTitle( 'démo sondage de texte' );
$poll->setCreationDate( new \DateTime() );
$poll->setExpiracyDate( new \DateTime( ( time() + 3600 * 24 ) ) );
$manager->persist( $poll );
$manager->flush();
}
}

View File

@ -20,6 +20,9 @@
"doctrine/common": {
"version": "v2.11.0"
},
"doctrine/data-fixtures": {
"version": "v1.3.2"
},
"doctrine/dbal": {
"version": "v2.9.2"
},
@ -41,6 +44,18 @@
"doctrine/doctrine-cache-bundle": {
"version": "1.3.5"
},
"doctrine/doctrine-fixtures-bundle": {
"version": "3.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "3.0",
"ref": "fc52d86631a6dfd9fdf3381d0b7e3df2069e51b3"
},
"files": [
"src/DataFixtures/AppFixtures.php"
]
},
"doctrine/doctrine-migrations-bundle": {
"version": "1.2",
"recipe": {
@ -170,18 +185,6 @@
"psr/log": {
"version": "1.1.0"
},
"sensio/framework-extra-bundle": {
"version": "5.2",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "5.2",
"ref": "fb7e19da7f013d0d422fa9bce16f5c510e27609b"
},
"files": [
"config/packages/sensio_framework_extra.yaml"
]
},
"symfony/cache": {
"version": "v4.3.5"
},