Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Abstract creating commands from requests" #379

Merged
merged 1 commit into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: php

php:
- 7.1
- 7.2

env:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Shop API for Sylius E-Commerce.",
"license": "MIT",
"require": {
"php": "^7.2",
"php": "^7.1",

"sylius/sylius": "^1.1",
"league/tactician-bundle": "^1.1",
Expand Down
50 changes: 0 additions & 50 deletions spec/Parser/CommandRequestParserSpec.php

This file was deleted.

14 changes: 2 additions & 12 deletions src/Controller/AddressBook/RemoveAddressAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
use FOS\RestBundle\View\ViewHandlerInterface;
use League\Tactician\CommandBus;
use Sylius\Component\Core\Model\ShopUserInterface;
use Sylius\ShopApiPlugin\Command\RemoveAddress;
use Sylius\ShopApiPlugin\Factory\ValidationErrorViewFactory;
use Sylius\ShopApiPlugin\Parser\CommandRequestParserInterface;
use Sylius\ShopApiPlugin\Provider\LoggedInShopUserProviderInterface;
use Sylius\ShopApiPlugin\Request\RemoveAddressRequest;
use Sylius\ShopApiPlugin\Request\UserEmailBasedCommandRequestInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\TokenNotFoundException;
Expand All @@ -36,23 +33,18 @@ final class RemoveAddressAction
/** @var LoggedInShopUserProviderInterface */
private $loggedInUserProvider;

/** @var CommandRequestParserInterface */
private $commandRequestParser;

public function __construct(
ViewHandlerInterface $viewHandler,
ValidatorInterface $validator,
ValidationErrorViewFactory $validationErrorViewFactory,
CommandBus $bus,
LoggedInShopUserProviderInterface $loggedInUserProvider,
CommandRequestParserInterface $commandRequestParser
LoggedInShopUserProviderInterface $loggedInUserProvider
) {
$this->viewHandler = $viewHandler;
$this->validator = $validator;
$this->validationErrorViewFactory = $validationErrorViewFactory;
$this->bus = $bus;
$this->loggedInUserProvider = $loggedInUserProvider;
$this->commandRequestParser = $commandRequestParser;
}

public function __invoke(Request $request): Response
Expand All @@ -64,9 +56,7 @@ public function __invoke(Request $request): Response
return $this->viewHandler->handle(View::create(null, Response::HTTP_UNAUTHORIZED));
}

/** @var UserEmailBasedCommandRequestInterface $removeAddressRequest */
$removeAddressRequest = $this->commandRequestParser->parse($request, RemoveAddress::class);
$removeAddressRequest->setUserEmail($user->getEmail());
$removeAddressRequest = new RemoveAddressRequest($request, $user->getEmail());

$validationResults = $this->validator->validate($removeAddressRequest);

Expand Down
14 changes: 2 additions & 12 deletions src/Controller/AddressBook/SetDefaultAddressAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
use FOS\RestBundle\View\ViewHandlerInterface;
use League\Tactician\CommandBus;
use Sylius\Component\Core\Model\ShopUserInterface;
use Sylius\ShopApiPlugin\Command\SetDefaultAddress;
use Sylius\ShopApiPlugin\Factory\ValidationErrorViewFactoryInterface;
use Sylius\ShopApiPlugin\Parser\CommandRequestParserInterface;
use Sylius\ShopApiPlugin\Provider\LoggedInShopUserProviderInterface;
use Sylius\ShopApiPlugin\Request\SetDefaultAddressRequest;
use Sylius\ShopApiPlugin\Request\UserEmailBasedCommandRequestInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\TokenNotFoundException;
Expand All @@ -36,23 +33,18 @@ final class SetDefaultAddressAction
/** @var LoggedInShopUserProviderInterface */
private $loggedInUserProvider;

/** @var CommandRequestParserInterface */
private $commandRequestParser;

public function __construct(
ViewHandlerInterface $viewHandler,
CommandBus $bus,
ValidatorInterface $validator,
ValidationErrorViewFactoryInterface $validationErrorViewFactory,
LoggedInShopUserProviderInterface $loggedInUserProvider,
CommandRequestParserInterface $commandRequestParser
LoggedInShopUserProviderInterface $loggedInUserProvider
) {
$this->viewHandler = $viewHandler;
$this->bus = $bus;
$this->validator = $validator;
$this->validationErrorViewFactory = $validationErrorViewFactory;
$this->loggedInUserProvider = $loggedInUserProvider;
$this->commandRequestParser = $commandRequestParser;
}

public function __invoke(Request $request): Response
Expand All @@ -64,9 +56,7 @@ public function __invoke(Request $request): Response
return $this->viewHandler->handle(View::create(null, Response::HTTP_UNAUTHORIZED));
}

/** @var UserEmailBasedCommandRequestInterface $setDefaultAddressRequest */
$setDefaultAddressRequest = $this->commandRequestParser->parse($request, SetDefaultAddress::class);
$setDefaultAddressRequest->setUserEmail($user->getEmail());
$setDefaultAddressRequest = new SetDefaultAddressRequest($request, $user->getEmail());

$validationResults = $this->validator->validate($setDefaultAddressRequest);

Expand Down
2 changes: 0 additions & 2 deletions src/Controller/Cart/AddCouponAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use League\Tactician\CommandBus;
use Sylius\ShopApiPlugin\Command\AddCoupon;
use Sylius\ShopApiPlugin\Factory\ValidationErrorViewFactoryInterface;
use Sylius\ShopApiPlugin\Request\AddCouponRequest;
use Sylius\ShopApiPlugin\ViewRepository\Cart\CartViewRepositoryInterface;
Expand Down Expand Up @@ -55,7 +54,6 @@ public function __invoke(Request $request): Response

