mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
⚡ start creation endpoint
This commit is contained in:
parent
063241ede6
commit
13cd182f3c
@ -2,7 +2,6 @@
|
||||
fos_rest:
|
||||
# param_fetcher_listener: true
|
||||
# allowed_methods_listener: true
|
||||
# routing_loader: true
|
||||
# view:
|
||||
# view_response_listener: true
|
||||
# exception:
|
||||
@ -10,8 +9,7 @@ fos_rest:
|
||||
# App\Exception\MyException: 403
|
||||
# messages:
|
||||
# App\Exception\MyException: Forbidden area.
|
||||
routing_loader:
|
||||
default_format: json
|
||||
routing_loader: true
|
||||
format_listener:
|
||||
rules:
|
||||
- { path: '^/',
|
||||
|
@ -1,9 +1,9 @@
|
||||
nelmio_api_doc:
|
||||
documentation:
|
||||
info:
|
||||
title: My App
|
||||
description: This is an awesome app!
|
||||
version: 1.0.0
|
||||
areas: # to filter documented areas
|
||||
path_patterns:
|
||||
- ^/api(?!/doc$) # Accepts routes under /api except /api/doc
|
||||
documentation:
|
||||
info:
|
||||
title: Poll Bliss
|
||||
description: Sondages à la framadate par CipherBliss
|
||||
version: 1.0.0
|
||||
areas: # to filter documented areas
|
||||
path_patterns:
|
||||
- ^/api(?!/doc$) # Accepts routes under /api except /api/doc
|
||||
|
@ -7,11 +7,12 @@ use FOS\RestBundle\Controller\Annotations\Get;
|
||||
use FOS\RestBundle\Controller\Annotations\Post;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Class DefaultController
|
||||
* @package App\Controller
|
||||
* @Route("/api",name="api_")
|
||||
* @Route("/api/v1",name="api_")
|
||||
*/
|
||||
class DefaultController extends AbstractController {
|
||||
/**
|
||||
@ -75,20 +76,25 @@ class DefaultController extends AbstractController {
|
||||
* name = "new_polls",
|
||||
* requirements = {"creator"="\w+"}
|
||||
* )
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse
|
||||
*/
|
||||
public function newPollAction( Poll $poll ) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
public function newPollAction( Request $request ) {
|
||||
|
||||
$data = $request->getContent();
|
||||
$poll = $this->get( 'jms_serializer' )->deserialize( $data, Poll::class, 'json' );
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist( $poll );
|
||||
$em->flush();
|
||||
|
||||
// return $poll;
|
||||
return $this->json( [
|
||||
'message' => 'you created a poll',
|
||||
'data' => $poll,
|
||||
],
|
||||
203 );
|
||||
|
||||
return $this->json( $poll );
|
||||
|
||||
// return $this->json( [
|
||||
// 'message' => 'you created a poll',
|
||||
// ] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,18 +16,18 @@ class Poll {
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
* @ORM\Column(type="integer")
|
||||
* @Serializer\Expose
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
private $id;
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255)
|
||||
* @Serializer\Expose
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $title;
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @Serializer\Expose
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
private $customUrl;
|
||||
|
||||
@ -39,13 +39,13 @@ class Poll {
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=1000)
|
||||
* @Serializer\Expose
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
* @Serializer\Expose
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
private $creationDate;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user