Skip to content

Commit

Permalink
remove FE API only dependencies from framework (#2032)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasLudvik committed Sep 22, 2020
1 parent 52465e9 commit ed95cb0
Show file tree
Hide file tree
Showing 12 changed files with 481 additions and 317 deletions.
68 changes: 0 additions & 68 deletions packages/framework/src/Model/Article/ArticleFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,64 +109,6 @@ public function getOrderedArticlesByDomainIdAndPlacementQueryBuilder($domainId,
return $this->articleRepository->getOrderedArticlesByDomainIdAndPlacementQueryBuilder($domainId, $placement);
}

/**
* @param int $domainId
* @return int
*/
public function getAllVisibleArticlesCountByDomainId(int $domainId): int
{
return $this->articleRepository->getAllVisibleArticlesCountByDomainId($domainId);
}

/**
* @param int $domainId
* @param string $placement
* @return int
*/
public function getAllVisibleArticlesCountByDomainIdAndPlacement(int $domainId, string $placement): int
{
return $this->articleRepository->getAllVisibleArticlesCountByDomainIdAndPlacement($domainId, $placement);
}

/**
* @param int $domainId
* @param int $limit
* @param int $offset
* @return \Shopsys\FrameworkBundle\Model\Article\Article[]
*/
public function getVisibleArticlesListByDomainId(
int $domainId,
int $limit,
int $offset
): array {
return $this->articleRepository->getVisibleListByDomainId(
$domainId,
$limit,
$offset
);
}

/**
* @param int $domainId
* @param string $placement
* @param int $limit
* @param int $offset
* @return \Shopsys\FrameworkBundle\Model\Article\Article[]
*/
public function getVisibleArticlesListByDomainIdAndPlacement(
int $domainId,
string $placement,
int $limit,
int $offset
): array {
return $this->articleRepository->getVisibleListByDomainIdAndPlacement(
$domainId,
$placement,
$limit,
$offset
);
}

/**
* @param \Shopsys\FrameworkBundle\Model\Article\ArticleData $articleData
* @return \Shopsys\FrameworkBundle\Model\Article\Article
Expand Down Expand Up @@ -260,14 +202,4 @@ public function getAvailablePlacementChoices(): array
t('without positioning') => Article::PLACEMENT_NONE,
];
}

/**
* @param int $domainId
* @param string $uuid
* @return \Shopsys\FrameworkBundle\Model\Article\Article
*/
public function getVisibleByDomainIdAndUuid(int $domainId, string $uuid): Article
{
return $this->articleRepository->getVisibleByDomainIdAndUuid($domainId, $uuid);
}
}
93 changes: 0 additions & 93 deletions packages/framework/src/Model/Article/ArticleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use Shopsys\FrameworkBundle\Model\Article\Exception\ArticleNotFoundException;

class ArticleRepository
{
Expand Down Expand Up @@ -96,42 +95,6 @@ public function getVisibleArticlesForPlacement($domainId, $placement)
return $queryBuilder->getQuery()->execute();
}

/**
* @param int $domainId
* @param string $placement
* @param int $limit
* @param int $offset
* @return \Shopsys\FrameworkBundle\Model\Article\Article[]
*/
public function getVisibleListByDomainIdAndPlacement(
int $domainId,
string $placement,
int $limit,
int $offset
): array {
$queryBuilder = $this->getVisibleArticlesByDomainIdAndPlacementSortedByPositionQueryBuilder($domainId, $placement)
->setFirstResult($offset)
->setMaxResults($limit);

return $queryBuilder->getQuery()->execute();
}

/**
* @param int $domainId
* @param string $placement
* @return int
*/
public function getAllVisibleArticlesCountByDomainIdAndPlacement(int $domainId, string $placement): int
{
$queryBuilder = $this->getArticlesByDomainIdQueryBuilder($domainId)
->select('COUNT(a)')
->andWhere('a.hidden = false')
->andWhere('a.placement = :placement')
->setParameter('placement', $placement);

return (int)$queryBuilder->getQuery()->getSingleScalarResult();
}

