Repositories refactoring. TopUserDTO moved.

This commit is contained in:
Alexey Skobkin 2016-03-23 19:59:06 +03:00
parent 8f44a04989
commit 0f0700f87b
12 changed files with 18 additions and 13 deletions

View file

@ -3,7 +3,7 @@
namespace Skobkin\Bundle\PointToolsBundle\Controller; namespace Skobkin\Bundle\PointToolsBundle\Controller;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Skobkin\Bundle\PointToolsBundle\Entity\TopUserDTO; use Skobkin\Bundle\PointToolsBundle\DTO\TopUserDTO;
use Skobkin\Bundle\PointToolsBundle\Entity\User; use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Skobkin\Bundle\PointToolsBundle\Service\UserApi; use Skobkin\Bundle\PointToolsBundle\Service\UserApi;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Skobkin\Bundle\PointToolsBundle\Entity; namespace Skobkin\Bundle\PointToolsBundle\DTO;
/** /**
* Data Transfer Object for top users list * Data Transfer Object for top users list

View file

@ -14,7 +14,7 @@ use Symfony\Component\Serializer\Annotation as Serializer;
* @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\Index(name="idx_post_private", columns={"private"}),
* }) * })
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\PostRepository") * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository")
*/ */
class Post class Post
{ {

View file

@ -11,7 +11,7 @@ use Symfony\Component\Serializer\Annotation as Serializer;
* @ORM\Table(name="posts.tags", schema="posts", indexes={ * @ORM\Table(name="posts.tags", schema="posts", indexes={
* @ORM\Index(name="idx_tag_text", columns={"text"}) * @ORM\Index(name="idx_tag_text", columns={"text"})
* }) * })
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\TagRepository") * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\TagRepository")
*/ */
class Tag class Tag
{ {

View file

@ -10,7 +10,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Table(name="subscriptions.subscriptions", schema="subscriptions", uniqueConstraints={ * @ORM\Table(name="subscriptions.subscriptions", schema="subscriptions", uniqueConstraints={
* @ORM\UniqueConstraint(name="subscription_unique", columns={"author_id", "subscriber_id"})} * @ORM\UniqueConstraint(name="subscription_unique", columns={"author_id", "subscriber_id"})}
* ) * )
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionRepository") * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionRepository")
*/ */
class Subscription class Subscription
{ {

View file

@ -12,7 +12,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Index(name="subscriber_idx", columns={"subscriber_id"}), * @ORM\Index(name="subscriber_idx", columns={"subscriber_id"}),
* @ORM\Index(name="date_idx", columns={"date"}) * @ORM\Index(name="date_idx", columns={"date"})
* }) * })
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEventRepository") * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository")
* @ORM\HasLifecycleCallbacks * @ORM\HasLifecycleCallbacks
*/ */
class SubscriptionEvent class SubscriptionEvent

View file

@ -9,7 +9,7 @@ use Doctrine\ORM\Mapping as ORM;
* User * User
* *
* @ORM\Table(name="users.users", schema="users") * @ORM\Table(name="users.users", schema="users")
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Entity\UserRepository") * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\UserRepository")
* @ORM\HasLifecycleCallbacks * @ORM\HasLifecycleCallbacks
*/ */
class User class User

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs; namespace Skobkin\Bundle\PointToolsBundle\Repository\Blogs;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;

View file

@ -1,8 +1,9 @@
<?php <?php
namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs; namespace Skobkin\Bundle\PointToolsBundle\Repository\Blogs;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag;
class TagRepository extends EntityRepository class TagRepository extends EntityRepository
{ {

View file

@ -1,9 +1,11 @@
<?php <?php
namespace Skobkin\Bundle\PointToolsBundle\Entity; namespace Skobkin\Bundle\PointToolsBundle\Repository;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent;
use Skobkin\Bundle\PointToolsBundle\Entity\User;
class SubscriptionEventRepository extends EntityRepository class SubscriptionEventRepository extends EntityRepository
{ {

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Skobkin\Bundle\PointToolsBundle\Entity; namespace Skobkin\Bundle\PointToolsBundle\Repository;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;

View file

@ -1,8 +1,10 @@
<?php <?php
namespace Skobkin\Bundle\PointToolsBundle\Entity; namespace Skobkin\Bundle\PointToolsBundle\Repository;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Skobkin\Bundle\PointToolsBundle\DTO\TopUserDTO;
use Skobkin\Bundle\PointToolsBundle\Entity\User;
class UserRepository extends EntityRepository class UserRepository extends EntityRepository
{ {
@ -71,7 +73,7 @@ class UserRepository extends EntityRepository
$qb = $this->getEntityManager()->getRepository('SkobkinPointToolsBundle:Subscription')->createQueryBuilder('s'); $qb = $this->getEntityManager()->getRepository('SkobkinPointToolsBundle:Subscription')->createQueryBuilder('s');
return $qb return $qb
->select(['COUNT(s.subscriber) as cnt', 'NEW SkobkinPointToolsBundle:TopUserDTO(a.login, COUNT(s.subscriber))']) ->select(['COUNT(s.subscriber) as cnt', 'NEW Skobkin\Bundle\PointToolsBundle\DTO\TopUserDTO(a.login, COUNT(s.subscriber))'])
->innerJoin('s.author', 'a') ->innerJoin('s.author', 'a')
->orderBy('cnt', 'desc') ->orderBy('cnt', 'desc')
->groupBy('a.id') ->groupBy('a.id')