From ae8cbde3e1647bc80f56b831fb9a4f5fc23453ef Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Wed, 16 Mar 2016 22:03:08 +0300 Subject: [PATCH 1/3] Post entity update. PostRepository and TagRepository created. --- .../PointToolsBundle/Entity/Blogs/Post.php | 52 +++++++++++++++++-- .../Entity/Blogs/PostRepository.php | 10 ++++ .../PointToolsBundle/Entity/Blogs/Tag.php | 2 +- .../Entity/Blogs/TagRepository.php | 26 ++++++++++ 4 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/PostRepository.php create mode 100644 src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/TagRepository.php diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php index f472dbd..60a955d 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php @@ -10,14 +10,18 @@ use Skobkin\Bundle\PointToolsBundle\Entity\User; * Post * * @ORM\Table(name="posts.posts", schema="posts", indexes={ - * @ORM\Index(name="idx_post_created_at", columns={"created_at"}) + * @ORM\Index(name="idx_post_created_at", columns={"created_at"}), + * @ORM\Index(name="idx_post_private", columns={"private"}), * }) - * @ORM\Entity + * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\PostRepository") */ class Post { + const TYPE_POST = 'post'; + const TYPE_FEED = 'feed'; + /** - * @var integer + * @var int * * @ORM\Column(name="id", type="string", length=16) * @ORM\Id @@ -45,6 +49,13 @@ class Post */ private $type; + /** + * @var bool + * + * @ORM\Column(name="private", type="boolean", nullable=true) + */ + private $private; + /** * @var bool * @@ -77,10 +88,20 @@ class Post private $comments; - public function __construct($id, $type, $text, \DateTime $createdAt, User $author = null) + /** + * Post constructor. + * @param string $id + * @param string $type + * @param bool $private + * @param string $text + * @param \DateTime $createdAt + * @param User|null $author + */ + public function __construct($id, $type, $private, $text, \DateTime $createdAt, User $author = null) { $this->id = $id; $this->type = $type; + $this->private = $private; $this->createdAt = $createdAt; $this->text = $text; $this->author = $author; @@ -251,4 +272,27 @@ class Post { return $this->deleted; } + + /** + * Set private + * + * @param boolean $private + * @return Post + */ + public function setPrivate($private) + { + $this->private = $private; + + return $this; + } + + /** + * Get private + * + * @return boolean + */ + public function getPrivate() + { + return $this->private; + } } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/PostRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/PostRepository.php new file mode 100644 index 0000000..14429bc --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/PostRepository.php @@ -0,0 +1,10 @@ +createQueryBuilder('t'); + return $qb + ->where($qb->expr()->eq( + $qb->expr()->lower('t.text'), + $qb->expr()->lower(':text') + )) + ->setParameter('text', $text) + ->getQuery()->getOneOrNullResult() + ; + } +} \ No newline at end of file From c1e01c473891378c67baaf57d7d2eb3679414957 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Wed, 16 Mar 2016 23:08:48 +0300 Subject: [PATCH 2/3] Symfony Serializer enabled. Serializer groups added to Post, Tag and Comment. --- app/config/config.yml | 3 +++ .../PointToolsBundle/Entity/Blogs/Comment.php | 17 ++++++++++++++++- .../PointToolsBundle/Entity/Blogs/Post.php | 17 +++++++++++++++++ .../PointToolsBundle/Entity/Blogs/Tag.php | 3 +++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/app/config/config.yml b/app/config/config.yml index 9cb2514..b502b3e 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -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" diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php index 119794d..7d3836b 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php @@ -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) */ diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php index 60a955d..01ffc19 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php @@ -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; diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Tag.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Tag.php index 302e37e..0cd1b56 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Tag.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Tag.php @@ -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; From 057481b808d01164329f8f5c421cbd38945ca971 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Wed, 16 Mar 2016 23:55:41 +0300 Subject: [PATCH 3/3] DTO's for crawler. Test implementation. Not tested. --- .../DTO/Api/Crawler/MetaPost.php | 59 ++++++ .../PointToolsBundle/DTO/Api/Crawler/Post.php | 184 ++++++++++++++++++ .../DTO/Api/Crawler/PostsPage.php | 35 ++++ .../DTO/Api/Crawler/Recommendation.php | 84 ++++++++ .../PointToolsBundle/DTO/Api/Crawler/User.php | 84 ++++++++ 5 files changed, 446 insertions(+) create mode 100644 src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/MetaPost.php create mode 100644 src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/Post.php create mode 100644 src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/PostsPage.php create mode 100644 src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/Recommendation.php create mode 100644 src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/User.php diff --git a/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/MetaPost.php b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/MetaPost.php new file mode 100644 index 0000000..c885785 --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/MetaPost.php @@ -0,0 +1,59 @@ +rec; + } + + /** + * @param Recommendation $rec + * @return MetaPost + */ + public function setRec(Recommendation $rec) + { + $this->rec = $rec; + return $this; + } + + /** + * @return Post + */ + public function getPost() + { + return $this->post; + } + + /** + * @param Post $post + * @return MetaPost + */ + public function setPost(Post $post) + { + $this->post = $post; + return $this; + } +} \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/Post.php b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/Post.php new file mode 100644 index 0000000..cd7fd8b --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/Post.php @@ -0,0 +1,184 @@ +id; + } + + /** + * @param string $id + * @return Post + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return string[] + */ + public function getTags() + { + return $this->tags; + } + + /** + * @param string[] $tags + * @return Post + */ + public function setTags(array $tags) + { + $this->tags = $tags; + return $this; + } + + /** + * @return User + */ + public function getAuthor() + { + return $this->author; + } + + /** + * @param User $author + * @return Post + */ + public function setAuthor(User $author) + { + $this->author = $author; + return $this; + } + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @param string $text + * @return Post + */ + public function setText($text) + { + $this->text = $text; + return $this; + } + + /** + * @return string + */ + public function getCreated() + { + return $this->created; + } + + /** + * @param string $created + * @return Post + */ + public function setCreated($created) + { + $this->created = $created; + return $this; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + * @return Post + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + + /** + * @return boolean + */ + public function isPrivate() + { + return $this->private; + } + + /** + * @param boolean $private + * @return Post + */ + public function setPrivate($private) + { + $this->private = $private; + return $this; + } +} \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/PostsPage.php b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/PostsPage.php new file mode 100644 index 0000000..6096bd6 --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/PostsPage.php @@ -0,0 +1,35 @@ +posts; + } + + /** + * @param MetaPost[] $posts + * @return PostsPage + */ + public function setPosts(array $posts) + { + $this->posts = $posts; + return $this; + } + + +} \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/Recommendation.php b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/Recommendation.php new file mode 100644 index 0000000..087cc01 --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/Recommendation.php @@ -0,0 +1,84 @@ +text; + } + + /** + * @param string $text + * @return Recommendation + */ + public function setText($text) + { + $this->text = $text; + return $this; + } + + /** + * @return int|null + */ + public function getComment_id() + { + return $this->comment_id; + } + + /** + * @param int|null $comment_id + * @return Recommendation + */ + public function setComment_id($comment_id) + { + $this->comment_id = $comment_id; + return $this; + } + + /** + * @return User + */ + public function getAuthor() + { + return $this->author; + } + + /** + * @param User $author + * @return Recommendation + */ + public function setAuthor(User $author) + { + $this->author = $author; + return $this; + } +} \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/User.php b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/User.php new file mode 100644 index 0000000..e70bb0a --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/User.php @@ -0,0 +1,84 @@ +id; + } + + /** + * @param string $id + * @return User + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getLogin() + { + return $this->login; + } + + /** + * @param string $login + * @return User + */ + public function setLogin($login) + { + $this->login = $login; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * @return User + */ + public function setName($name) + { + $this->name = $name; + return $this; + } +} \ No newline at end of file