Browse Source

Refactoring services

feature/symfony6.1
Guillaume 3 years ago
parent
commit
45e92852ce
4 changed files with 16 additions and 31 deletions
  1. +7
    -6
      Repository/AbstractRepositoryQuery.php
  2. +5
    -21
      Repository/AbstractStore.php
  3. +3
    -2
      Repository/Ticket/TicketStore.php
  4. +1
    -2
      Repository/User/UserStore.php

+ 7
- 6
Repository/AbstractRepositoryQuery.php View File

@@ -5,6 +5,9 @@ namespace Lc\SovBundle\Repository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\QueryBuilder;
use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Doctrine\EntityInterface;

abstract class AbstractRepositoryQuery
{
@@ -52,14 +55,14 @@ abstract class AbstractRepositoryQuery
public function count(): string
{
return $this->query->getQuery()
->getSingleScalarResult();
->getSingleScalarResult();
}

public function findOne()
public function findOne(): ?EntityInterface
{
return $this->query->getQuery()
->setMaxResults(1)
->getOneOrNullResult();
->setMaxResults(1)
->getOneOrNullResult();
}

public function find(): array
@@ -133,7 +136,5 @@ abstract class AbstractRepositoryQuery
->setParameter('slug', $slug);
}



}


+ 5
- 21
Repository/AbstractStore.php View File

@@ -6,9 +6,12 @@ use Lc\SovBundle\Model\Site\PageInterface;

abstract class AbstractStore
{
public function createQuery()
public function createQuery($query = null)
{
return $this->query->create();
if (is_null($query)) {
$query = $this->query->create();
}
return $query;
}

public function getRepositoryQuery()
@@ -24,23 +27,4 @@ abstract class AbstractStore

return $query->findOne();
}

public function getOneByDevAlias(string $devAlias)
{
$query = $this->query->create();

$query->filterByDevAlias($devAlias);

return $query->findOne();
}

//findPageBySlug
public function getOneBySlug(string $slug): ?PageInterface
{
$query = $this->query->create();
$query->filterBySlug($slug);

return $query->findOne();
}

}

+ 3
- 2
Repository/Ticket/TicketStore.php View File

@@ -4,6 +4,7 @@ namespace Lc\SovBundle\Repository\Ticket;

use App\Entity\Ticket\Ticket;
use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractStore;

class TicketStore extends AbstractStore implements TicketStoreInterface
@@ -16,10 +17,10 @@ class TicketStore extends AbstractStore implements TicketStoreInterface
}

// getTicketsByUser
public function getByUser($user, $query = null): array
public function getByUser(UserInterface $user, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
$query = $this->createQuery();
}

$query->filterByUser($user);

+ 1
- 2
Repository/User/UserStore.php View File

@@ -21,8 +21,7 @@ class UserStore extends AbstractStore implements UserStoreInterface
$query = $this->query->create();
}

$query
->filterByNewsletter($newsletter);
$query->filterByNewsletter($newsletter);

return $query->find();
}

Loading…
Cancel
Save