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

[Product] Remove channel code from product routes #470

Merged
merged 2 commits into from
Jul 19, 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
10 changes: 8 additions & 2 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@

| Old Route | New route |
|:--------------------------------------|:---------------------------------------|
| `{channelCode}/address-book/*` | `address-book/*` |
| `{channelCode}/address-book/*` | `address-book/*` |
| `{channelCode}/checkout/*` | `checkout/*` |
| `{channelCode}/orders/*` | `orders/*` |
| `{channelCode}/orders/*` | `orders/*` |
| `{channelCode}/products/*` | `products/*` |
| `{channelCode}/product-latest` | `product-latest` |
| `{channelCode}/taxon-products/*` | `taxon-products/*` |

* The channel code has been added as a second argument to `AddProductReviewByCodeRequest`
and `AddProductReviewBySlugRequest` classes.

# UPGRADE FROM 1.0.0-beta.17 to 1.0.0-beta.18

Expand Down
54 changes: 38 additions & 16 deletions doc/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,7 @@ paths:
- {}
- bearerAuth: []

/{channelCode}/taxon-products/by-slug/{taxonSlug}:
parameters:
- $ref: "#/parameters/ChannelCode"
/taxon-products/by-slug/{taxonSlug}:
get:
tags:
- "products"
Expand Down Expand Up @@ -475,9 +473,8 @@ paths:
description: "Paginated product list."
schema:
$ref: "#/definitions/ProductsPage"
/{channelCode}/taxon-products/by-code/{taxonCode}:
parameters:
- $ref: "#/parameters/ChannelCode"

/taxon-products/by-code/{taxonCode}:
get:
tags:
- "products"
Expand Down Expand Up @@ -510,9 +507,8 @@ paths:
description: "Paginated product list."
schema:
$ref: "#/definitions/ProductsPage"
/{channelCode}/products/by-slug/{slug}:
parameters:
- $ref: "#/parameters/ChannelCode"

/products/by-slug/{slug}:
get:
tags:
- "products"
Expand All @@ -535,9 +531,8 @@ paths:
description: "Show a product with the given slug."
schema:
$ref: "#/definitions/ProductDetails"
/{channelCode}/products/by-code/{code}:
parameters:
- $ref: "#/parameters/ChannelCode"

/products/by-code/{code}:
get:
tags:
- "products"
Expand All @@ -560,9 +555,9 @@ paths:
description: "Show a product with the given code."
schema:
$ref: "#/definitions/ProductDetails"
/{channelCode}/products/by-slug/{slug}/reviews:

/products/by-slug/{slug}/reviews:
parameters:
- $ref: "#/parameters/ChannelCode"
- name: "slug"
in: "path"
description: "Slug of expected product."
Expand Down Expand Up @@ -598,9 +593,9 @@ paths:
description: "A paginated list of all reviews related to the product identified by slug."
schema:
$ref: "#/definitions/ProductReviewsPage"
/{channelCode}/product/by-code/{code}/reviews:

/products/by-code/{code}/reviews:
parameters:
- $ref: "#/parameters/ChannelCode"
- name: "code"
in: "path"
description: "Code of expected product."
Expand Down Expand Up @@ -636,6 +631,33 @@ paths:
description: "A paginated list of all reviews related to the product identified by slug."
schema:
$ref: "#/definitions/ProductReviewsPage"

/product-latest:
get:
tags:
- "products"
summary: "Show latest products."
description: "This endpoint will return an array of latest products."
operationId: "latestProducts"
parameters:
- name: "locale"
in: "query"
description: "Locale in which products should be shown."
required: false
type: "string"
- name: "limit"
in: "query"
description: "Number of expected products per page."
required: false
type: "integer"
responses:
200:
description: "Array of latest products."
schema:
type: "array"
items:
$ref: "#/definitions/Product"

/{channelCode}/taxons:
parameters:
- $ref: "#/parameters/ChannelCode"
Expand Down
11 changes: 9 additions & 2 deletions src/Controller/Product/AddReviewByCodeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\ShopApiPlugin\Factory\ValidationErrorViewFactoryInterface;
use Sylius\ShopApiPlugin\Request\Product\AddProductReviewByCodeRequest;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -27,21 +28,27 @@ final class AddReviewByCodeAction
/** @var ValidationErrorViewFactoryInterface */
private $validationErrorViewFactory;

