Symfony Serializer enabled. Serializer groups added to Post, Tag and Comment.

This commit is contained in:
Alexey Skobkin 2016-03-16 23:08:48 +03:00
parent ae8cbde3e1
commit c1e01c4738
4 changed files with 39 additions and 1 deletions

View file

@ -6,6 +6,9 @@ imports:
framework:
#esi: ~
translator: { fallbacks: ["%locale%"] }
serializer:
#enabled: true
enable_annotations: true
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"

View file

@ -4,6 +4,7 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\Mapping as ORM;
use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* Comment
@ -18,6 +19,8 @@ class Comment
/**
* @var integer
*
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
*/
@ -26,6 +29,8 @@ class Comment
/**
* @var string
*
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="text", type="text")
*/
private $text;
@ -33,6 +38,8 @@ class Comment
/**
* @var \DateTime
*
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
@ -40,6 +47,8 @@ class Comment
/**
* @var boolean
*
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="is_rec", type="boolean")
*/
private $rec;
@ -47,6 +56,8 @@ class Comment
/**
* @var bool
*
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="is_deleted", type="boolean")
*/
private $deleted = false;
@ -55,7 +66,7 @@ class Comment
* @var Post
*
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post")
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post", inversedBy="comments")
* @ORM\JoinColumn(name="post_id")
*/
private $post;
@ -63,6 +74,8 @@ class Comment
/**
* @var User
*
* @Serializer\Groups("post_show")
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
* @ORM\JoinColumn(name="author_id")
*/
@ -71,6 +84,8 @@ class Comment
/**
* @var Comment|null
*
* @Serializer\Groups("post_show")
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment")
* @ORM\JoinColumn(name="to_comment_id", nullable=true)
*/

View file

@ -5,6 +5,7 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* Post
@ -23,6 +24,8 @@ class Post
/**
* @var int
*
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="id", type="string", length=16)
* @ORM\Id
*/
@ -31,6 +34,8 @@ class Post
/**
* @var string
*
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="text", type="text")
*/
private $text;
@ -38,6 +43,8 @@ class Post
/**
* @var \DateTime
*
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
@ -45,6 +52,8 @@ class Post
/**
* @var string
*
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="type", type="string", length=6)
*/
private $type;
@ -66,6 +75,8 @@ class Post
/**
* @var User
*
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
* @ORM\JoinColumn(name="author")
*/
@ -74,6 +85,8 @@ class Post
/**
* @var Tag[]|ArrayCollection
*
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\ManyToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag", fetch="EXTRA_LAZY")
* @ORM\JoinTable(name="posts.posts_tags",
* joinColumns={@ORM\JoinColumn(name="post_id")},
@ -84,6 +97,10 @@ class Post
/**
* @var Comment[]|ArrayCollection
*
* @Serializer\Groups({"post_show"})
*
* @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", mappedBy="post")
*/
private $comments;

View file

@ -3,6 +3,7 @@
namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* Tag
@ -26,6 +27,8 @@ class Tag
/**
* @var string
*
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="text", type="text", unique=true)
*/
private $text;