Commit 152f04f0 authored by Mat's avatar Mat

groupes de serialisation

parent 7191ddac
......@@ -11,7 +11,7 @@ class MessageController extends FOSRestController
{
/**
* @Rest\Get("/message")
* @Rest\View()
* @Rest\View(serializerGroups={"getMessage"})
*/
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 @@
namespace SocketBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/**
* Message
......@@ -18,6 +19,7 @@ class Message
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"getMessage"})
*/
private $id;
......@@ -26,6 +28,7 @@ class Message
* @var User
* @ORM\ManyToOne(targetEntity="SocketBundle\Entity\User")
* @ORM\JoinColumn(name="id_author", nullable=false)
* @Serializer\Groups({"getMessage"})
*/
private $author;
......@@ -33,12 +36,14 @@ class Message
* @var User
* @ORM\ManyToOne(targetEntity="SocketBundle\Entity\User")
* @ORM\JoinColumn(name="id_receiver", nullable=false)
* @Serializer\Groups({"getMessage"})
*/
private $receiver;
/**
* @var string
* @ORM\Column(name="content", type="text", nullable=false, unique=false)
* @Serializer\Groups({"getMessage"})
*/
private $content;
......
......@@ -33,6 +33,7 @@ class User implements UserInterface
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"getMessage", "getUser"})
*/
private $id;
......@@ -40,6 +41,7 @@ class User implements UserInterface
* @var string
* @ORM\Column(name="username", type="string", length=255, nullable=false, unique=true)
* @Assert\NotBlank()
* @Serializer\Groups({"getMessage", "getUser"})
*/
private $username;
......@@ -61,6 +63,7 @@ class User implements UserInterface
/**
* @var array
* @ORM\Column(name="role", type="array", length=255, nullable=false, unique=false)
* @Serializer\Groups({"getUser"})
*/
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