1
0
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:
Baptiste Lemoine 2019-11-06 11:23:43 +01:00
parent 063241ede6
commit 13cd182f3c
4 changed files with 30 additions and 26 deletions

View File

@ -2,7 +2,6 @@
fos_rest: fos_rest:
# param_fetcher_listener: true # param_fetcher_listener: true
# allowed_methods_listener: true # allowed_methods_listener: true
# routing_loader: true
# view: # view:
# view_response_listener: true # view_response_listener: true
# exception: # exception:
@ -10,8 +9,7 @@ fos_rest:
# App\Exception\MyException: 403 # App\Exception\MyException: 403
# messages: # messages:
# App\Exception\MyException: Forbidden area. # App\Exception\MyException: Forbidden area.
routing_loader: routing_loader: true
default_format: json
format_listener: format_listener:
rules: rules:
- { path: '^/', - { path: '^/',

View File

@ -1,8 +1,8 @@
nelmio_api_doc: nelmio_api_doc:
documentation: documentation:
info: info:
title: My App title: Poll Bliss
description: This is an awesome app! description: Sondages à la framadate par CipherBliss
version: 1.0.0 version: 1.0.0
areas: # to filter documented areas areas: # to filter documented areas
path_patterns: path_patterns:

View File

@ -7,11 +7,12 @@ use FOS\RestBundle\Controller\Annotations\Get;
use FOS\RestBundle\Controller\Annotations\Post; use FOS\RestBundle\Controller\Annotations\Post;
use FOS\RestBundle\Controller\Annotations\Route; use FOS\RestBundle\Controller\Annotations\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
/** /**
* Class DefaultController * Class DefaultController
* @package App\Controller * @package App\Controller
* @Route("/api",name="api_") * @Route("/api/v1",name="api_")
*/ */
class DefaultController extends AbstractController { class DefaultController extends AbstractController {
/** /**
@ -75,20 +76,25 @@ class DefaultController extends AbstractController {
* name = "new_polls", * name = "new_polls",
* requirements = {"creator"="\w+"} * requirements = {"creator"="\w+"}
* ) * )
* @param Request $request
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/ */
public function newPollAction( Poll $poll ) { public function newPollAction( Request $request ) {
$em = $this->getDoctrine()->getManager();
$data = $request->getContent();
$poll = $this->get( 'jms_serializer' )->deserialize( $data, Poll::class, 'json' );
$em = $this->getDoctrine()->getManager();
$em->persist( $poll ); $em->persist( $poll );
$em->flush(); $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',
// ] );
} }
/** /**

View File

@ -16,18 +16,18 @@ class Poll {
* @ORM\Id() * @ORM\Id()
* @ORM\GeneratedValue() * @ORM\GeneratedValue()
* @ORM\Column(type="integer") * @ORM\Column(type="integer")
* @Serializer\Expose * @Serializer\Expose()
*/ */
private $id; public $id;
/** /**
* @ORM\Column(type="string", length=255) * @ORM\Column(type="string", length=255)
* @Serializer\Expose * @Serializer\Expose()
*/ */
public $title; public $title;
/** /**
* @ORM\Column(type="string", length=255, nullable=true) * @ORM\Column(type="string", length=255, nullable=true)
* @Serializer\Expose * @Serializer\Expose()
*/ */
private $customUrl; private $customUrl;
@ -39,13 +39,13 @@ class Poll {
/** /**
* @ORM\Column(type="string", length=1000) * @ORM\Column(type="string", length=1000)
* @Serializer\Expose * @Serializer\Expose()
*/ */
private $description; private $description;
/** /**
* @ORM\Column(type="datetime") * @ORM\Column(type="datetime")
* @Serializer\Expose * @Serializer\Expose()
*/ */
private $creationDate; private $creationDate;