if (0 === count($validationResults)) {
$addCouponCommand = $addCouponRequest->getCommand();
assert($addCouponCommand instanceof AddCoupon);

$this->bus->handle($addCouponCommand);

Expand Down
13 changes: 3 additions & 10 deletions src/Controller/Cart/ChangeItemQuantityAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use League\Tactician\CommandBus;
use Sylius\ShopApiPlugin\Command\ChangeItemQuantity;
use Sylius\ShopApiPlugin\Factory\ValidationErrorViewFactoryInterface;
use Sylius\ShopApiPlugin\Parser\CommandRequestParserInterface;
use Sylius\ShopApiPlugin\Request\ChangeItemQuantityRequest;
use Sylius\ShopApiPlugin\ViewRepository\Cart\CartViewRepositoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -33,28 +32,23 @@ final class ChangeItemQuantityAction
/** @var CartViewRepositoryInterface */
private $cartQuery;

/** @var CommandRequestParserInterface */
private $commandRequestParser;

public function __construct(
ViewHandlerInterface $viewHandler,
CommandBus $bus,
ValidatorInterface $validator,
ValidationErrorViewFactoryInterface $validationErrorViewFactory,
CartViewRepositoryInterface $cartQuery,
CommandRequestParserInterface $commandRequestParser
CartViewRepositoryInterface $cartQuery
) {
$this->viewHandler = $viewHandler;
$this->bus = $bus;
$this->validator = $validator;
$this->validationErrorViewFactory = $validationErrorViewFactory;
$this->cartQuery = $cartQuery;
$this->commandRequestParser = $commandRequestParser;
}

public function __invoke(Request $request): Response
{
$changeItemQuantityRequest = $this->commandRequestParser->parse($request, ChangeItemQuantity::class);
$changeItemQuantityRequest = new ChangeItemQuantityRequest($request);

$validationResults = $this->validator->validate($changeItemQuantityRequest);

Expand All @@ -63,7 +57,6 @@ public function __invoke(Request $request): Response
}

$changeItemQuantityCommand = $changeItemQuantityRequest->getCommand();
assert($changeItemQuantityCommand instanceof ChangeItemQuantity);

$this->bus->handle($changeItemQuantityCommand);

Expand Down
16 changes: 5 additions & 11 deletions src/Controller/Cart/DropCartAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use League\Tactician\CommandBus;
use Sylius\ShopApiPlugin\Command\DropCart;
use Sylius\ShopApiPlugin\Factory\ValidationErrorViewFactoryInterface;
use Sylius\ShopApiPlugin\Parser\CommandRequestParserInterface;
use Sylius\ShopApiPlugin\Request\DropCartRequest;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Validator\ValidatorInterface;
Expand All @@ -28,31 +27,26 @@ final class DropCartAction
/** @var ValidationErrorViewFactoryInterface */
private $validationErrorViewFactory;

/** @var CommandRequestParserInterface */
private $commandRequestParser;

public function __construct(
ViewHandlerInterface $viewHandler,
CommandBus $bus,
ValidatorInterface $validator,
ValidationErrorViewFactoryInterface $validationErrorViewFactory,
CommandRequestParserInterface $commandRequestParser
ValidationErrorViewFactoryInterface $validationErrorViewFactory
) {
$this->viewHandler = $viewHandler;
$this->bus = $bus;
$this->validator = $validator;
$this->validationErrorViewFactory = $validationErrorViewFactory;
$this->commandRequestParser = $commandRequestParser;
}

public function __invoke(Request $request): Response
{
$dropCartRequest = $this->commandRequestParser->parse($request, DropCart::class);
$pickupRequest = new DropCartRequest($request);

$validationResults = $this->validator->validate($dropCartRequest);
$validationResults = $this->validator->validate($pickupRequest);

if (0 === count($validationResults)) {
$this->bus->handle($dropCartRequest->getCommand());
$this->bus->handle($pickupRequest->getCommand());

return $this->viewHandler->handle(View::create(null, Response::HTTP_NO_CONTENT));
}
Expand Down
13 changes: 3 additions & 10 deletions src/Controller/Cart/PickupAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use League\Tactician\CommandBus;
use Sylius\ShopApiPlugin\Command\PickupCart;
use Sylius\ShopApiPlugin\Factory\ValidationErrorViewFactoryInterface;
use Sylius\ShopApiPlugin\Parser\CommandRequestParserInterface;
use Sylius\ShopApiPlugin\Request\PickupCartRequest;
use Sylius\ShopApiPlugin\ViewRepository\Cart\CartViewRepositoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -33,34 +32,28 @@ final class PickupAction
/** @var CartViewRepositoryInterface */
private $cartQuery;

/** @var CommandRequestParserInterface */
private $commandRequestParser;

public function __construct(
ViewHandlerInterface $viewHandler,
CommandBus $bus,
ValidatorInterface $validator,
ValidationErrorViewFactoryInterface $validationErrorViewFactory,
CartViewRepositoryInterface $cartQuery,
CommandRequestParserInterface $commandRequestParser
CartViewRepositoryInterface $cartQuery
) {
$this->viewHandler = $viewHandler;
$this->bus = $bus;
$this->validator = $validator;
$this->validationErrorViewFactory = $validationErrorViewFactory;
$this->cartQuery = $cartQuery;
$this->commandRequestParser = $commandRequestParser;
}

public function __invoke(Request $request): Response
{
$pickupRequest = $this->commandRequestParser->parse($request, PickupCart::class);
$pickupRequest = new PickupCartRequest($request);

$validationResults = $this->validator->validate($pickupRequest);

if (0 === count($validationResults)) {
$pickupCartCommand = $pickupRequest->getCommand();
assert($pickupCartCommand instanceof PickupCart);

$this->bus->handle($pickupCartCommand);

Expand Down
Loading