Skip to content

Commit

Permalink
Replaced: /orders -> /shipments
Browse files Browse the repository at this point in the history
  • Loading branch information
igormukhingmailcom committed Mar 10, 2020
1 parent 79fb765 commit a69028e
Show file tree
Hide file tree
Showing 23 changed files with 333 additions and 304 deletions.
6 changes: 5 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ indent_size = 4

[phpunit.xml{,.dist}]
indent_style = space
indent_size = 4
indent_size = 4

[tests/Responses/Expected/**/*.json]
indent_style = space
indent_size = 4
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ imports:

Like it was done at:

- [tests/Application/Entity](tests/Application/Entity)
- [tests/Application/Repository](tests/Application/Repository)
- [tests/Application/config/packages/_sylius.yaml](tests/Application/config/packages/_sylius.yaml)

Expand Down Expand Up @@ -128,10 +129,10 @@ curl "$SYLIUS_HOST/api/lagersystem/product-variants/$SYLIUS_SOME_PRODUCT_VARIANT
-H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
```

### Order list enpoint
### Shipments list enpoint

```bash
curl "$SYLIUS_HOST/api/lagersystem/orders?limit=3" \
curl "$SYLIUS_HOST/api/lagersystem/shipments?locale=en_US&limit=3" \
-H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,36 @@

declare(strict_types=1);

namespace Setono\SyliusLagersystemPlugin\Controller\Order;
namespace Setono\SyliusLagersystemPlugin\Controller\Shipment;

use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Setono\SyliusLagersystemPlugin\Model\PaginatorDetails;
use Setono\SyliusLagersystemPlugin\ViewRepository\Order\OrderViewRepositoryInterface;
use Setono\SyliusLagersystemPlugin\ViewRepository\Shipment\ShipmentViewRepositoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