/**
* @param int $articleId
* @return \Shopsys\FrameworkBundle\Model\Article\Article
Expand Down Expand Up @@ -175,41 +138,6 @@ protected function getAllVisibleQueryBuilder()
->where('a.hidden = false');
}

/**
* @param int $domainId
* @return int
*/
public function getAllVisibleArticlesCountByDomainId($domainId): int
{
$queryBuilder = $this->getArticlesByDomainIdQueryBuilder($domainId)
->select('COUNT(a)')
->andWhere('a.hidden = false');

return (int)$queryBuilder->getQuery()->getSingleScalarResult();
}

/**
* @param int $domainId
* @param int $limit
* @param int $offset
* @return \Shopsys\FrameworkBundle\Model\Article\Article[]
*/
public function getVisibleListByDomainId(
int $domainId,
int $limit,
int $offset
): array {
$queryBuilder = $this->getAllVisibleQueryBuilder()
->andWhere('a.domainId = :domainId')
->setParameter('domainId', $domainId)
->orderBy('a.placement')
->addOrderBy('a.position')
->setFirstResult($offset)
->setMaxResults($limit);

return $queryBuilder->getQuery()->execute();
}

/**
* @param int $domainId
* @return \Shopsys\FrameworkBundle\Model\Article\Article[]
Expand All @@ -235,25 +163,4 @@ protected function getVisibleArticlesByDomainIdAndPlacementSortedByPositionQuery
->orderBy('a.position, a.id');
return $queryBuilder;
}

/**
* @param int $domainId
* @param string $uuid
* @return \Shopsys\FrameworkBundle\Model\Article\Article
*/
public function getVisibleByDomainIdAndUuid(int $domainId, string $uuid): Article
{
$article = $this->getAllVisibleQueryBuilder()
->andWhere('a.domainId = :domainId')
->setParameter('domainId', $domainId)
->andWhere('a.uuid = :uuid')
->setParameter('uuid', $uuid)
->getQuery()->getOneOrNullResult();

if ($article === null) {
$message = 'Article with UUID \'' . $uuid . '\' not found.';
throw new ArticleNotFoundException($message);
}
return $article;
}
}
43 changes: 0 additions & 43 deletions packages/framework/src/Model/Order/OrderFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,29 +427,6 @@ public function getCustomerUserOrderList(CustomerUser $customerUser)
return $this->orderRepository->getCustomerUserOrderList($customerUser);
}

/**
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser $customerUser
* @param int $limit
* @param int $offset
* @return \Shopsys\FrameworkBundle\Model\Order\Order[]
*/
public function getCustomerUserOrderLimitedList(
CustomerUser $customerUser,
int $limit,
int $offset
): array {
return $this->orderRepository->getCustomerUserOrderLimitedList($customerUser, $limit, $offset);
}

/**
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser $customerUser
* @return int
*/
public function getCustomerUserOrderCount(CustomerUser $customerUser): int
{
return $this->orderRepository->getCustomerUserOrderCount($customerUser);
}

/**
* @param string $email
* @param int $domainId
Expand All @@ -469,26 +446,6 @@ public function getById($orderId)
return $this->orderRepository->getById($orderId);
}

/**
* @param string $uuid
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser $customerUser
* @return \Shopsys\FrameworkBundle\Model\Order\Order
*/
public function getByUuidAndCustomerUser(string $uuid, CustomerUser $customerUser): Order
{
return $this->orderRepository->getByUuidAndCustomerUser($uuid, $customerUser);
}

/**
* @param string $uuid
* @param string $urlHash
* @return \Shopsys\FrameworkBundle\Model\Order\Order
*/
public function getByUuidAndUrlHash(string $uuid, string $urlHash): Order
{
return $this->orderRepository->getByUuidAndUrlHash($uuid, $urlHash);
}

/**
* @param string $urlHash
* @param int $domainId
Expand Down
100 changes: 0 additions & 100 deletions packages/framework/src/Model/Order/OrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,34 +93,6 @@ public function findById($id)
->getQuery()->getOneOrNullResult();
}

/**
* @param string $uuid
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser $customerUser
* @return \Shopsys\FrameworkBundle\Model\Order\Order|null
*/
protected function findByUuidAndCustomerUser(string $uuid, CustomerUser $customerUser)
{
return $this->createOrderQueryBuilder()
->andWhere('o.uuid = :uuid')->setParameter(':uuid', $uuid)
->andWhere('o.customerUser = :customerUser')->setParameter(':customerUser', $customerUser)
->setMaxResults(1)
->getQuery()->getOneOrNullResult();
}

/**
* @param string $uuid
* @param string $urlHash
* @return \Shopsys\FrameworkBundle\Model\Order\Order|null
*/
protected function findByUuidAndUrlHash(string $uuid, string $urlHash)
{
return $this->createOrderQueryBuilder()
->andWhere('o.uuid = :uuid')->setParameter(':uuid', $uuid)
->andWhere('o.urlHash = :urlHash')->setParameter(':urlHash', $urlHash)
->setMaxResults(1)
->getQuery()->getOneOrNullResult();
}

/**
* @param int $id
* @return \Shopsys\FrameworkBundle\Model\Order\Order
Expand All @@ -136,44 +108,6 @@ public function getById($id)
return $order;
}

/**
* @param string $uuid
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser $customerUser
* @return \Shopsys\FrameworkBundle\Model\Order\Order
*/
public function getByUuidAndCustomerUser(string $uuid, CustomerUser $customerUser): Order
{
$order = $this->findByUuidAndCustomerUser($uuid, $customerUser);

if ($order === null) {
throw new \Shopsys\FrameworkBundle\Model\Order\Exception\OrderNotFoundException(sprintf(
'Order with UUID \'%s\' not found.',
$uuid
));
}

return $order;
}

/**
* @param string $uuid
* @param string $urlHash
* @return \Shopsys\FrameworkBundle\Model\Order\Order
*/
public function getByUuidAndUrlHash(string $uuid, string $urlHash): Order
{
$order = $this->findByUuidAndUrlHash($uuid, $urlHash);

if ($order === null) {
throw new \Shopsys\FrameworkBundle\Model\Order\Exception\OrderNotFoundException(sprintf(
'Order with UUID \'%s\' not found.',
$uuid
));
}

return $order;
}

/**
* @param \Shopsys\FrameworkBundle\Model\Order\Status\OrderStatus $orderStatus
* @return bool
Expand Down Expand Up @@ -243,40 +177,6 @@ public function getCustomerUserOrderList(CustomerUser $customerUser)
->getQuery()->execute();
}

/**
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser $customerUser
* @param int $limit
* @param int $offset
* @return \Shopsys\FrameworkBundle\Model\Order\Order[]
*/
public function getCustomerUserOrderLimitedList(CustomerUser $customerUser, int $limit, int $offset): array
{
return $this->createOrderQueryBuilder()
->andWhere('o.customerUser = :customerUser')
->setParameter('customerUser', $customerUser)
->orderBy('o.createdAt', 'DESC')
->setFirstResult($offset)
->setMaxResults($limit)
->getQuery()
->execute();
}

/**
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser $customerUser
* @return int
*/
public function getCustomerUserOrderCount(CustomerUser $customerUser): int
{
return $this->em->createQueryBuilder()
->select('count(o.id)')
->from(Order::class, 'o')
->where('o.deleted = FALSE')
->andWhere('o.customerUser = :customerUser')
->setParameter('customerUser', $customerUser)
->getQuery()
->getSingleScalarResult();
}

/**
* @param string $email
* @param int $domainId
Expand Down
Loading

0 comments on commit ed95cb0

Please sign in to comment.