Commit 152f04f0 authored by Mat's avatar Mat

groupes de serialisation

parent 7191ddac
...@@ -11,7 +11,7 @@ class MessageController extends FOSRestController ...@@ -11,7 +11,7 @@ class MessageController extends FOSRestController
{ {
/** /**
* @Rest\Get("/message") * @Rest\Get("/message")
* @Rest\View() * @Rest\View(serializerGroups={"getMessage"})
*/ */
public function getAction() public function getAction()
{ {
......
<?php
namespace Api2Bundle\Controller;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController;
use SocketBundle\Entity\User;
class UserController extends FOSRestController
{
/**
* @Rest\Get(path="/user")
* @Rest\View(serializerGroups={"getUser"})
*/
public function getAction()
{
return $this->getDoctrine()
->getRepository(User::class)
->findAll();
}
}
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace SocketBundle\Entity; namespace SocketBundle\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/** /**
* Message * Message
...@@ -18,6 +19,7 @@ class Message ...@@ -18,6 +19,7 @@ class Message
* @ORM\Column(name="id", type="integer") * @ORM\Column(name="id", type="integer")
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO") * @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"getMessage"})
*/ */
private $id; private $id;
...@@ -26,6 +28,7 @@ class Message ...@@ -26,6 +28,7 @@ class Message
* @var User * @var User
* @ORM\ManyToOne(targetEntity="SocketBundle\Entity\User") * @ORM\ManyToOne(targetEntity="SocketBundle\Entity\User")
* @ORM\JoinColumn(name="id_author", nullable=false) * @ORM\JoinColumn(name="id_author", nullable=false)
* @Serializer\Groups({"getMessage"})
*/ */
private $author; private $author;
...@@ -33,12 +36,14 @@ class Message ...@@ -33,12 +36,14 @@ class Message
* @var User * @var User
* @ORM\ManyToOne(targetEntity="SocketBundle\Entity\User") * @ORM\ManyToOne(targetEntity="SocketBundle\Entity\User")
* @ORM\JoinColumn(name="id_receiver", nullable=false) * @ORM\JoinColumn(name="id_receiver", nullable=false)
* @Serializer\Groups({"getMessage"})
*/ */
private $receiver; private $receiver;
/** /**
* @var string * @var string
* @ORM\Column(name="content", type="text", nullable=false, unique=false) * @ORM\Column(name="content", type="text", nullable=false, unique=false)
* @Serializer\Groups({"getMessage"})
*/ */
private $content; private $content;
......
...@@ -33,6 +33,7 @@ class User implements UserInterface ...@@ -33,6 +33,7 @@ class User implements UserInterface
* @ORM\Column(name="id", type="integer") * @ORM\Column(name="id", type="integer")
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO") * @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"getMessage", "getUser"})
*/ */
private $id; private $id;
...@@ -40,6 +41,7 @@ class User implements UserInterface ...@@ -40,6 +41,7 @@ class User implements UserInterface
* @var string * @var string
* @ORM\Column(name="username", type="string", length=255, nullable=false, unique=true) * @ORM\Column(name="username", type="string", length=255, nullable=false, unique=true)
* @Assert\NotBlank() * @Assert\NotBlank()
* @Serializer\Groups({"getMessage", "getUser"})
*/ */
private $username; private $username;
...@@ -61,6 +63,7 @@ class User implements UserInterface ...@@ -61,6 +63,7 @@ class User implements UserInterface
/** /**
* @var array * @var array
* @ORM\Column(name="role", type="array", length=255, nullable=false, unique=false) * @ORM\Column(name="role", type="array", length=255, nullable=false, unique=false)
* @Serializer\Groups({"getUser"})
*/ */
private $role; private $role;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment