Skip to content

Commit

Permalink
[project-base] repeat order improvements (#2876)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaholesz authored Nov 23, 2023
2 parents f14064e + 34ead70 commit 6d1e819
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,34 @@
namespace Shopsys\FrontendApiBundle\Model\Order;

use Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser;
use Shopsys\FrameworkBundle\Model\Order\Exception\OrderNotFoundException;
use Shopsys\FrameworkBundle\Model\Order\Order;
use Shopsys\FrameworkBundle\Model\Order\OrderFacade;
use Shopsys\FrontendApiBundle\Model\Resolver\Order\Exception\OrderNotFoundUserError;

class OrderFacade
class OrderApiFacade
{
/**
* @param \Shopsys\FrontendApiBundle\Model\Order\OrderRepository $orderRepository
* @param \Shopsys\FrameworkBundle\Model\Order\OrderFacade $orderFacade
*/
public function __construct(protected readonly OrderRepository $orderRepository)
public function __construct(
protected readonly OrderRepository $orderRepository,
protected readonly OrderFacade $orderFacade,
) {
}

/**
* @param string $orderUuid
* @return \Shopsys\FrameworkBundle\Model\Order\Order
*/
public function getByUuid(string $orderUuid): Order
{
try {
return $this->orderFacade->getByUuid($orderUuid);
} catch (OrderNotFoundException) {
throw new OrderNotFoundUserError('Order with UUID \'' . $orderUuid . '\' not found.');
}
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/Model/Order/OrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function __construct(EntityManagerInterface $entityManager)

/**
* @return \Doctrine\ORM\QueryBuilder
* @internal This will be replaced by \Shopsys\FrameworkBundle\Model\Order::getOrderRepository() with visibility set to public
*/
protected function createOrderQueryBuilder()
{
Expand Down
8 changes: 4 additions & 4 deletions src/Model/Resolver/Order/OrderQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Shopsys\FrameworkBundle\Model\Order\Exception\OrderNotFoundException;
use Shopsys\FrameworkBundle\Model\Order\Order;
use Shopsys\FrameworkBundle\Model\Order\OrderFacade;
use Shopsys\FrontendApiBundle\Model\Order\OrderFacade as FrontendApiOrderFacade;
use Shopsys\FrontendApiBundle\Model\Order\OrderApiFacade;
use Shopsys\FrontendApiBundle\Model\Resolver\AbstractQuery;
use Shopsys\FrontendApiBundle\Model\Resolver\Order\Exception\InvalidAccessUserError;
use Shopsys\FrontendApiBundle\Model\Resolver\Order\Exception\OrderNotFoundUserError;
Expand All @@ -21,13 +21,13 @@ class OrderQuery extends AbstractQuery
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CurrentCustomerUser $currentCustomerUser
* @param \Shopsys\FrameworkBundle\Model\Order\OrderFacade $orderFacade
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
* @param \Shopsys\FrontendApiBundle\Model\Order\OrderFacade $frontendApiOrderFacade
* @param \Shopsys\FrontendApiBundle\Model\Order\OrderApiFacade $orderApiFacade
*/
public function __construct(
protected readonly CurrentCustomerUser $currentCustomerUser,
protected readonly OrderFacade $orderFacade,
protected readonly Domain $domain,
protected readonly FrontendApiOrderFacade $frontendApiOrderFacade,
protected readonly OrderApiFacade $orderApiFacade,
) {
}

Expand Down Expand Up @@ -64,6 +64,6 @@ protected function getOrderForCustomerUserByUuid(
CustomerUser $customerUser,
string $uuid,
): Order {
return $this->frontendApiOrderFacade->getByUuidAndCustomerUser($uuid, $customerUser);
return $this->orderApiFacade->getByUuidAndCustomerUser($uuid, $customerUser);
}
}
10 changes: 5 additions & 5 deletions src/Model/Resolver/Order/OrdersQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Overblog\GraphQLBundle\Definition\Argument;
use Overblog\GraphQLBundle\Relay\Connection\Paginator;
use Shopsys\FrameworkBundle\Model\Customer\User\CurrentCustomerUser;
use Shopsys\FrontendApiBundle\Model\Order\OrderFacade;
use Shopsys\FrontendApiBundle\Model\Order\OrderApiFacade;
use Shopsys\FrontendApiBundle\Model\Resolver\AbstractQuery;
use Shopsys\FrontendApiBundle\Model\Token\Exception\InvalidTokenUserMessageException;

Expand All @@ -17,11 +17,11 @@ class OrdersQuery extends AbstractQuery

/**
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CurrentCustomerUser $currentCustomerUser
* @param \Shopsys\FrontendApiBundle\Model\Order\OrderFacade $orderFacade
* @param \Shopsys\FrontendApiBundle\Model\Order\OrderApiFacade $orderApiFacade
*/
public function __construct(
protected readonly CurrentCustomerUser $currentCustomerUser,
protected readonly OrderFacade $orderFacade,
protected readonly OrderApiFacade $orderApiFacade,
) {
}

Expand All @@ -40,10 +40,10 @@ public function ordersQuery(Argument $argument)
}

$paginator = new Paginator(function ($offset, $limit) use ($customerUser) {
return $this->orderFacade->getCustomerUserOrderLimitedList($customerUser, $limit, $offset);
return $this->orderApiFacade->getCustomerUserOrderLimitedList($customerUser, $limit, $offset);
});

return $paginator->auto($argument, $this->orderFacade->getCustomerUserOrderCount($customerUser));
return $paginator->auto($argument, $this->orderApiFacade->getCustomerUserOrderCount($customerUser));
}

/**
Expand Down
31 changes: 31 additions & 0 deletions src/Model/Resolver/Settings/MaxAllowedPaymentTransactionsQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Shopsys\FrontendApiBundle\Model\Resolver\Settings;

use Shopsys\FrameworkBundle\Component\EntityExtension\EntityNameResolver;
use Shopsys\FrameworkBundle\Model\Order\Order;
use Shopsys\FrontendApiBundle\Model\Resolver\AbstractQuery;

class MaxAllowedPaymentTransactionsQuery extends AbstractQuery
{
/**
* @param \Shopsys\FrameworkBundle\Component\EntityExtension\EntityNameResolver $entityNameResolver
*/
public function __construct(
protected readonly EntityNameResolver $entityNameResolver,
) {
}

/**
* @return int
*/
public function maxAllowedPaymentTransactionsQuery(): int
{
/** @var \Shopsys\FrameworkBundle\Model\Order\Order $orderClass */
$orderClass = $this->entityNameResolver->resolve(Order::class);

return $orderClass::MAX_TRANSACTION_COUNT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ SettingsDecorator:
type: "SeoSetting!"
resolve: "@=query('seoSettingsQuery')"
description: "Settings related to SEO"
maxAllowedPaymentTransactions:
type: Int!
resolve: "@=query('maxAllowedPaymentTransactionsQuery')"
description: "Max allowed payment transactions (how many times is user allowed to try the same payment)"

0 comments on commit 6d1e819

Please sign in to comment.