final class OrderIndexAction
final class ShipmentIndexAction
{
/** @var ViewHandlerInterface */
private $viewHandler;

/** @var OrderViewRepositoryInterface */
private $orderViewRepository;
/** @var ShipmentViewRepositoryInterface */
private $shipmentViewRepository;

public function __construct(
ViewHandlerInterface $viewHandler,
OrderViewRepositoryInterface $orderViewRepository
ShipmentViewRepositoryInterface $shipmentViewRepository
) {
$this->viewHandler = $viewHandler;
$this->orderViewRepository = $orderViewRepository;
$this->shipmentViewRepository = $shipmentViewRepository;
}

public function __invoke(Request $request): Response
{
$page = $this->orderViewRepository->getAllPaginated(
new PaginatorDetails($request->attributes->get('_route'), $request->query->all())
$page = $this->shipmentViewRepository->getAllPaginated(
new PaginatorDetails($request->attributes->get('_route'), $request->query->all()),
$request->query->get('locale')
);

return $this->viewHandler->handle(
Expand Down
12 changes: 0 additions & 12 deletions src/Factory/Order/OrderViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
use Setono\SyliusLagersystemPlugin\Factory\Address\AddressViewFactoryInterface;
use Setono\SyliusLagersystemPlugin\Factory\Customer\CustomerViewFactoryInterface;
use Setono\SyliusLagersystemPlugin\Factory\PaymentViewFactoryInterface;
use Setono\SyliusLagersystemPlugin\Factory\ShipmentViewFactoryInterface;
use Setono\SyliusLagersystemPlugin\View\Order\OrderView;
use Sylius\Component\Core\Model\AdjustmentInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\Model\ShipmentInterface;
use Webmozart\Assert\Assert;

class OrderViewFactory implements OrderViewFactoryInterface
Expand All @@ -25,9 +23,6 @@ class OrderViewFactory implements OrderViewFactoryInterface
/** @var AddressViewFactoryInterface */
protected $addressViewFactory;

/** @var ShipmentViewFactoryInterface */
protected $shipmentViewFactory;

/** @var PaymentViewFactoryInterface */
protected $paymentViewFactory;

Expand All @@ -43,15 +38,13 @@ class OrderViewFactory implements OrderViewFactoryInterface
public function __construct(
CustomerViewFactoryInterface $customerViewFactory,
AddressViewFactoryInterface $addressViewFactory,
ShipmentViewFactoryInterface $shipmentViewFactory,
PaymentViewFactoryInterface $paymentViewFactory,
AdjustmentViewFactoryInterface $adjustmentViewFactory,
ItemViewFactoryInterface $itemFactory,
string $orderViewClass
) {
$this->customerViewFactory = $customerViewFactory;
$this->addressViewFactory = $addressViewFactory;
$this->shipmentViewFactory = $shipmentViewFactory;
$this->paymentViewFactory = $paymentViewFactory;
$this->adjustmentViewFactory = $adjustmentViewFactory;
$this->itemFactory = $itemFactory;
Expand Down Expand Up @@ -97,11 +90,6 @@ public function create(OrderInterface $order): OrderView
);
}

/** @var ShipmentInterface $shipment */
foreach ($order->getShipments() as $shipment) {
$orderView->shipments[] = $this->shipmentViewFactory->create($shipment, $localeCode);
}

/** @var PaymentInterface $payment */
foreach ($order->getPayments() as $payment) {
$orderView->payments[] = $this->paymentViewFactory->create($payment, $localeCode);
Expand Down
12 changes: 11 additions & 1 deletion src/Factory/ShipmentViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,45 @@

namespace Setono\SyliusLagersystemPlugin\Factory;

use Setono\SyliusLagersystemPlugin\Factory\Order\OrderViewFactoryInterface;
use Setono\SyliusLagersystemPlugin\View\ShipmentView;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\ShipmentInterface;
use Webmozart\Assert\Assert;

class ShipmentViewFactory implements ShipmentViewFactoryInterface
{
/** @var ShippingMethodViewFactoryInterface */
protected $shippingMethodViewFactory;

/** @var OrderViewFactoryInterface */
protected $orderViewFactory;

/** @var string */
protected $shipmentViewClass;

public function __construct(
ShippingMethodViewFactoryInterface $shippingMethodViewFactory,
OrderViewFactoryInterface $orderViewFactory,
string $shipmentViewClass
) {
$this->shippingMethodViewFactory = $shippingMethodViewFactory;
$this->orderViewFactory = $orderViewFactory;
$this->shipmentViewClass = $shipmentViewClass;
}

public function create(ShipmentInterface $shipment, string $locale): ShipmentView
{
/** @var OrderInterface $order */
/** @var OrderInterface|null $order */
$order = $shipment->getOrder();
Assert::notNull($order);

/** @var ShipmentView $shipmentView */
$shipmentView = new $this->shipmentViewClass();
$shipmentView->id = $shipment->getId();
$shipmentView->state = $shipment->getState();
$shipmentView->method = $this->shippingMethodViewFactory->create($shipment, $locale);
$shipmentView->order = $this->orderViewFactory->create($order);

return $shipmentView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Setono\SyliusLagersystemPlugin\Repository;

use Doctrine\ORM\QueryBuilder;
use Sylius\Component\Core\Repository\OrderRepositoryInterface as BaseOrderRepositoryInterface;
use Sylius\Component\Core\Repository\ShipmentRepositoryInterface as BaseShipmentRepositoryInterface;

interface OrderRepositoryInterface extends BaseOrderRepositoryInterface
interface ShipmentRepositoryInterface extends BaseShipmentRepositoryInterface
{
public function createLagersystemListQueryBuilder(): QueryBuilder;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Sylius\Component\Core\OrderPaymentStates;
use Sylius\Component\Core\OrderShippingStates;

trait OrderRepositoryTrait
trait ShipmentRepositoryTrait
{
/**
* @param string $alias
Expand All @@ -21,7 +21,9 @@ abstract public function createQueryBuilder($alias, $indexBy = null);

public function createLagersystemListQueryBuilder(): QueryBuilder
{
return $this->createQueryBuilder('o')
return $this->createQueryBuilder('shipment')
->join('shipment.order', 'o')

->andWhere('o.checkoutState in (:checkoutStates)')
->setParameter('checkoutStates', [
OrderCheckoutStates::STATE_COMPLETED,
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/config/routing/api.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
setono_sylius_lagersystem_api_order_index:
path: /orders
setono_sylius_lagersystem_api_shipment_index:
path: /shipments
methods: [GET]
defaults:
_controller: setono_sylius_lagersystem.controller.order.order_index_action
_controller: setono_sylius_lagersystem.controller.shipment.shipment_index_action

setono_sylius_lagersystem_api_product_variant_index:
path: /product-variants
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/config/services/actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<services>
<defaults public="true" />

<service id="setono_sylius_lagersystem.controller.order.order_index_action"
class="Setono\SyliusLagersystemPlugin\Controller\Order\OrderIndexAction">
<service id="setono_sylius_lagersystem.controller.shipment.shipment_index_action"
class="Setono\SyliusLagersystemPlugin\Controller\Shipment\ShipmentIndexAction">
<argument type="service" id="fos_rest.view_handler" />
<argument type="service" id="setono_sylius_lagersystem.view_repository.order_view_repository" />
<argument type="service" id="setono_sylius_lagersystem.view_repository.shipment_view_repository" />
</service>

<service id="setono_sylius_lagersystem.controller.product.product_variant_index_action"
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services/factories.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<service id="setono_sylius_lagersystem.factory.shipment_view_factory"
class="Setono\SyliusLagersystemPlugin\Factory\ShipmentViewFactory">
<argument type="service" id="setono_sylius_lagersystem.factory.shipping_method_view_factory"/>
<argument type="service" id="setono_sylius_lagersystem.factory.order_view_factory"/>
<argument type="string">%setono_sylius_lagersystem.view.shipment.class%</argument>
</service>

Expand All @@ -46,7 +47,6 @@
class="Setono\SyliusLagersystemPlugin\Factory\Order\OrderViewFactory">
<argument type="service" id="setono_sylius_lagersystem.factory.customer_view_factory"/>
<argument type="service" id="setono_sylius_lagersystem.factory.address_view_factory"/>
<argument type="service" id="setono_sylius_lagersystem.factory.shipment_view_factory"/>
<argument type="service" id="setono_sylius_lagersystem.factory.payment_view_factory"/>
<argument type="service" id="setono_sylius_lagersystem.factory.adjustment_view_factory"/>
<argument type="service" id="setono_sylius_lagersystem.factory.item_view_factory"/>
Expand Down
8 changes: 4 additions & 4 deletions src/Resources/config/services/repositories.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<container xmlns="http://symfony.com/schema/dic/services">
<services>

<service id="setono_sylius_lagersystem.view_repository.order_view_repository"
class="Setono\SyliusLagersystemPlugin\ViewRepository\Order\OrderViewRepository">
<argument type="service" id="sylius.repository.order" />
<service id="setono_sylius_lagersystem.view_repository.shipment_view_repository"
class="Setono\SyliusLagersystemPlugin\ViewRepository\Shipment\ShipmentViewRepository">
<argument type="service" id="sylius.repository.shipment" />
<argument type="service" id="setono_sylius_lagersystem.factory.page_view_factory" />
<argument type="service" id="setono_sylius_lagersystem.factory.order_view_factory" />
<argument type="service" id="setono_sylius_lagersystem.factory.shipment_view_factory" />
</service>

<service id="setono_sylius_lagersystem.view_repository.product_variant_view_repository"
Expand Down
4 changes: 0 additions & 4 deletions src/View/Order/OrderView.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Setono\SyliusLagersystemPlugin\View\AddressView;
use Setono\SyliusLagersystemPlugin\View\Customer\CustomerView;
use Setono\SyliusLagersystemPlugin\View\PaymentView;
use Setono\SyliusLagersystemPlugin\View\ShipmentView;

class OrderView
{
Expand Down Expand Up @@ -44,9 +43,6 @@ class OrderView
/** @var string|null */
public $shippingState;

/** @var array|ShipmentView[] */
public $shipments = [];

/** @var AddressView */
public $shippingAddress;

Expand Down
8 changes: 8 additions & 0 deletions src/View/ShipmentView.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@

namespace Setono\SyliusLagersystemPlugin\View;

use Setono\SyliusLagersystemPlugin\View\Order\OrderView;

class ShipmentView
{
/** @var int|null */
public $id;

/** @var string|null */
public $state;

/** @var ShippingMethodView|null */
public $method;

/** @var OrderView|null */
public $order;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,50 @@

declare(strict_types=1);

namespace Setono\SyliusLagersystemPlugin\ViewRepository\Order;
namespace Setono\SyliusLagersystemPlugin\ViewRepository\Shipment;

use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Pagerfanta;
use Setono\SyliusLagersystemPlugin\Factory\Order\OrderViewFactoryInterface;
use Setono\SyliusLagersystemPlugin\Factory\PageViewFactoryInterface;
use Setono\SyliusLagersystemPlugin\Factory\ShipmentViewFactoryInterface;
use Setono\SyliusLagersystemPlugin\Model\PaginatorDetails;
use Setono\SyliusLagersystemPlugin\Repository\OrderRepositoryInterface;
use Setono\SyliusLagersystemPlugin\Repository\ShipmentRepositoryInterface;
use Setono\SyliusLagersystemPlugin\View\PageView;
use Webmozart\Assert\Assert;

class OrderViewRepository implements OrderViewRepositoryInterface
class ShipmentViewRepository implements ShipmentViewRepositoryInterface
{
/** @var OrderRepositoryInterface */
protected $orderRepository;
/** @var ShipmentRepositoryInterface */
protected $shipmentRepository;

/** @var PageViewFactoryInterface */
protected $pageViewFactory;

/** @var OrderViewFactoryInterface */
protected $orderViewFactory;
/** @var ShipmentViewFactoryInterface */
protected $shipmentViewFactory;

public function __construct(
OrderRepositoryInterface $orderRepository,
ShipmentRepositoryInterface $shipmentRepository,
PageViewFactoryInterface $pageViewFactory,
OrderViewFactoryInterface $orderViewFactory
ShipmentViewFactoryInterface $shipmentViewFactory
) {
$this->orderRepository = $orderRepository;
$this->shipmentRepository = $shipmentRepository;
$this->pageViewFactory = $pageViewFactory;
$this->orderViewFactory = $orderViewFactory;
$this->shipmentViewFactory = $shipmentViewFactory;
}

public function getAllPaginated(PaginatorDetails $paginatorDetails): PageView
public function getAllPaginated(PaginatorDetails $paginatorDetails, ?string $localeCode): PageView
{
$queryBuilder = $this->orderRepository->createLagersystemListQueryBuilder();
Assert::notNull($localeCode);
$queryBuilder = $this->shipmentRepository->createLagersystemListQueryBuilder();

$pagerfanta = new Pagerfanta(new DoctrineORMAdapter($queryBuilder));
$pagerfanta->setMaxPerPage($paginatorDetails->limit());
$pagerfanta->setCurrentPage($paginatorDetails->page());

$pageView = $this->pageViewFactory->create($pagerfanta, $paginatorDetails->route(), $paginatorDetails->parameters());
foreach ($pagerfanta->getCurrentPageResults() as $currentPageResult) {
$pageView->items[] = $this->orderViewFactory->create($currentPageResult);
$pageView->items[] = $this->shipmentViewFactory->create($currentPageResult, $localeCode);
}

return $pageView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace Setono\SyliusLagersystemPlugin\ViewRepository\Order;
namespace Setono\SyliusLagersystemPlugin\ViewRepository\Shipment;

use Setono\SyliusLagersystemPlugin\Model\PaginatorDetails;
use Setono\SyliusLagersystemPlugin\View\PageView;

interface OrderViewRepositoryInterface
interface ShipmentViewRepositoryInterface
{
public function getAllPaginated(PaginatorDetails $paginatorDetails): PageView;
public function getAllPaginated(PaginatorDetails $paginatorDetails, ?string $localeCode): PageView;
}
Loading

0 comments on commit a69028e

Please sign in to comment.