/** @var ChannelContextInterface */
private $channelContext;

public function __construct(
ViewHandlerInterface $viewHandler,
MessageBusInterface $bus,
ValidatorInterface $validator,
ValidationErrorViewFactoryInterface $validationErrorViewFactory
ValidationErrorViewFactoryInterface $validationErrorViewFactory,
ChannelContextInterface $channelContext
) {
$this->viewHandler = $viewHandler;
$this->bus = $bus;
$this->validator = $validator;
$this->validationErrorViewFactory = $validationErrorViewFactory;
$this->channelContext = $channelContext;
}

public function __invoke(Request $request): Response
{
$addReviewRequest = new AddProductReviewByCodeRequest($request);
$channel = $this->channelContext->getChannel();
$addReviewRequest = new AddProductReviewByCodeRequest($request, $channel->getCode());

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

Expand Down
11 changes: 9 additions & 2 deletions src/Controller/Product/AddReviewBySlugAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\ShopApiPlugin\Factory\ValidationErrorViewFactoryInterface;
use Sylius\ShopApiPlugin\Request\Product\AddProductReviewBySlugRequest;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -27,21 +28,27 @@ final class AddReviewBySlugAction
/** @var ValidationErrorViewFactoryInterface */
private $validationErrorViewFactory;

/** @var ChannelContextInterface */
private $channelContext;

public function __construct(
ViewHandlerInterface $viewHandler,
MessageBusInterface $bus,
ValidatorInterface $validator,
ValidationErrorViewFactoryInterface $validationErrorViewFactory
ValidationErrorViewFactoryInterface $validationErrorViewFactory,
ChannelContextInterface $channelContext
) {
$this->viewHandler = $viewHandler;
$this->bus = $bus;
$this->validator = $validator;
$this->validationErrorViewFactory = $validationErrorViewFactory;
$this->channelContext = $channelContext;
}

public function __invoke(Request $request): Response
{
$addReviewRequest = new AddProductReviewBySlugRequest($request);
$channel = $this->channelContext->getChannel();
$addReviewRequest = new AddProductReviewBySlugRequest($request, $channel->getCode());

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

Expand Down
15 changes: 13 additions & 2 deletions src/Controller/Product/ShowLatestProductAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Channel\Context\ChannelNotFoundException;
use Sylius\ShopApiPlugin\ViewRepository\Product\ProductLatestViewRepositoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -19,22 +21,31 @@ final class ShowLatestProductAction
/** @var ProductLatestViewRepositoryInterface */
private $productLatestQuery;

/** @var ChannelContextInterface */
private $channelContext;

public function __construct(
ViewHandlerInterface $viewHandler,
ProductLatestViewRepositoryInterface $productLatestQuery
ProductLatestViewRepositoryInterface $productLatestQuery,
ChannelContextInterface $channelContext
) {
$this->viewHandler = $viewHandler;
$this->productLatestQuery = $productLatestQuery;
$this->channelContext = $channelContext;
}

public function __invoke(Request $request): Response
{
try {
$channel = $this->channelContext->getChannel();

return $this->viewHandler->handle(View::create($this->productLatestQuery->getLatestProducts(
$request->attributes->get('channelCode'),
$channel->getCode(),
$request->query->get('locale'),
$request->query->getInt('limit', 4)
), Response::HTTP_OK));
} catch (ChannelNotFoundException $exception) {
throw new NotFoundHttpException('Channel has not been found.');
} catch (\InvalidArgumentException $exception) {
throw new NotFoundHttpException($exception->getMessage());
}
Expand Down
15 changes: 13 additions & 2 deletions src/Controller/Product/ShowProductCatalogByTaxonCodeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Channel\Context\ChannelNotFoundException;
use Sylius\ShopApiPlugin\Model\PaginatorDetails;
use Sylius\ShopApiPlugin\ViewRepository\Product\ProductCatalogViewRepositoryInterface;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -20,23 +22,32 @@ final class ShowProductCatalogByTaxonCodeAction
/** @var ProductCatalogViewRepositoryInterface */
private $productCatalogQuery;

/** @var ChannelContextInterface */
private $channelContext;

public function __construct(
ViewHandlerInterface $viewHandler,
ProductCatalogViewRepositoryInterface $productCatalogQuery
ProductCatalogViewRepositoryInterface $productCatalogQuery,
ChannelContextInterface $channelContext
) {
$this->viewHandler = $viewHandler;
$this->productCatalogQuery = $productCatalogQuery;
$this->channelContext = $channelContext;
}

public function __invoke(Request $request): Response
{
try {
$channel = $this->channelContext->getChannel();

return $this->viewHandler->handle(View::create($this->productCatalogQuery->findByTaxonCode(
$request->attributes->get('taxonCode'),
$request->attributes->get('channelCode'),
$channel->getCode(),
new PaginatorDetails($request->attributes->get('_route'), $request->query->all()),
$request->query->get('locale')
), Response::HTTP_OK));
} catch (ChannelNotFoundException $exception) {
throw new NotFoundHttpException('Channel has not been found.');
} catch (\InvalidArgumentException $exception) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to mute all \InvalidArgumentException?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it is due to old Assert implementation :(

throw new NotFoundHttpException($exception->getMessage());
}
Expand Down
15 changes: 13 additions & 2 deletions src/Controller/Product/ShowProductCatalogByTaxonSlugAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Channel\Context\ChannelNotFoundException;
use Sylius\ShopApiPlugin\Model\PaginatorDetails;
use Sylius\ShopApiPlugin\ViewRepository\Product\ProductCatalogViewRepositoryInterface;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -20,23 +22,32 @@ final class ShowProductCatalogByTaxonSlugAction
/** @var ProductCatalogViewRepositoryInterface */
private $productCatalogQuery;

/** @var ChannelContextInterface */
private $channelContext;

public function __construct(
ViewHandlerInterface $viewHandler,
ProductCatalogViewRepositoryInterface $productCatalogQuery
ProductCatalogViewRepositoryInterface $productCatalogQuery,
ChannelContextInterface $channelContext
) {
$this->viewHandler = $viewHandler;
$this->productCatalogQuery = $productCatalogQuery;
$this->channelContext = $channelContext;
}

public function __invoke(Request $request): Response
{
try {
$channel = $this->channelContext->getChannel();

return $this->viewHandler->handle(View::create($this->productCatalogQuery->findByTaxonSlug(
$request->attributes->get('taxonSlug'),
$request->attributes->get('channelCode'),
$channel->getCode(),
new PaginatorDetails($request->attributes->get('_route'), $request->query->all()),
$request->query->get('locale')
), Response::HTTP_OK));
} catch (ChannelNotFoundException $exception) {
throw new NotFoundHttpException('Channel has not been found.');
} catch (\InvalidArgumentException $exception) {
throw new NotFoundHttpException($exception->getMessage());
}
Expand Down
15 changes: 13 additions & 2 deletions src/Controller/Product/ShowProductDetailsByCodeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Channel\Context\ChannelNotFoundException;
use Sylius\ShopApiPlugin\ViewRepository\Product\ProductDetailsViewRepositoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -19,22 +21,31 @@ final class ShowProductDetailsByCodeAction
/** @var ViewHandlerInterface */
private $viewHandler;

/** @var ChannelContextInterface */
private $channelContext;

public function __construct(
ProductDetailsViewRepositoryInterface $productCatalog,
ViewHandlerInterface $viewHandler
ViewHandlerInterface $viewHandler,
ChannelContextInterface $channelContext
) {
$this->productCatalog = $productCatalog;
$this->viewHandler = $viewHandler;
$this->channelContext = $channelContext;
}

public function __invoke(Request $request): Response
{
try {
$channel = $this->channelContext->getChannel();

return $this->viewHandler->handle(View::create($this->productCatalog->findOneByCode(
$request->attributes->get('code'),
$request->attributes->get('channelCode'),
$channel->getCode(),
$request->query->get('locale')
), Response::HTTP_OK));
} catch (ChannelNotFoundException $exception) {
throw new NotFoundHttpException('Channel has not been found.');
} catch (\InvalidArgumentException $exception) {
throw new NotFoundHttpException($exception->getMessage());
}
Expand Down
Loading