Commit eccad323 authored by Mat's avatar Mat

API optimisation: readLettres group

parent 4b50b5aa
......@@ -72,7 +72,7 @@ class LettreAPIController extends MasterAPIController
{
$em = $this->getDoctrine()->getManager();
$lettres = $em->getRepository('PotageBundle:Lettre')->findAllByStatusForRead($status);
return $this->api($lettres);
return $this->api($lettres, 200, array('readLettres'));
}
......
......@@ -13,16 +13,14 @@ abstract class MasterAPIController extends MasterController
/**
* @param $data
* @param int $status
* @param array $groups
* @return JsonResponse
*/
protected function api($data, $status = 200)
protected function api($data, $status = 200, $groups = array())
{
$serializer = $this->get('jms_serializer');
$serialized = $serializer->serialize($data, 'json', SerializationContext::create()->enableMaxDepthChecks());
// if ($data instanceof Form) {
// $status = 400;
// }
$serialized = $serializer->serialize($data, 'json',
SerializationContext::create()->setGroups($groups));
return new JsonResponse($serialized, $status, array(), true);
}
......
......@@ -5,6 +5,7 @@ namespace PotageBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use JMS\Serializer\Annotation as Serializer;
/**
* Groupe
......@@ -21,6 +22,7 @@ class Groupe
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"readLettres"})
*/
private $id;
......@@ -46,6 +48,7 @@ class Groupe
* @var string
*
* @ORM\Column(name="nom", type="string", length=100)
* @Serializer\Groups({"readLettres"})
*/
private $nom;
......
......@@ -2,7 +2,7 @@
namespace PotageBundle\Entity;
use JMS\Serializer\Annotation\MaxDepth;
use JMS\Serializer\Annotation as Serializer;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
......@@ -22,19 +22,20 @@ class Info
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"readLettres"})
*/
private $id;
/**
* @var int
* @ORM\ManyToMany(targetEntity="PotageBundle\Entity\Lettre", mappedBy="infos")
* @MaxDepth(3)
*/
private $lettres;
/**
* @var string
* @ORM\Column(name="title", type="string", length=150)
* @Serializer\Groups({"readLettres"})
*/
private $title;
......
......@@ -2,9 +2,9 @@
namespace PotageBundle\Entity;
use JMS\Serializer\Annotation\MaxDepth;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/**
* Lettre
......@@ -21,6 +21,7 @@ class Lettre
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"readLettres"})
*/
private $id;
......@@ -28,7 +29,7 @@ class Lettre
* @var int
* @ORM\ManyToOne(targetEntity="PotageBundle\Entity\Offre", inversedBy="lettres")
* @ORM\JoinColumn(name="id_offre", nullable=false)
* @MaxDepth(2)
* @Serializer\Groups({"readLettres"})
*/
private $offre;
......@@ -39,6 +40,7 @@ class Lettre
* joinColumns={@ORM\JoinColumn(name="id_lettre", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="id_info", referencedColumnName="id")}
* )
* @Serializer\Groups({"readLettres"})
*/
private $infos;
......@@ -46,55 +48,63 @@ class Lettre
* @var int
* @ORM\ManyToOne(targetEntity="PotageBundle\Entity\Groupe", inversedBy="lettres")
* @ORM\JoinColumn(name="id_groupe", nullable=false)
* @MaxDepth(2)
* @Serializer\Groups({"readLettres"})
*/
private $groupe;
/**
* @var string
* @ORM\Column(name="reference", type="string", length=16, unique=true)
* @Serializer\Groups({"readLettres"})
*/
private $reference;
/**
* @var string
* @ORM\Column(name="subject", type="string", length=150)
* @Serializer\Groups({"readLettres"})
*/
private $subject;
/**
* @var \DateTime
* @ORM\Column(name="started_at", type="datetime")
* @Serializer\Groups({"readLettres"})
*/
private $startedAt;
/**
* @var \DateTime
* @ORM\Column(name="ended_at", type="datetime")
* @Serializer\Groups({"readLettres"})
*/
private $endedAt;
/**
* @var string
* @ORM\Column(name="status", type="string", columnDefinition="enum('draft', 'current', 'sent', 'closed', 'trash')")
* @Serializer\Groups({"readLettres"})
*/
private $status;
/**
* @var \DateTime
* @ORM\Column(name="created_at", type="datetime")
* @Serializer\Groups({"readLettres"})
*/
private $createdAt;
/**
* @var \DateTime
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
* @Serializer\Groups({"readLettres"})
*/
private $updatedAt;
/**
* @var string
* @ORM\Column(name="sorted", type="string", nullable=true)
* @Serializer\Groups({"readLettres"})
*/
private $sorted;
......
......@@ -2,7 +2,7 @@
namespace PotageBundle\Entity;
use JMS\Serializer\Annotation\MaxDepth;
use JMS\Serializer\Annotation as Serializer;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
......@@ -22,20 +22,19 @@ class Offre
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"readLettres"})
*/
private $id;
/**
* @var OffreLegumes[]
* @ORM\OneToMany(targetEntity="PotageBundle\Entity\OffreLegumes", mappedBy="offre")
* @MaxDepth(2)
*/
private $offreLegumes;
/**
* @var Lettre[]
* @ORM\OneToMany(targetEntity="PotageBundle\Entity\Lettre", mappedBy="offre")
* @MaxDepth(2)
*/
private $lettres;
......@@ -43,6 +42,7 @@ class Offre
* @var string
*
* @ORM\Column(name="reference", type="string", length=16, unique=true)
* @Serializer\Groups({"readLettres"})
*/
private $reference;
......
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